-10, 'default' => 10, 'late' => 99, ]; const ALL_LOCATIONS = [ 'sitewide' => '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 $output; protected $presets; /** * Instantiate sub-classes and start each one. * * @return void */ protected function init(): void { add_action( 'init', [ $this, 'register' ] ); add_action( 'init', [ $this, 'register_builtin_shortcodes' ], 10 ); $this->settings = new Custom_Code_Settings(); $this->output = new Custom_Code_Output(); $this->presets = new Custom_Code_Presets(); } /** * 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, 'capabilities' => [ 'edit_post' => self::CAPABILITY, 'read_post' => self::CAPABILITY, 'delete_post' => self::CAPABILITY, 'edit_posts' => self::CAPABILITY, 'edit_others_posts' => self::CAPABILITY, 'publish_posts' => self::CAPABILITY, 'read_private_posts' => self::CAPABILITY, 'delete_posts' => self::CAPABILITY, 'delete_private_posts' => self::CAPABILITY, 'delete_published_posts' => self::CAPABILITY, 'delete_others_posts' => self::CAPABILITY, 'edit_private_posts' => self::CAPABILITY, 'edit_published_posts' => self::CAPABILITY, 'create_posts' => self::CAPABILITY, ], ] ); } /** Register the built-in shortcode library. */ public function register_builtin_shortcodes(): void { add_shortcode( 'ao_copyright', static fn() => '©' ); add_shortcode( 'ao_year', static fn() => date_i18n( 'Y' ) ); add_shortcode( 'ao_sitename', static fn() => esc_html( get_bloginfo( 'name' ) ) ); add_shortcode( 'ao_tagline', static fn() => esc_html( get_bloginfo( 'description' ) ) ); add_shortcode( 'ao_home_url', static fn() => esc_url( home_url( '/' ) ) ); add_shortcode( 'ao_post_title', static fn() => is_singular() ? esc_html( get_the_title() ) : '' ); add_shortcode( 'ao_post_date', static fn() => is_singular() ? esc_html( get_the_date() ) : '' ); add_shortcode( 'ao_post_modified', static fn() => is_singular() ? esc_html( get_the_modified_date() ) : '' ); add_shortcode( 'ao_user_name', static fn() => is_user_logged_in() ? esc_html( wp_get_current_user()->display_name ) : '' ); add_shortcode( 'ao_user_email', static fn() => is_user_logged_in() ? esc_html( wp_get_current_user()->user_email ) : '' ); add_shortcode( 'ao_login_url', static fn() => esc_url( wp_login_url() ) ); add_shortcode( 'ao_logout_url', static fn() => esc_url( wp_logout_url() ) ); add_shortcode( 'ao_privacy_page', static function () { $url = get_privacy_policy_url(); return $url ? esc_url( $url ) : ''; } ); } /** * Include both the custom list page and native snippet edit screens. * * @param string $hook_suffix Current admin page hook suffix. */ protected function is_settings_screen( string $hook_suffix ): bool { if ( parent::is_settings_screen( $hook_suffix ) ) { return true; } $screen = get_current_screen(); return in_array( $hook_suffix, [ 'post.php', 'post-new.php' ], true ) && $screen && self::POST_TYPE === $screen->post_type; } }