block-templates.php
1 year ago
class-templates-list-table.php
2 years ago
default-template-types.php
7 months ago
full-site-editing.php
1 year ago
get-block-templates.php
1 year ago
template-loader.php
1 year ago
template-parts.php
1 month ago
templates.php
1 month ago
default-template-types.php
144 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Template types. |
| 4 | * |
| 5 | * @package gutenberg |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * Returns a filtered list of default template types, containing their |
| 10 | * localized titles and descriptions. |
| 11 | * |
| 12 | * @return array The default template types. |
| 13 | */ |
| 14 | function kubio_get_default_template_types() { |
| 15 | |
| 16 | if ( function_exists( 'gutenberg_get_default_template_types' ) ) { |
| 17 | return gutenberg_get_default_template_types(); |
| 18 | } |
| 19 | |
| 20 | if ( function_exists( 'get_default_template_types' ) ) { |
| 21 | return get_default_template_types(); |
| 22 | } |
| 23 | |
| 24 | $default_template_types = array( |
| 25 | 'index' => array( |
| 26 | 'title' => _x( 'Index', 'Template name', 'kubio' ), |
| 27 | 'description' => __( 'The default template used when no other template is available. This is a required template in WordPress.', 'kubio' ), |
| 28 | ), |
| 29 | 'home' => array( |
| 30 | 'title' => _x( 'Home', 'Template name', 'kubio' ), |
| 31 | 'description' => __( 'Template used for the main page that displays blog posts. This is the front page by default in WordPress. If a static front page is set, this is the template used for the page that contains the latest blog posts.', 'kubio' ), |
| 32 | ), |
| 33 | 'front-page' => array( |
| 34 | 'title' => _x( 'Front Page', 'Template name', 'kubio' ), |
| 35 | 'description' => __( 'Template used to render the front page of the site, whether it displays blog posts or a static page. The front page template takes precedence over the "Home" template.', 'kubio' ), |
| 36 | ), |
| 37 | 'singular' => array( |
| 38 | 'title' => _x( 'Singular', 'Template name', 'kubio' ), |
| 39 | 'description' => __( 'Template used for displaying single views of the content. This template is a fallback for the Single, Post, and Page templates, which take precedence when they exist.', 'kubio' ), |
| 40 | ), |
| 41 | 'single' => array( |
| 42 | 'title' => _x( 'Single Post', 'Template name', 'kubio' ), |
| 43 | 'description' => __( 'Template used to display a single blog post.', 'kubio' ), |
| 44 | ), |
| 45 | 'page' => array( |
| 46 | 'title' => _x( 'Page', 'Template name', 'kubio' ), |
| 47 | 'description' => __( 'Template used to display individual pages.', 'kubio' ), |
| 48 | ), |
| 49 | 'archive' => array( |
| 50 | 'title' => _x( 'Archive', 'Template name', 'kubio' ), |
| 51 | 'description' => __( 'The archive template displays multiple entries at once. It is used as a fallback for the Category, Author, and Date templates, which take precedence when they are available.', 'kubio' ), |
| 52 | ), |
| 53 | 'author' => array( |
| 54 | 'title' => _x( 'Author', 'Template name', 'kubio' ), |
| 55 | 'description' => __( 'Archive template used to display a list of posts from a single author.', 'kubio' ), |
| 56 | ), |
| 57 | 'category' => array( |
| 58 | 'title' => _x( 'Category', 'Template name', 'kubio' ), |
| 59 | 'description' => __( 'Archive template used to display a list of posts from the same category.', 'kubio' ), |
| 60 | ), |
| 61 | 'taxonomy' => array( |
| 62 | 'title' => _x( 'Taxonomy', 'Template name', 'kubio' ), |
| 63 | 'description' => __( 'Archive template used to display a list of posts from the same taxonomy.', 'kubio' ), |
| 64 | ), |
| 65 | 'date' => array( |
| 66 | 'title' => _x( 'Date', 'Template name', 'kubio' ), |
| 67 | 'description' => __( 'Archive template used to display a list of posts from a specific date.', 'kubio' ), |
| 68 | ), |
| 69 | 'tag' => array( |
| 70 | 'title' => _x( 'Tag', 'Template name', 'kubio' ), |
| 71 | 'description' => __( 'Archive template used to display a list of posts with a given tag.', 'kubio' ), |
| 72 | ), |
| 73 | 'attachment' => array( |
| 74 | 'title' => __( 'Media', 'kubio' ), |
| 75 | 'description' => __( 'Template used to display individual media items or attachments.', 'kubio' ), |
| 76 | ), |
| 77 | 'search' => array( |
| 78 | 'title' => _x( 'Search', 'Template name', 'kubio' ), |
| 79 | 'description' => __( 'Template used to display search results.', 'kubio' ), |
| 80 | ), |
| 81 | 'privacy-policy' => array( |
| 82 | 'title' => __( 'Privacy Policy', 'kubio' ), |
| 83 | 'description' => '', |
| 84 | ), |
| 85 | '404' => array( |
| 86 | 'title' => _x( '404', 'Template name', 'kubio' ), |
| 87 | 'description' => __( 'Template shown when no content is found.', 'kubio' ), |
| 88 | ), |
| 89 | ); |
| 90 | |
| 91 | /** |
| 92 | * Filters the list of template types. |
| 93 | * |
| 94 | * @param array $default_template_types An array of template types, formatted as [ slug => [ title, description ] ]. |
| 95 | * |
| 96 | * @since 5.x.x |
| 97 | */ |
| 98 | return apply_filters( 'default_template_types', $default_template_types ); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Converts the default template types array from associative to indexed, |
| 103 | * to be used in JS, where numeric keys (e.g. '404') always appear before alphabetical |
| 104 | * ones, regardless of the actual order of the array. |
| 105 | * |
| 106 | * From slug-keyed associative array: |
| 107 | * `[ 'index' => [ 'title' => 'Index', 'description' => 'Index template' ] ]` |
| 108 | * |
| 109 | * ...to indexed array with slug as property: |
| 110 | * `[ [ 'slug' => 'index', 'title' => 'Index', 'description' => 'Index template' ] ]` |
| 111 | * |
| 112 | * @return array The default template types as an indexed array. |
| 113 | */ |
| 114 | function kubio_get_indexed_default_template_types() { |
| 115 | |
| 116 | if ( function_exists( 'gutenberg_get_indexed_default_template_types()' ) ) { |
| 117 | return gutenberg_get_indexed_default_template_types(); |
| 118 | } |
| 119 | |
| 120 | $indexed_template_types = array(); |
| 121 | $default_template_types = kubio_get_default_template_types(); |
| 122 | foreach ( $default_template_types as $slug => $template_type ) { |
| 123 | $template_type['slug'] = strval( $slug ); |
| 124 | $indexed_template_types[] = $template_type; |
| 125 | } |
| 126 | return $indexed_template_types; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Return a list of all overrideable default template type slugs. |
| 131 | * |
| 132 | * @see get_query_template |
| 133 | * |
| 134 | * @return string[] List of all overrideable default template type slugs. |
| 135 | */ |
| 136 | function kubio_get_template_type_slugs() { |
| 137 | |
| 138 | if ( function_exists( 'get_default_block_template_types' ) ) { |
| 139 | return array_keys( get_default_block_template_types()); |
| 140 | } |
| 141 | |
| 142 | return array_keys( kubio_get_default_template_types() ); |
| 143 | } |
| 144 |