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