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