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