| 1 |
<?php |
| 2 |
/** |
| 3 |
* Register post types |
| 4 |
* |
| 5 |
* @package Tutor\PostTypes |
| 6 |
* @category PostTypes |
| 7 |
* @author Themeum <support@themeum.com> |
| 8 |
* @link https://themeum.com |
| 9 |
* @since 1.0.0 |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace TUTOR; |
| 13 |
|
| 14 |
use Tutor\Models\CourseModel; |
| 15 |
|
| 16 |
if ( ! defined( 'ABSPATH' ) ) { |
| 17 |
exit; |
| 18 |
} |
| 19 |
/** |
| 20 |
* Register Tutor's post types |
| 21 |
* |
| 22 |
* @since 1.0.0 |
| 23 |
*/ |
| 24 |
//phpcs:ignore |
| 25 |
class Post_types { |
| 26 |
|
| 27 |
/** |
| 28 |
* Course post type |
| 29 |
* |
| 30 |
* @since 1.0.0 |
| 31 |
* |
| 32 |
* @var string |
| 33 |
*/ |
| 34 |
public $course_post_type; |
| 35 |
|
| 36 |
/** |
| 37 |
* Lesson post type |
| 38 |
* |
| 39 |
* @since 1.0.0 |
| 40 |
* |
| 41 |
* @var string |
| 42 |
*/ |
| 43 |
public $lesson_post_type; |
| 44 |
|
| 45 |
/** |
| 46 |
* Register hooks |
| 47 |
* |
| 48 |
* @since 1.0.0 |
| 49 |
*/ |
| 50 |
public function __construct() { |
| 51 |
$this->course_post_type = tutor()->course_post_type; |
| 52 |
$this->lesson_post_type = tutor()->lesson_post_type; |
| 53 |
|
| 54 |
add_action( 'init', array( $this, 'register_course_post_types' ) ); |
| 55 |
add_action( 'init', array( $this, 'register_lesson_post_types' ) ); |
| 56 |
add_action( 'init', array( $this, 'register_quiz_post_types' ) ); |
| 57 |
add_action( 'init', array( $this, 'register_topic_post_types' ) ); |
| 58 |
add_action( 'init', array( $this, 'register_assignments_post_types' ) ); |
| 59 |
|
| 60 |
add_filter( 'gutenberg_can_edit_post_type', array( $this, 'gutenberg_can_edit_post_type' ), 10, 2 ); |
| 61 |
add_filter( 'use_block_editor_for_post_type', array( $this, 'gutenberg_can_edit_post_type' ), 10, 2 ); |
| 62 |
|
| 63 |
/** |
| 64 |
* Customize the message of course |
| 65 |
*/ |
| 66 |
add_filter( 'post_updated_messages', array( $this, 'course_updated_messages' ) ); |
| 67 |
|
| 68 |
/** |
| 69 |
* Since 1.4.0 |
| 70 |
*/ |
| 71 |
add_action( 'init', array( $this, 'register_tutor_enrolled_post_types' ) ); |
| 72 |
|
| 73 |
/** |
| 74 |
* Remove tutor course post type from admin menu |
| 75 |
* |
| 76 |
* @since v2.0.0 |
| 77 |
*/ |
| 78 |
add_action( 'admin_menu', array( $this, 'remove_course_post_menu' ) ); |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Register course post type |
| 83 |
* |
| 84 |
* @since 1.0.0 |
| 85 |
* |
| 86 |
* @return void |
| 87 |
*/ |
| 88 |
public function register_course_post_types() { |
| 89 |
$course_post_type = $this->course_post_type; |
| 90 |
|
| 91 |
$labels = array( |
| 92 |
'name' => _x( 'Courses', 'post type general name', 'tutor' ), |
| 93 |
'singular_name' => _x( 'Course', 'post type singular name', 'tutor' ), |
| 94 |
'menu_name' => _x( 'Courses', 'admin menu', 'tutor' ), |
| 95 |
'name_admin_bar' => _x( 'Course', 'add new on admin bar', 'tutor' ), |
| 96 |
'add_new' => _x( 'Add New', 'tutor course add', 'tutor' ), |
| 97 |
'add_new_item' => __( 'Add New Course', 'tutor' ), |
| 98 |
'new_item' => __( 'New Course', 'tutor' ), |
| 99 |
'edit_item' => __( 'Edit Course', 'tutor' ), |
| 100 |
'view_item' => __( 'View Course', 'tutor' ), |
| 101 |
'all_items' => __( 'Courses', 'tutor' ), |
| 102 |
'search_items' => __( 'Search Courses', 'tutor' ), |
| 103 |
'parent_item_colon' => __( 'Parent Courses:', 'tutor' ), |
| 104 |
'not_found' => __( 'No courses found.', 'tutor' ), |
| 105 |
'not_found_in_trash' => __( 'No courses found in Trash.', 'tutor' ), |
| 106 |
); |
| 107 |
|
| 108 |
$args = array( |
| 109 |
'labels' => $labels, |
| 110 |
'description' => __( 'Description.', 'tutor' ), |
| 111 |
'public' => true, |
| 112 |
'publicly_queryable' => true, |
| 113 |
// 'show_ui' => true, |
| 114 |
// 'show_in_menu' => 'tutor', |
| 115 |
'query_var' => true, |
| 116 |
'rewrite' => array( |
| 117 |
'slug' => tutor_utils()->get_option( 'course_permalink_base', $course_post_type ), |
| 118 |
'with_front' => true, |
| 119 |
), |
| 120 |
'menu_icon' => 'dashicons-book-alt', |
| 121 |
'capability_type' => 'post', |
| 122 |
'has_archive' => true, |
| 123 |
'hierarchical' => false, |
| 124 |
'menu_position' => null, |
| 125 |
'taxonomies' => array( CourseModel::COURSE_CATEGORY, CourseModel::COURSE_TAG ), |
| 126 |
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'author' ), |
| 127 |
'show_in_rest' => true, |
| 128 |
|
| 129 |
'capabilities' => array( |
| 130 |
'edit_post' => 'edit_tutor_course', |
| 131 |
'read_post' => 'read_tutor_course', |
| 132 |
'delete_post' => 'delete_tutor_course', |
| 133 |
'delete_posts' => 'delete_tutor_courses', |
| 134 |
'edit_posts' => 'edit_tutor_courses', |
| 135 |
'edit_others_posts' => 'edit_others_tutor_courses', |
| 136 |
'publish_posts' => 'publish_tutor_courses', |
| 137 |
'read_private_posts' => 'read_private_tutor_courses', |
| 138 |
'create_posts' => 'edit_tutor_courses', |
| 139 |
), |
| 140 |
); |
| 141 |
|
| 142 |
register_post_type( $course_post_type, $args ); |
| 143 |
|
| 144 |
/** |
| 145 |
* Taxonomy |
| 146 |
*/ |
| 147 |
$labels = array( |
| 148 |
'name' => _x( 'Course Categories', 'taxonomy general name', 'tutor' ), |
| 149 |
'singular_name' => _x( 'Category', 'taxonomy singular name', 'tutor' ), |
| 150 |
'search_items' => __( 'Search Categories', 'tutor' ), |
| 151 |
'popular_items' => __( 'Popular Categories', 'tutor' ), |
| 152 |
'all_items' => __( 'All Categories', 'tutor' ), |
| 153 |
'parent_item' => null, |
| 154 |
'parent_item_colon' => null, |
| 155 |
'edit_item' => __( 'Edit Category', 'tutor' ), |
| 156 |
'update_item' => __( 'Update Category', 'tutor' ), |
| 157 |
'add_new_item' => __( 'Add New Category', 'tutor' ), |
| 158 |
'new_item_name' => __( 'New Category Name', 'tutor' ), |
| 159 |
'separate_items_with_commas' => __( 'Separate categories with commas', 'tutor' ), |
| 160 |
'add_or_remove_items' => __( 'Add or remove categories', 'tutor' ), |
| 161 |
'choose_from_most_used' => __( 'Choose from the most used categories', 'tutor' ), |
| 162 |
'not_found' => __( 'No categories found.', 'tutor' ), |
| 163 |
'menu_name' => __( 'Course Categories', 'tutor' ), |
| 164 |
); |
| 165 |
|
| 166 |
$args = array( |
| 167 |
'hierarchical' => true, |
| 168 |
'labels' => $labels, |
| 169 |
'show_ui' => true, |
| 170 |
'show_admin_column' => true, |
| 171 |
'update_count_callback' => '_update_post_term_count', |
| 172 |
'query_var' => true, |
| 173 |
'show_in_rest' => true, |
| 174 |
'rewrite' => array( 'slug' => 'course-category' ), |
| 175 |
); |
| 176 |
|
| 177 |
register_taxonomy( 'course-category', $this->course_post_type, $args ); |
| 178 |
|
| 179 |
$labels = array( |
| 180 |
'name' => _x( 'Tags', 'taxonomy general name', 'tutor' ), |
| 181 |
'singular_name' => _x( 'Tag', 'taxonomy singular name', 'tutor' ), |
| 182 |
'search_items' => __( 'Search Tags', 'tutor' ), |
| 183 |
'popular_items' => __( 'Popular Tags', 'tutor' ), |
| 184 |
'all_items' => __( 'All Tags', 'tutor' ), |
| 185 |
'parent_item' => null, |
| 186 |
'parent_item_colon' => null, |
| 187 |
'edit_item' => __( 'Edit Tag', 'tutor' ), |
| 188 |
'update_item' => __( 'Update Tag', 'tutor' ), |
| 189 |
'add_new_item' => __( 'Add New Tag', 'tutor' ), |
| 190 |
'new_item_name' => __( 'New Tag Name', 'tutor' ), |
| 191 |
'separate_items_with_commas' => __( 'Separate Tags with commas', 'tutor' ), |
| 192 |
'add_or_remove_items' => __( 'Add or remove Tags', 'tutor' ), |
| 193 |
'choose_from_most_used' => __( 'Choose from the most used Tags', 'tutor' ), |
| 194 |
'not_found' => __( 'No Tags found.', 'tutor' ), |
| 195 |
'menu_name' => __( 'Tags', 'tutor' ), |
| 196 |
); |
| 197 |
|
| 198 |
$args = array( |
| 199 |
'hierarchical' => false, |
| 200 |
'labels' => $labels, |
| 201 |
'show_ui' => true, |
| 202 |
'show_admin_column' => true, |
| 203 |
'update_count_callback' => '_update_post_term_count', |
| 204 |
'query_var' => true, |
| 205 |
'show_in_rest' => true, |
| 206 |
'rewrite' => array( 'slug' => 'course-tag' ), |
| 207 |
); |
| 208 |
|
| 209 |
register_taxonomy( 'course-tag', $this->course_post_type, $args ); |
| 210 |
} |
| 211 |
|
| 212 |
/** |
| 213 |
* Register lesson post type |
| 214 |
* |
| 215 |
* @since 1.0.0 |
| 216 |
* |
| 217 |
* @return void |
| 218 |
*/ |
| 219 |
public function register_lesson_post_types() { |
| 220 |
$lesson_post_type = $this->lesson_post_type; |
| 221 |
$lesson_base_slug = apply_filters( 'tutor_lesson_base_slug', $lesson_post_type ); |
| 222 |
|
| 223 |
$labels = array( |
| 224 |
'name' => _x( 'Lessons', 'post type general name', 'tutor' ), |
| 225 |
'singular_name' => _x( 'Lesson', 'post type singular name', 'tutor' ), |
| 226 |
'menu_name' => _x( 'Lessons', 'admin menu', 'tutor' ), |
| 227 |
'name_admin_bar' => _x( 'Lesson', 'add new on admin bar', 'tutor' ), |
| 228 |
'add_new' => _x( 'Add New', 'tutor lesson add', 'tutor' ), |
| 229 |
'add_new_item' => __( 'Add New Lesson', 'tutor' ), |
| 230 |
'new_item' => __( 'New Lesson', 'tutor' ), |
| 231 |
'edit_item' => __( 'Edit Lesson', 'tutor' ), |
| 232 |
'view_item' => __( 'View Lesson', 'tutor' ), |
| 233 |
'all_items' => __( 'Lessons', 'tutor' ), |
| 234 |
'search_items' => __( 'Search Lessons', 'tutor' ), |
| 235 |
'parent_item_colon' => __( 'Parent Lessons:', 'tutor' ), |
| 236 |
'not_found' => __( 'No lessons found.', 'tutor' ), |
| 237 |
'not_found_in_trash' => __( 'No lessons found in Trash.', 'tutor' ), |
| 238 |
); |
| 239 |
|
| 240 |
$args = array( |
| 241 |
'labels' => $labels, |
| 242 |
'description' => __( 'Description.', 'tutor' ), |
| 243 |
'public' => true, |
| 244 |
'publicly_queryable' => true, |
| 245 |
'show_ui' => true, |
| 246 |
'show_in_menu' => false, |
| 247 |
'query_var' => true, |
| 248 |
'rewrite' => array( 'slug' => $lesson_base_slug ), |
| 249 |
'menu_icon' => 'dashicons-list-view', |
| 250 |
'capability_type' => 'post', |
| 251 |
'has_archive' => true, |
| 252 |
'hierarchical' => false, |
| 253 |
'menu_position' => null, |
| 254 |
'supports' => array( 'title', 'editor', 'comments' ), |
| 255 |
'exclude_from_search' => apply_filters( 'tutor_lesson_exclude_from_search', true ), |
| 256 |
'capabilities' => array( |
| 257 |
'edit_post' => 'edit_tutor_lesson', |
| 258 |
'read_post' => 'read_tutor_lesson', |
| 259 |
'delete_post' => 'delete_tutor_lesson', |
| 260 |
'delete_posts' => 'delete_tutor_lessons', |
| 261 |
'edit_posts' => 'edit_tutor_lessons', |
| 262 |
'edit_others_posts' => 'edit_others_tutor_lessons', |
| 263 |
'publish_posts' => 'publish_tutor_lessons', |
| 264 |
'read_private_posts' => 'read_private_tutor_lessons', |
| 265 |
'create_posts' => 'edit_tutor_lessons', |
| 266 |
), |
| 267 |
); |
| 268 |
|
| 269 |
/** |
| 270 |
* Added for support gutenberg editor to lesson post type |
| 271 |
* |
| 272 |
* @since 2.1.6 |
| 273 |
*/ |
| 274 |
$enable_gutenberg = (bool) tutor_utils()->get_option( 'enable_gutenberg_course_edit' ); |
| 275 |
if ( $enable_gutenberg ) { |
| 276 |
$args['show_in_rest'] = true; |
| 277 |
} |
| 278 |
|
| 279 |
register_post_type( $lesson_post_type, $args ); |
| 280 |
} |
| 281 |
|
| 282 |
/** |
| 283 |
* Register quiz post type |
| 284 |
* |
| 285 |
* @since 1.0.0 |
| 286 |
* |
| 287 |
* @return void |
| 288 |
*/ |
| 289 |
public function register_quiz_post_types() { |
| 290 |
$labels = array( |
| 291 |
'name' => _x( 'Quizzes', 'post type general name', 'tutor' ), |
| 292 |
'singular_name' => _x( 'Quiz', 'post type singular name', 'tutor' ), |
| 293 |
'menu_name' => _x( 'Quizzes', 'admin menu', 'tutor' ), |
| 294 |
'name_admin_bar' => _x( 'Quiz', 'add new on admin bar', 'tutor' ), |
| 295 |
'add_new' => _x( 'Add New', 'tutor quiz add', 'tutor' ), |
| 296 |
'add_new_item' => __( 'Add New Quiz', 'tutor' ), |
| 297 |
'new_item' => __( 'New Quiz', 'tutor' ), |
| 298 |
'edit_item' => __( 'Edit Quiz', 'tutor' ), |
| 299 |
'view_item' => __( 'View Quiz', 'tutor' ), |
| 300 |
'all_items' => __( 'Quizzes', 'tutor' ), |
| 301 |
'search_items' => __( 'Search Quizzes', 'tutor' ), |
| 302 |
'parent_item_colon' => __( 'Parent Quizzes:', 'tutor' ), |
| 303 |
'not_found' => __( 'No quizzes found.', 'tutor' ), |
| 304 |
'not_found_in_trash' => __( 'No quizzes found in Trash.', 'tutor' ), |
| 305 |
); |
| 306 |
|
| 307 |
$args = array( |
| 308 |
'labels' => $labels, |
| 309 |
'description' => __( 'Description.', 'tutor' ), |
| 310 |
'public' => true, |
| 311 |
'publicly_queryable' => true, |
| 312 |
'show_ui' => false, |
| 313 |
'show_in_menu' => 'tutor', |
| 314 |
'query_var' => true, |
| 315 |
'rewrite' => array( 'slug' => $this->lesson_post_type ), |
| 316 |
'menu_icon' => 'dashicons-editor-help', |
| 317 |
'capability_type' => 'post', |
| 318 |
'has_archive' => true, |
| 319 |
'hierarchical' => false, |
| 320 |
'menu_position' => null, |
| 321 |
'supports' => array( 'title', 'editor' ), |
| 322 |
'exclude_from_search' => apply_filters( 'tutor_quiz_exclude_from_search', true ), |
| 323 |
'capabilities' => array( |
| 324 |
'edit_post' => 'edit_tutor_quiz', |
| 325 |
'read_post' => 'read_tutor_quiz', |
| 326 |
'delete_post' => 'delete_tutor_quiz', |
| 327 |
'delete_posts' => 'delete_tutor_quizzes', |
| 328 |
'edit_posts' => 'edit_tutor_quizzes', |
| 329 |
'edit_others_posts' => 'edit_others_tutor_quizzes', |
| 330 |
'publish_posts' => 'publish_tutor_quizzes', |
| 331 |
'read_private_posts' => 'read_private_tutor_quizzes', |
| 332 |
'create_posts' => 'edit_tutor_quizzes', |
| 333 |
), |
| 334 |
); |
| 335 |
|
| 336 |
register_post_type( 'tutor_quiz', $args ); |
| 337 |
} |
| 338 |
|
| 339 |
/** |
| 340 |
* Register topic post type |
| 341 |
* |
| 342 |
* @since 1.0.0 |
| 343 |
* |
| 344 |
* @return void |
| 345 |
*/ |
| 346 |
public function register_topic_post_types() { |
| 347 |
$args = array( |
| 348 |
'label' => 'Topics', |
| 349 |
'description' => __( 'Description.', 'tutor' ), |
| 350 |
'public' => false, |
| 351 |
'publicly_queryable' => false, |
| 352 |
'show_ui' => false, |
| 353 |
'query_var' => false, |
| 354 |
'has_archive' => false, |
| 355 |
'hierarchical' => false, |
| 356 |
'menu_position' => null, |
| 357 |
); |
| 358 |
register_post_type( 'topics', $args ); |
| 359 |
} |
| 360 |
|
| 361 |
/** |
| 362 |
* Register assignment post type |
| 363 |
* |
| 364 |
* @since 1.0.0 |
| 365 |
* |
| 366 |
* @return void |
| 367 |
*/ |
| 368 |
public function register_assignments_post_types() { |
| 369 |
$labels = array( |
| 370 |
'name' => _x( 'Assignments', 'post type general name', 'tutor' ), |
| 371 |
'singular_name' => _x( 'Assignment', 'post type singular name', 'tutor' ), |
| 372 |
'menu_name' => _x( 'Assignments', 'admin menu', 'tutor' ), |
| 373 |
'name_admin_bar' => _x( 'Assignment', 'add new on admin bar', 'tutor' ), |
| 374 |
'add_new' => _x( 'Add New', 'tutor assignment add', 'tutor' ), |
| 375 |
'add_new_item' => __( 'Add New Assignment', 'tutor' ), |
| 376 |
'new_item' => __( 'New Assignment', 'tutor' ), |
| 377 |
'edit_item' => __( 'Edit Assignment', 'tutor' ), |
| 378 |
'view_item' => __( 'View Assignment', 'tutor' ), |
| 379 |
'all_items' => __( 'Assignments', 'tutor' ), |
| 380 |
'search_items' => __( 'Search Assignments', 'tutor' ), |
| 381 |
'parent_item_colon' => __( 'Parent Assignments:', 'tutor' ), |
| 382 |
'not_found' => __( 'No Assignments found.', 'tutor' ), |
| 383 |
'not_found_in_trash' => __( 'No Assignments found in Trash.', 'tutor' ), |
| 384 |
); |
| 385 |
|
| 386 |
$args = array( |
| 387 |
'labels' => $labels, |
| 388 |
'description' => __( 'Description.', 'tutor' ), |
| 389 |
'public' => true, |
| 390 |
'publicly_queryable' => true, |
| 391 |
'show_ui' => false, |
| 392 |
'show_in_menu' => 'tutor', |
| 393 |
'query_var' => true, |
| 394 |
'rewrite' => array( 'slug' => $this->lesson_post_type ), |
| 395 |
'menu_icon' => 'dashicons-editor-help', |
| 396 |
'capability_type' => 'post', |
| 397 |
'has_archive' => true, |
| 398 |
'hierarchical' => false, |
| 399 |
'menu_position' => null, |
| 400 |
'supports' => array( 'title', 'editor' ), |
| 401 |
'exclude_from_search' => apply_filters( 'tutor_assignment_exclude_from_search', true ), |
| 402 |
'capabilities' => array( |
| 403 |
'edit_post' => 'edit_tutor_assignment', |
| 404 |
'read_post' => 'read_tutor_assignment', |
| 405 |
'delete_post' => 'delete_tutor_assignment', |
| 406 |
'delete_posts' => 'delete_tutor_assignments', |
| 407 |
'edit_posts' => 'edit_tutor_assignments', |
| 408 |
'edit_others_posts' => 'edit_others_tutor_assignments', |
| 409 |
'publish_posts' => 'publish_tutor_assignments', |
| 410 |
'read_private_posts' => 'read_private_tutor_assignments', |
| 411 |
'create_posts' => 'edit_tutor_assignments', |
| 412 |
), |
| 413 |
); |
| 414 |
|
| 415 |
register_post_type( 'tutor_assignments', $args ); |
| 416 |
} |
| 417 |
|
| 418 |
/** |
| 419 |
* Course update messages |
| 420 |
* |
| 421 |
* @since 1.0.0 |
| 422 |
* |
| 423 |
* @param array $messages messages. |
| 424 |
* |
| 425 |
* @return mixed |
| 426 |
*/ |
| 427 |
public function course_updated_messages( $messages ) { |
| 428 |
$post = get_post(); |
| 429 |
$post_type = get_post_type( $post ); |
| 430 |
$post_type_object = get_post_type_object( $post_type ); |
| 431 |
|
| 432 |
$course_post_type = tutor()->course_post_type; |
| 433 |
|
| 434 |
$revision = Input::get( 'revision' ); |
| 435 |
$revision_msg = __( 'Course restored to revision from ', 'tutor' ); |
| 436 |
if ( ! is_null( $revision ) ) { |
| 437 |
$revision_msg .= wp_post_revision_title( $revision ); |
| 438 |
} else { |
| 439 |
$revision_msg = false; |
| 440 |
} |
| 441 |
|
| 442 |
$schedule_date = date_i18n( __( 'M j, Y @ G:i', 'tutor' ), strtotime( $post->post_date ) ); |
| 443 |
$schedule_msg = __( 'Course scheduled for:', 'tutor' ); |
| 444 |
$schedule_msg .= ' <strong> ' . $schedule_date . ' </strong>'; |
| 445 |
|
| 446 |
$messages[ $course_post_type ] = array( |
| 447 |
0 => '', // Unused. Messages start at index 1. |
| 448 |
1 => __( 'Course updated.', 'tutor' ), |
| 449 |
2 => __( 'Custom field updated.', 'tutor' ), |
| 450 |
3 => __( 'Custom field deleted.', 'tutor' ), |
| 451 |
4 => __( 'Course updated.', 'tutor' ), |
| 452 |
5 => $revision_msg, |
| 453 |
6 => __( 'Course published.', 'tutor' ), |
| 454 |
7 => __( 'Course saved.', 'tutor' ), |
| 455 |
8 => __( 'Course submitted.', 'tutor' ), |
| 456 |
9 => $schedule_msg, |
| 457 |
10 => __( 'Course draft updated.', 'tutor' ), |
| 458 |
); |
| 459 |
|
| 460 |
if ( $post_type_object->publicly_queryable && $course_post_type === $post_type ) { |
| 461 |
$permalink = get_permalink( $post->ID ); |
| 462 |
|
| 463 |
$view_link = sprintf( ' <a href="%s">%s</a>', esc_url( $permalink ), __( 'View course', 'tutor' ) ); |
| 464 |
$messages[ $post_type ][1] .= $view_link; |
| 465 |
$messages[ $post_type ][6] .= $view_link; |
| 466 |
$messages[ $post_type ][9] .= $view_link; |
| 467 |
|
| 468 |
$preview_permalink = add_query_arg( 'preview', 'true', $permalink ); |
| 469 |
$preview_link = sprintf( ' <a target="_blank" href="%s">%s</a>', esc_url( $preview_permalink ), __( 'Preview course', 'tutor' ) ); |
| 470 |
$messages[ $post_type ][8] .= $preview_link; |
| 471 |
$messages[ $post_type ][10] .= $preview_link; |
| 472 |
} |
| 473 |
|
| 474 |
return $messages; |
| 475 |
} |
| 476 |
|
| 477 |
/** |
| 478 |
* Gutenberg can edit post filter handler |
| 479 |
* |
| 480 |
* @since 1.0.0 |
| 481 |
* |
| 482 |
* @param bool $can_edit use block editor. |
| 483 |
* @param string $post_type post type. |
| 484 |
* |
| 485 |
* @return bool |
| 486 |
* |
| 487 |
* Enable / Disable Gutenberg Editor |
| 488 |
* @since v.1.3.4 |
| 489 |
*/ |
| 490 |
public function gutenberg_can_edit_post_type( $can_edit, $post_type ) { |
| 491 |
$enable_gutenberg = (bool) tutor_utils()->get_option( 'enable_gutenberg_course_edit' ); |
| 492 |
return $this->course_post_type === $post_type ? $enable_gutenberg : $can_edit; |
| 493 |
} |
| 494 |
|
| 495 |
/** |
| 496 |
* Register tutor_enrolled post type |
| 497 |
* |
| 498 |
* @since v.1.4.0 |
| 499 |
*/ |
| 500 |
public function register_tutor_enrolled_post_types() { |
| 501 |
$args = array( |
| 502 |
'label' => 'Tutor Enrolled', |
| 503 |
'description' => __( 'Description.', 'tutor' ), |
| 504 |
'public' => false, |
| 505 |
'publicly_queryable' => false, |
| 506 |
'show_ui' => false, |
| 507 |
'query_var' => false, |
| 508 |
'has_archive' => false, |
| 509 |
'hierarchical' => false, |
| 510 |
'menu_position' => null, |
| 511 |
); |
| 512 |
register_post_type( 'tutor_enrolled', $args ); |
| 513 |
} |
| 514 |
|
| 515 |
/** |
| 516 |
* Remove course post menu |
| 517 |
* |
| 518 |
* @return void |
| 519 |
* @since v2.0.0 |
| 520 |
*/ |
| 521 |
public function remove_course_post_menu() { |
| 522 |
remove_menu_page( 'edit.php?post_type=' . tutor()->course_post_type ); |
| 523 |
} |
| 524 |
} |
| 525 |
|