AdminAjaxController.php
3 years ago
MetaController.php
3 years ago
NoticeController.php
3 years ago
PostTypeController.php
3 years ago
SettingsController.php
3 years ago
UpgradeController.php
3 years ago
PostTypeController.php
112 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Post Type Controller class. |
| 4 | * |
| 5 | * @package RT_TPG |
| 6 | */ |
| 7 | |
| 8 | namespace RT\ThePostGrid\Controllers\Admin; |
| 9 | |
| 10 | // Do not allow directly accessing this file. |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit( 'This script cannot be accessed directly.' ); |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * Post Type Controller class. |
| 17 | */ |
| 18 | class PostTypeController { |
| 19 | /** |
| 20 | * Class constructor |
| 21 | */ |
| 22 | public function __construct() { |
| 23 | add_action( 'init', [ $this, 'register_post_types' ], 1 ); |
| 24 | add_action( 'admin_init', [ $this, 'the_post_grid_remove_all_meta_box' ], 9999 ); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Remove meta box. |
| 29 | * |
| 30 | * @return void |
| 31 | */ |
| 32 | public function the_post_grid_remove_all_meta_box() { |
| 33 | if ( get_option( 'rttpg_activation_redirect', false ) ) { |
| 34 | delete_option( 'rttpg_activation_redirect' ); |
| 35 | wp_safe_redirect( admin_url( 'edit.php?post_type=rttpg&page=rttpg_settings§ion=common-settings' ) ); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Register post type |
| 41 | * |
| 42 | * @return void |
| 43 | */ |
| 44 | public function register_post_types() { |
| 45 | $labels = [ |
| 46 | 'name' => esc_html__( 'The Post Grid', 'the-post-grid' ), |
| 47 | 'singular_name' => esc_html__( 'The Post Grid', 'the-post-grid' ), |
| 48 | 'add_new' => esc_html__( 'Add New Grid', 'the-post-grid' ), |
| 49 | 'all_items' => esc_html__( 'All Grids', 'the-post-grid' ), |
| 50 | 'add_new_item' => esc_html__( 'Add New Post Grid', 'the-post-grid' ), |
| 51 | 'edit_item' => esc_html__( 'Edit Post Grid', 'the-post-grid' ), |
| 52 | 'new_item' => esc_html__( 'New Post Grid', 'the-post-grid' ), |
| 53 | 'view_item' => esc_html__( 'View Post Grid', 'the-post-grid' ), |
| 54 | 'search_items' => esc_html__( 'Search Post Grids', 'the-post-grid' ), |
| 55 | 'not_found' => esc_html__( 'No Post Grids found', 'the-post-grid' ), |
| 56 | 'not_found_in_trash' => esc_html__( 'No Post Grids found in Trash', 'the-post-grid' ), |
| 57 | ]; |
| 58 | |
| 59 | register_post_type( |
| 60 | rtTPG()->post_type, |
| 61 | [ |
| 62 | 'labels' => $labels, |
| 63 | 'public' => false, |
| 64 | 'show_ui' => true, |
| 65 | '_builtin' => false, |
| 66 | 'capability_type' => 'page', |
| 67 | 'hierarchical' => true, |
| 68 | 'menu_icon' => rtTPG()->get_assets_uri( 'images/icon-16x16.png' ), |
| 69 | 'rewrite' => false, |
| 70 | 'query_var' => rtTPG()->post_type, |
| 71 | 'supports' => [ |
| 72 | 'title', |
| 73 | ], |
| 74 | 'show_in_menu' => true, |
| 75 | 'menu_position' => 20, |
| 76 | ] |
| 77 | ); |
| 78 | |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Remove meta box |
| 83 | * |
| 84 | * @return array |
| 85 | */ |
| 86 | public function remove_all_meta_boxes_tgp_sc() { |
| 87 | global $wp_meta_boxes; |
| 88 | if ( isset( $wp_meta_boxes[ rtTPG()->post_type ]['normal']['high']['rttpg_meta'] ) && $wp_meta_boxes[ rtTPG()->post_type ]['normal']['high']['rttpg_sc_preview_meta'] && $wp_meta_boxes[ rtTPG()->post_type ]['side']['low']['rt_plugin_sc_pro_information'] |
| 89 | ) { |
| 90 | |
| 91 | $publishBox = $wp_meta_boxes[ rtTPG()->post_type ]['side']['core']['submitdiv']; |
| 92 | $scBox = $wp_meta_boxes[ rtTPG()->post_type ]['normal']['high']['rttpg_meta']; |
| 93 | $scBoxPreview = $wp_meta_boxes[ rtTPG()->post_type ]['normal']['high']['rttpg_sc_preview_meta']; |
| 94 | $docBox = $wp_meta_boxes[ rtTPG()->post_type ]['side']['low']['rt_plugin_sc_pro_information']; |
| 95 | |
| 96 | $wp_meta_boxes[ rtTPG()->post_type ] = [ |
| 97 | 'side' => [ |
| 98 | 'core' => [ 'submitdiv' => $publishBox ], |
| 99 | 'default' => [ |
| 100 | 'rt_plugin_sc_pro_information' => $docBox, |
| 101 | ], |
| 102 | ], |
| 103 | 'normal' => [ 'high' => [ 'submitdiv' => $scBox ] ], |
| 104 | 'advanced' => [ 'high' => [ 'postexcerpt' => $scBoxPreview ] ], |
| 105 | ]; |
| 106 | |
| 107 | return []; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | } |
| 112 |