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