array( 'name' => _x( 'Local Patterns (Legacy)', 'Post Type General Name', 'generateblocks-pro' ), 'singular_name' => _x( 'Local Pattern', 'Post Type Singular Name', 'generateblocks-pro' ), 'menu_name' => __( 'Local Patterns', 'generateblocks-pro' ), 'parent_item_colon' => __( 'Parent Local Pattern', 'generateblocks-pro' ), 'all_items' => __( 'Local Patterns', 'generateblocks-pro' ), 'view_item' => __( 'View Local Pattern', 'generateblocks-pro' ), 'add_new_item' => __( 'Add New Local Pattern', 'generateblocks-pro' ), 'add_new' => __( 'Add New', 'generateblocks-pro' ), 'edit_item' => __( 'Edit Local Pattern', 'generateblocks-pro' ), 'update_item' => __( 'Update Local Pattern', 'generateblocks-pro' ), 'search_items' => __( 'Search Local Pattern', 'generateblocks-pro' ), 'not_found' => __( 'Not Found', 'generateblocks-pro' ), 'not_found_in_trash' => __( 'Not found in Trash', 'generateblocks-pro' ), ), 'public' => false, 'publicly_queryable' => false, 'has_archive' => false, 'show_ui' => true, 'exclude_from_search' => true, 'show_in_nav_menus' => false, 'rewrite' => false, 'hierarchical' => false, 'show_in_menu' => false, 'show_in_admin_bar' => false, 'show_in_rest' => $this->should_show_in_rest(), 'capabilities' => array( 'create_posts' => 'do_not_allow', 'publish_posts' => 'manage_options', 'edit_posts' => 'manage_options', 'edit_others_posts' => 'manage_options', 'delete_posts' => 'manage_options', 'delete_others_posts' => 'manage_options', 'read_private_posts' => 'manage_options', 'edit_post' => 'manage_options', 'delete_post' => 'manage_options', 'read_post' => 'manage_options', ), 'supports' => array( 'title', 'editor', 'thumbnail', ), ) ); } /** * Determine if the legacy CPT should be exposed through core REST routes. * * @return bool */ private function should_show_in_rest() { if ( is_admin() ) { return true; } if ( function_exists( 'wp_is_json_request' ) && wp_is_json_request() ) { return current_user_can( 'manage_options' ); } return false; } /** * Redirect the empty legacy CPT list back to the dashboard. */ public function maybe_redirect_empty_legacy_templates() { global $pagenow; if ( ! in_array( $pagenow, array( 'edit.php', 'post-new.php' ), true ) ) { return; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Redirecting a read-only admin URL. $post_type = isset( $_GET['post_type'] ) ? sanitize_key( wp_unslash( $_GET['post_type'] ) ) : ''; if ( 'gblocks_templates' !== $post_type ) { return; } if ( generateblocks_pro_has_legacy_patterns() ) { return; } wp_safe_redirect( admin_url() ); exit; } /** * Trick the WordPress menu to highlight our Patterns menu item * when we're dealing with collections or categories. */ public function fix_menu() { global $parent_file, $submenu_file, $post_type; $screen = get_current_screen(); if ( 'edit-gblocks_templates' === $screen->id ) { $parent_file = 'generateblocks'; // phpcs:ignore -- Override necessary. $submenu_file = 'edit.php?post_type=wp_block'; // phpcs:ignore -- Override necessary. } } /** * Add a link to the new patterns. */ public function add_scripts() { $screen = get_current_screen(); if ( 'edit-gblocks_templates' !== $screen->id ) { return; } ?>