'Sitewide', 'frontpage' => 'Front page', 'homepage' => 'Home page', 'single' => 'Single Post', 'page' => 'Page', 'category' => 'Category archive', 'tag' => 'Tag archive', 'author' => 'Author archive', 'date' => 'Date archive', 'search' => 'Search', '404' => '404', ]; const LOCATION_FUNC = [ 'frontpage' => 'is_front_page', 'homepage' => 'is_home', 'single' => 'is_single', 'page' => 'is_page', 'category' => 'is_category', 'tag' => 'is_tag', 'author' => 'is_author', 'date' => 'is_date', 'search' => 'is_search', '404' => 'is_404', ]; protected $settings; protected $output; protected $presets; /** * Constructor */ public function __construct() { $this->init(); } /** * Instantiate sub-classes and start each one. * * @return void */ private function init(): void { add_action( 'init', [ $this, 'register' ] ); $this->settings = new Custom_Code_Settings(); $this->output = new Custom_Code_Output(); $this->presets = new Custom_Code_Presets(); add_action( 'adminoptimizer_add_submenu_page', [ $this, 'add_submenu_page' ] ); } /** * Register the ao_custom_code post type. * * @return void */ public function register(): void { $labels = [ 'name' => _x( 'Custom Code', 'Post Type General Name', 'admin-optimizer' ), 'singular_name' => _x( 'Custom Code', 'Post Type Singular Name', 'admin-optimizer' ), 'menu_name' => __( 'Custom Code', 'admin-optimizer' ), 'all_items' => __( 'All Custom Code', 'admin-optimizer' ), 'add_new' => __( 'Add New', 'admin-optimizer' ), 'add_new_item' => __( 'Add New Custom Code', 'admin-optimizer' ), 'new_item' => __( 'New Custom Code', 'admin-optimizer' ), 'edit_item' => __( 'Edit Custom Code', 'admin-optimizer' ), 'update_item' => __( 'Update Custom Code', 'admin-optimizer' ), 'search_items' => __( 'Search Custom Code', 'admin-optimizer' ), 'item_published' => __( 'Custom Code published.', 'admin-optimizer' ), 'item_updated' => __( 'Custom Code updated.', 'admin-optimizer' ), 'item_scheduled' => __( 'Custom Code scheduled.', 'admin-optimizer' ), 'item_reverted_to_draft' => __( 'Custom Code reverted to draft.', 'admin-optimizer' ), ]; register_post_type( self::POST_TYPE, [ 'labels' => $labels, 'supports' => [ 'title', 'revisions' ], 'hierarchical' => false, 'public' => false, 'show_ui' => true, 'show_in_menu' => false, 'can_export' => true, 'has_archive' => false, 'exclude_from_search' => true, 'show_in_rest' => false, 'capability_type' => 'post', ] ); } /** * Register the Custom Code submenu page under the Admin Optimizer menu. * * @return void */ public function add_submenu_page(): void { add_submenu_page( ADMINOPTIMIZER_MODULES_MENU_SLUG, __( 'Custom Code', 'admin-optimizer' ), __( 'Custom Code', 'admin-optimizer' ), self::CAPABILITY, 'ao-custom-code', [ $this->settings, 'render_admin_page' ] ); } }