array( 'name' => _x( 'Buildify Templates', 'post type general name', 'buildify' ), 'singular_name' => _x( 'Template', 'post type singular name', 'buildify' ), 'add_new' => __( 'Add New Template', 'buildify' ), 'add_new_item' => __( 'Add New Template', 'buildify' ), 'edit_item' => __( 'Edit Template', 'buildify' ), 'new_item' => __( 'New Template', 'buildify' ), 'all_items' => __( 'Templates', 'buildify' ), 'view_item' => __( 'View Template', 'buildify' ), 'search_items' => __( 'Search Templates', 'buildify' ), 'not_found' => __( 'No templates found.', 'buildify' ), 'not_found_in_trash' => __( 'No templates found in Trash.', 'buildify' ), 'menu_name' => __( 'Templates', 'buildify' ), ), 'public' => false, 'publicly_queryable' => true, 'exclude_from_search' => true, 'show_ui' => true, 'show_in_menu' => false, 'show_in_nav_menus' => false, 'show_in_admin_bar' => false, 'show_in_rest' => false, 'has_archive' => false, 'hierarchical' => false, 'rewrite' => false, 'query_var' => true, 'can_export' => true, 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'elementor', 'revisions' ), 'map_meta_cap' => true, 'capabilities' => array( 'edit_posts' => $cap, 'edit_others_posts' => $cap, 'edit_private_posts' => $cap, 'edit_published_posts' => $cap, 'publish_posts' => $cap, 'read_private_posts' => $cap, 'delete_posts' => $cap, 'delete_private_posts' => $cap, 'delete_published_posts' => $cap, 'delete_others_posts' => $cap, 'create_posts' => $cap, ), ) ); } /** * Templates are only viewable by people who can edit them (the Elementor preview needs the URL). */ public function protect_front_end() { if ( ! is_singular( self::POST_TYPE ) ) { return; } if ( current_user_can( 'edit_post', get_queried_object_id() ) ) { return; } global $wp_query; $wp_query->set_404(); status_header( 404 ); nocache_headers(); } /** * Templates are edited with Elementor, not the block editor. * * @param bool $use Whether to use the block editor. * @param string $post_type Post type. * @return bool */ public function disable_block_editor( $use, $post_type ) { return self::POST_TYPE === $post_type ? false : $use; } /** * Keeps templates out of the core sitemap. * * @param array $post_types Post types. * @return array */ public function exclude_from_sitemap( $post_types ) { unset( $post_types[ self::POST_TYPE ] ); return $post_types; } /** * Adds noindex to template previews. * * @param array $robots Robots directives. * @return array */ public function no_robots( $robots ) { if ( is_singular( self::POST_TYPE ) ) { $robots['noindex'] = true; $robots['nofollow'] = true; } return $robots; } /** * Published template IDs of a type. * * @param string $type Template type. * @param string $status Post status. * @return int[] */ public static function get_ids( $type, $status = 'publish' ) { return array_map( 'intval', get_posts( array( 'post_type' => self::POST_TYPE, 'post_status' => $status, 'posts_per_page' => 200, 'fields' => 'ids', 'orderby' => 'modified', 'order' => 'DESC', 'suppress_filters' => false, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Small admin-only query on an indexed meta key. 'meta_query' => array( array( 'key' => self::TYPE_META, 'value' => $type, ), ), ) ) ); } }