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