| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 3 |
|
| 4 |
/*---------------------------------------------------------*/ |
| 5 |
/* Custom Post Types */ |
| 6 |
/*---------------------------------------------------------*/ |
| 7 |
|
| 8 |
function mbt_post_types_init() { |
| 9 |
add_action('init', 'mbt_register_post_types'); |
| 10 |
add_filter('parent_file', 'mbt_override_post_types_parent_files'); |
| 11 |
add_filter('post_updated_messages', 'mbt_override_post_updated_messages'); |
| 12 |
} |
| 13 |
add_action('mbt_init', 'mbt_post_types_init'); |
| 14 |
|
| 15 |
function mbt_register_post_types() |
| 16 |
{ |
| 17 |
register_post_type('mbt_book', array( |
| 18 |
'labels' => array( |
| 19 |
'name' => __('Books', 'mybooktable'), |
| 20 |
'singular_name' => __('Book', 'mybooktable'), |
| 21 |
'all_items' => __('Books', 'mybooktable'), |
| 22 |
'add_new' => __('Add New Book', 'mybooktable'), |
| 23 |
'add_new_item' => __('Add New Book', 'mybooktable'), |
| 24 |
'new_item_name' => __('New Book', 'mybooktable'), |
| 25 |
'edit_item' => __('Edit Book', 'mybooktable'), |
| 26 |
'view_item' => __('View Book', 'mybooktable'), |
| 27 |
'update_item' => __('Update Book', 'mybooktable'), |
| 28 |
'search_items' => __('Search Books', 'mybooktable'), |
| 29 |
'parent_item' => __('Parent Book', 'mybooktable'), |
| 30 |
'parent_item_colon' => __('Parent Book:', 'mybooktable'), |
| 31 |
), |
| 32 |
'public' => true, |
| 33 |
'show_ui' => true, |
| 34 |
'capability_type' => 'post', |
| 35 |
'hierarchical' => false, |
| 36 |
'menu_position' => 5, |
| 37 |
'exclude_from_search' => false, |
| 38 |
'has_archive' => true, |
| 39 |
'show_in_rest' => true, |
| 40 |
'supports' => array('title'), |
| 41 |
'rewrite' => array('slug' => mbt_get_product_slug(), 'with_front' => false) |
| 42 |
)); |
| 43 |
} |
| 44 |
|
| 45 |
function mbt_override_post_types_parent_files() { |
| 46 |
global $pagenow, $parent_file, $submenu_file; |
| 47 |
|
| 48 |
if(($pagenow == "post.php" or $pagenow == "post-new.php") and get_post_type() == "mbt_book") { |
| 49 |
$parent_file = "mbt_dashboard"; |
| 50 |
$submenu_file = "edit.php?post_type=mbt_book"; |
| 51 |
} |
| 52 |
|
| 53 |
return $parent_file; |
| 54 |
} |
| 55 |
|
| 56 |
function mbt_override_post_updated_messages($messages) { |
| 57 |
$post_id = (null!==get_the_ID() ? get_the_ID() : 0); |
| 58 |
if(get_post_type($post_id) == "mbt_book") { |
| 59 |
$messages['post'][1] = sprintf('Book updated. <a href="%s">View book</a>', esc_url(get_permalink($post_id))); |
| 60 |
} |
| 61 |
return $messages; |
| 62 |
} |
| 63 |
|
| 64 |
/*---------------------------------------------------------*/ |
| 65 |
/* Post Manager Columns */ |
| 66 |
/*---------------------------------------------------------*/ |
| 67 |
|
| 68 |
add_filter('manage_mbt_book_posts_columns', 'mbt_modify_post_manager_columns'); |
| 69 |
|
| 70 |
function mbt_modify_post_manager_columns($columns) { |
| 71 |
unset($columns['date']); |
| 72 |
return $columns; |
| 73 |
} |
| 74 |
|