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.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / classes / Post_types.php
tutor / classes Last commit date
Addons.php 4 years ago Admin.php 4 years ago Ajax.php 4 years ago Announcements.php 4 years ago Assets.php 4 years ago Backend_Page_Trait.php 4 years ago Course.php 4 years ago Course_Filter.php 4 years ago Course_List.php 4 years ago Course_Settings_Tabs.php 4 years ago Course_Widget.php 4 years ago Custom_Validation.php 4 years ago Dashboard.php 4 years ago FormHandler.php 4 years ago Frontend.php 4 years ago Gutenberg.php 4 years ago Input.php 4 years ago Instructor.php 4 years ago Instructors_List.php 4 years ago Lesson.php 4 years ago Options_V2.php 4 years ago Post_types.php 4 years ago Private_Course_Access.php 4 years ago Q_and_A.php 4 years ago Question_Answers_List.php 4 years ago Quiz.php 4 years ago Quiz_Attempts_List.php 4 years ago RestAPI.php 4 years ago Reviews.php 4 years ago Rewrite_Rules.php 4 years ago Shortcode.php 4 years ago Student.php 4 years ago Students_List.php 4 years ago Taxonomies.php 4 years ago Template.php 4 years ago Theme_Compatibility.php 5 years ago Tools.php 4 years ago Tools_V2.php 4 years ago Tutor.php 4 years ago TutorEDD.php 4 years ago Tutor_Base.php 5 years ago Tutor_List_Table.php 4 years ago Tutor_Setup.php 4 years ago Upgrader.php 4 years ago User.php 4 years ago Utils.php 4 years ago Video_Stream.php 4 years ago Withdraw.php 4 years ago Withdraw_Requests_List.php 4 years ago WooCommerce.php 4 years ago
Post_types.php
419 lines
1 <?php
2 namespace TUTOR;
3 if ( ! defined( 'ABSPATH' ) )
4 exit;
5
6 class Post_types{
7
8 public $course_post_type;
9 public $lesson_post_type;
10
11 public function __construct() {
12 $this->course_post_type = tutor()->course_post_type;
13 $this->lesson_post_type = tutor()->lesson_post_type;
14
15 add_action( 'init', array($this, 'register_course_post_types') );
16 add_action( 'init', array($this, 'register_lesson_post_types') );
17 add_action( 'init', array($this, 'register_quiz_post_types') );
18 add_action( 'init', array($this, 'register_topic_post_types') );
19 add_action( 'init', array($this, 'register_assignments_post_types') );
20
21 add_filter( 'gutenberg_can_edit_post_type', array( $this, 'gutenberg_can_edit_post_type' ), 10, 2 );
22 add_filter( 'use_block_editor_for_post_type', array( $this, 'gutenberg_can_edit_post_type' ), 10, 2 );
23
24 /**
25 * Customize the message of course
26 */
27 add_filter( 'post_updated_messages', array($this, 'course_updated_messages') );
28
29 /**
30 * Since 1.4.0
31 */
32 add_action( 'init', array( $this, 'register_tutor_enrolled_post_types' ) );
33
34 /**
35 * Remove tutor course post type from admin menu
36 *
37 * @since v2.0.0
38 */
39 add_action( 'admin_menu', array( $this, 'remove_course_post_menu' ) );
40 }
41
42 public function register_course_post_types() {
43 $course_post_type = $this->course_post_type;
44 $courses_base_slug = apply_filters('tutor_courses_base_slug', $course_post_type);
45
46 $labels = array(
47 'name' => _x( 'Courses', 'post type general name', 'tutor' ),
48 'singular_name' => _x( 'Course', 'post type singular name', 'tutor' ),
49 'menu_name' => _x( 'Courses', 'admin menu', 'tutor' ),
50 'name_admin_bar' => _x( 'Course', 'add new on admin bar', 'tutor' ),
51 'add_new' => _x( 'Add New', 'tutor course add', 'tutor' ),
52 'add_new_item' => __( 'Add New Course', 'tutor' ),
53 'new_item' => __( 'New Course', 'tutor' ),
54 'edit_item' => __( 'Edit Course', 'tutor' ),
55 'view_item' => __( 'View Course', 'tutor' ),
56 'all_items' => __( 'Courses', 'tutor' ),
57 'search_items' => __( 'Search Courses', 'tutor' ),
58 'parent_item_colon' => __( 'Parent Courses:', 'tutor' ),
59 'not_found' => __( 'No courses found.', 'tutor' ),
60 'not_found_in_trash' => __( 'No courses found in Trash.', 'tutor' )
61 );
62
63 $args = array(
64 'labels' => $labels,
65 'description' => __( 'Description.', 'tutor' ),
66 'public' => true,
67 'publicly_queryable' => true,
68 //'show_ui' => true,
69 //'show_in_menu' => 'tutor',
70 'query_var' => true,
71 'rewrite' => array( 'slug' => $courses_base_slug, 'with_front' => false ),
72 'menu_icon' => 'dashicons-book-alt',
73 'capability_type' => 'post',
74 'has_archive' => true,
75 'hierarchical' => false,
76 'menu_position' => null,
77 'taxonomies' => array( 'course-category', 'course-tag' ),
78 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'author'),
79 'show_in_rest' => true,
80
81 'capabilities' => array(
82 'edit_post' => 'edit_tutor_course',
83 'read_post' => 'read_tutor_course',
84 'delete_post' => 'delete_tutor_course',
85 'delete_posts' => 'delete_tutor_courses',
86 'edit_posts' => 'edit_tutor_courses',
87 'edit_others_posts' => 'edit_others_tutor_courses',
88 'publish_posts' => 'publish_tutor_courses',
89 'read_private_posts' => 'read_private_tutor_courses',
90 'create_posts' => 'edit_tutor_courses',
91 ),
92
93 );
94
95 register_post_type($course_post_type, $args);
96
97 /**
98 * Taxonomy
99 */
100 $labels = array(
101 'name' => _x( 'Course Categories', 'taxonomy general name', 'tutor' ),
102 'singular_name' => _x( 'Category', 'taxonomy singular name', 'tutor' ),
103 'search_items' => __( 'Search Categories', 'tutor' ),
104 'popular_items' => __( 'Popular Categories', 'tutor' ),
105 'all_items' => __( 'All Categories', 'tutor' ),
106 'parent_item' => null,
107 'parent_item_colon' => null,
108 'edit_item' => __( 'Edit Category', 'tutor' ),
109 'update_item' => __( 'Update Category', 'tutor' ),
110 'add_new_item' => __( 'Add New Category', 'tutor' ),
111 'new_item_name' => __( 'New Category Name', 'tutor' ),
112 'separate_items_with_commas' => __( 'Separate categories with commas', 'tutor' ),
113 'add_or_remove_items' => __( 'Add or remove categories', 'tutor' ),
114 'choose_from_most_used' => __( 'Choose from the most used categories', 'tutor' ),
115 'not_found' => __( 'No categories found.', 'tutor' ),
116 'menu_name' => __( 'Course Categories', 'tutor' ),
117 );
118
119 $args = array(
120 'hierarchical' => true,
121 'labels' => $labels,
122 'show_ui' => true,
123 'show_admin_column' => true,
124 'update_count_callback' => '_update_post_term_count',
125 'query_var' => true,
126 'show_in_rest' => true,
127 'rewrite' => array( 'slug' => 'course-category' ),
128 );
129
130 register_taxonomy( 'course-category', $this->course_post_type, $args );
131
132 $labels = array(
133 'name' => _x( 'Tags', 'taxonomy general name', 'tutor' ),
134 'singular_name' => _x( 'Tag', 'taxonomy singular name', 'tutor' ),
135 'search_items' => __( 'Search Tags', 'tutor' ),
136 'popular_items' => __( 'Popular Tags', 'tutor' ),
137 'all_items' => __( 'All Tags', 'tutor' ),
138 'parent_item' => null,
139 'parent_item_colon' => null,
140 'edit_item' => __( 'Edit Tag', 'tutor' ),
141 'update_item' => __( 'Update Tag', 'tutor' ),
142 'add_new_item' => __( 'Add New Tag', 'tutor' ),
143 'new_item_name' => __( 'New Tag Name', 'tutor' ),
144 'separate_items_with_commas' => __( 'Separate Tags with commas', 'tutor' ),
145 'add_or_remove_items' => __( 'Add or remove Tags', 'tutor' ),
146 'choose_from_most_used' => __( 'Choose from the most used Tags', 'tutor' ),
147 'not_found' => __( 'No Tags found.', 'tutor' ),
148 'menu_name' => __( 'Tags', 'tutor' ),
149 );
150
151 $args = array(
152 'hierarchical' => false,
153 'labels' => $labels,
154 'show_ui' => true,
155 'show_admin_column' => true,
156 'update_count_callback' => '_update_post_term_count',
157 'query_var' => true,
158 'show_in_rest' => true,
159 'rewrite' => array( 'slug' => 'course-tag' ),
160 );
161
162 register_taxonomy( 'course-tag', $this->course_post_type, $args );
163 }
164
165 public function register_lesson_post_types() {
166 $lesson_post_type = $this->lesson_post_type;
167 $lesson_base_slug = apply_filters('tutor_lesson_base_slug', $lesson_post_type);
168
169 $labels = array(
170 'name' => _x( 'Lessons', 'post type general name', 'tutor' ),
171 'singular_name' => _x( 'Lesson', 'post type singular name', 'tutor' ),
172 'menu_name' => _x( 'Lessons', 'admin menu', 'tutor' ),
173 'name_admin_bar' => _x( 'Lesson', 'add new on admin bar', 'tutor' ),
174 'add_new' => _x( 'Add New', "tutor lesson add", 'tutor' ),
175 'add_new_item' => __( 'Add New Lesson', 'tutor' ),
176 'new_item' => __( 'New Lesson', 'tutor' ),
177 'edit_item' => __( 'Edit Lesson', 'tutor' ),
178 'view_item' => __( 'View Lesson', 'tutor' ),
179 'all_items' => __( 'Lessons', 'tutor' ),
180 'search_items' => __( 'Search Lessons', 'tutor' ),
181 'parent_item_colon' => __( 'Parent Lessons:', 'tutor' ),
182 'not_found' => __( 'No lessons found.', 'tutor' ),
183 'not_found_in_trash' => __( 'No lessons found in Trash.', 'tutor' )
184 );
185
186 $args = array(
187 'labels' => $labels,
188 'description' => __( 'Description.', 'tutor' ),
189 'public' => true,
190 'publicly_queryable' => true,
191 'show_ui' => true,
192 'show_in_menu' => false,
193 'query_var' => true,
194 'rewrite' => array( 'slug' => $lesson_base_slug ),
195 'menu_icon' => 'dashicons-list-view',
196 'capability_type' => 'post',
197 'has_archive' => true,
198 'hierarchical' => false,
199 'menu_position' => null,
200 'supports' => array( 'title', 'editor', 'comments'),
201 'exclude_from_search' => apply_filters('tutor_lesson_exclude_from_search', true),
202 'capabilities' => array(
203 'edit_post' => 'edit_tutor_lesson',
204 'read_post' => 'read_tutor_lesson',
205 'delete_post' => 'delete_tutor_lesson',
206 'delete_posts' => 'delete_tutor_lessons',
207 'edit_posts' => 'edit_tutor_lessons',
208 'edit_others_posts' => 'edit_others_tutor_lessons',
209 'publish_posts' => 'publish_tutor_lessons',
210 'read_private_posts' => 'read_private_tutor_lessons',
211 'create_posts' => 'edit_tutor_lessons',
212 ),
213 );
214
215 register_post_type($lesson_post_type, $args );
216 }
217
218 public function register_quiz_post_types() {
219 $labels = array(
220 'name' => _x( 'Quizzes', 'post type general name', 'tutor' ),
221 'singular_name' => _x( 'Quiz', 'post type singular name', 'tutor' ),
222 'menu_name' => _x( 'Quizzes', 'admin menu', 'tutor' ),
223 'name_admin_bar' => _x( 'Quiz', 'add new on admin bar', 'tutor' ),
224 'add_new' => _x( 'Add New', "tutor quiz add", 'tutor' ),
225 'add_new_item' => __( 'Add New Quiz', 'tutor' ),
226 'new_item' => __( 'New Quiz', 'tutor' ),
227 'edit_item' => __( 'Edit Quiz', 'tutor' ),
228 'view_item' => __( 'View Quiz', 'tutor' ),
229 'all_items' => __( 'Quizzes', 'tutor' ),
230 'search_items' => __( 'Search Quizzes', 'tutor' ),
231 'parent_item_colon' => __( 'Parent Quizzes:', 'tutor' ),
232 'not_found' => __( 'No quizzes found.', 'tutor' ),
233 'not_found_in_trash' => __( 'No quizzes found in Trash.', 'tutor' )
234 );
235
236 $args = array(
237 'labels' => $labels,
238 'description' => __( 'Description.', 'tutor' ),
239 'public' => true,
240 'publicly_queryable' => true,
241 'show_ui' => false,
242 'show_in_menu' => 'tutor',
243 'query_var' => true,
244 'rewrite' => array( 'slug' => $this->lesson_post_type ),
245 'menu_icon' => 'dashicons-editor-help',
246 'capability_type' => 'post',
247 'has_archive' => true,
248 'hierarchical' => false,
249 'menu_position' => null,
250 'supports' => array( 'title', 'editor'),
251 'exclude_from_search' => apply_filters('tutor_quiz_exclude_from_search', true),
252 'capabilities' => array(
253 'edit_post' => 'edit_tutor_quiz',
254 'read_post' => 'read_tutor_quiz',
255 'delete_post' => 'delete_tutor_quiz',
256 'delete_posts' => 'delete_tutor_quizzes',
257 'edit_posts' => 'edit_tutor_quizzes',
258 'edit_others_posts' => 'edit_others_tutor_quizzes',
259 'publish_posts' => 'publish_tutor_quizzes',
260 'read_private_posts' => 'read_private_tutor_quizzes',
261 'create_posts' => 'edit_tutor_quizzes',
262 ),
263 );
264
265 register_post_type( 'tutor_quiz', $args );
266 }
267
268 public function register_topic_post_types(){
269 $args = array(
270 'label' => 'Topics',
271 'description' => __( 'Description.', 'tutor' ),
272 'public' => false,
273 'publicly_queryable' => false,
274 'show_ui' => false,
275 'query_var' => false,
276 'has_archive' => false,
277 'hierarchical' => false,
278 'menu_position' => null,
279 );
280 register_post_type( 'topics', $args );
281 }
282
283 public function register_assignments_post_types() {
284 $labels = array(
285 'name' => _x( 'Assignments', 'post type general name', 'tutor' ),
286 'singular_name' => _x( 'Assignment', 'post type singular name', 'tutor' ),
287 'menu_name' => _x( 'Assignments', 'admin menu', 'tutor' ),
288 'name_admin_bar' => _x( 'Assignment', 'add new on admin bar', 'tutor' ),
289 'add_new' => _x( 'Add New', "tutor assignment add", 'tutor' ),
290 'add_new_item' => __( 'Add New Assignment', 'tutor' ),
291 'new_item' => __( 'New Assignment', 'tutor' ),
292 'edit_item' => __( 'Edit Assignment', 'tutor' ),
293 'view_item' => __( 'View Assignment', 'tutor' ),
294 'all_items' => __( 'Assignments', 'tutor' ),
295 'search_items' => __( 'Search Assignments', 'tutor' ),
296 'parent_item_colon' => __( 'Parent Assignments:', 'tutor' ),
297 'not_found' => __( 'No Assignments found.', 'tutor' ),
298 'not_found_in_trash' => __( 'No Assignments found in Trash.', 'tutor' )
299 );
300
301 $args = array(
302 'labels' => $labels,
303 'description' => __( 'Description.', 'tutor' ),
304 'public' => true,
305 'publicly_queryable' => true,
306 'show_ui' => false,
307 'show_in_menu' => 'tutor',
308 'query_var' => true,
309 'rewrite' => array( 'slug' => $this->lesson_post_type ),
310 'menu_icon' => 'dashicons-editor-help',
311 'capability_type' => 'post',
312 'has_archive' => true,
313 'hierarchical' => false,
314 'menu_position' => null,
315 'supports' => array( 'title', 'editor'),
316 'exclude_from_search' => apply_filters('tutor_assignment_exclude_from_search', true),
317 'capabilities' => array(
318 'edit_post' => 'edit_tutor_assignment',
319 'read_post' => 'read_tutor_assignment',
320 'delete_post' => 'delete_tutor_assignment',
321 'delete_posts' => 'delete_tutor_assignments',
322 'edit_posts' => 'edit_tutor_assignments',
323 'edit_others_posts' => 'edit_others_tutor_assignments',
324 'publish_posts' => 'publish_tutor_assignments',
325 'read_private_posts' => 'read_private_tutor_assignments',
326 'create_posts' => 'edit_tutor_assignments',
327 ),
328 );
329
330 register_post_type( 'tutor_assignments', $args );
331 }
332
333 function course_updated_messages( $messages ) {
334 $post = get_post();
335 $post_type = get_post_type( $post );
336 $post_type_object = get_post_type_object( $post_type );
337
338 $course_post_type = tutor()->course_post_type;
339
340 $messages[$course_post_type] = array(
341 0 => '', // Unused. Messages start at index 1.
342 1 => __( 'Course updated.', 'tutor' ),
343 2 => __( 'Custom field updated.', 'tutor' ),
344 3 => __( 'Custom field deleted.', 'tutor' ),
345 4 => __( 'Course updated.', 'tutor' ),
346 /* translators: %s: date and time of the revision */
347 5 => isset( $_GET['revision'] ) ? sprintf( __( 'Course restored to revision from %s', 'tutor' ), wp_post_revision_title( (int) tutor_sanitize_data($_GET['revision']), false ) ) : false,
348 6 => __( 'Course published.', 'tutor' ),
349 7 => __( 'Course saved.', 'tutor' ),
350 8 => __( 'Course submitted.', 'tutor' ),
351 9 => sprintf(
352 __( 'Course scheduled for: <strong>%1$s</strong>.', 'tutor' ),
353 // translators: Publish box date format, see http://php.net/date
354 date_i18n( __( 'M j, Y @ G:i', 'tutor' ), strtotime( $post->post_date ) )
355 ),
356 10 => __( 'Course draft updated.', 'tutor' )
357 );
358
359 if ( $post_type_object->publicly_queryable && $course_post_type === $post_type ) {
360 $permalink = get_permalink( $post->ID );
361
362 $view_link = sprintf( ' <a href="%s">%s</a>', esc_url( $permalink ), __( 'View course', 'tutor' ) );
363 $messages[ $post_type ][1] .= $view_link;
364 $messages[ $post_type ][6] .= $view_link;
365 $messages[ $post_type ][9] .= $view_link;
366
367 $preview_permalink = add_query_arg( 'preview', 'true', $permalink );
368 $preview_link = sprintf( ' <a target="_blank" href="%s">%s</a>', esc_url( $preview_permalink ), __( 'Preview course', 'tutor' ) );
369 $messages[ $post_type ][8] .= $preview_link;
370 $messages[ $post_type ][10] .= $preview_link;
371 }
372
373 return $messages;
374 }
375
376 /**
377 * @param $can_edit
378 * @param $post_type
379 *
380 * @return bool
381 *
382 * Enable / Disable Gutenberg Editor
383 * @since v.1.3.4
384 */
385 public function gutenberg_can_edit_post_type( $can_edit, $post_type ) {
386 $enable_gutenberg = (bool) tutor_utils()->get_option('enable_gutenberg_course_edit');
387 return $this->course_post_type === $post_type ? $enable_gutenberg : $can_edit;
388 }
389
390 /**
391 * Register tutor_enrolled post type
392 * @since v.1.4.0
393 */
394 public function register_tutor_enrolled_post_types(){
395 $args = array(
396 'label' => 'Tutor Enrolled',
397 'description' => __( 'Description.', 'tutor' ),
398 'public' => false,
399 'publicly_queryable' => false,
400 'show_ui' => false,
401 'query_var' => false,
402 'has_archive' => false,
403 'hierarchical' => false,
404 'menu_position' => null,
405 );
406 register_post_type( 'tutor_enrolled', $args );
407 }
408
409 /**
410 * Remove course post menu
411 *
412 * @return void
413 * @since v2.0.0
414 */
415 public function remove_course_post_menu() {
416 remove_menu_page( 'edit.php?post_type=courses' );
417 }
418 }
419