Changeset 54269 for trunk/src/wp-includes/block-template-utils.php
- Timestamp:
- 09/20/2022 09:19:10 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-template-utils.php
r54210 r54269 148 148 'category' => array( 149 149 'title' => _x( 'Category', 'Template name' ), 150 'description' => __( 'Displays latest posts insingle post category.' ),150 'description' => __( 'Displays latest posts from a single post category.' ), 151 151 ), 152 152 'taxonomy' => array( … … 556 556 $has_theme_file = wp_get_theme()->get_stylesheet() === $theme && null !== $template_file; 557 557 558 $origin = get_post_meta( $post->ID, 'origin', true ); 558 $origin = get_post_meta( $post->ID, 'origin', true ); 559 $is_wp_suggestion = get_post_meta( $post->ID, 'is_wp_suggestion', true ); 559 560 560 561 $template = new WP_Block_Template(); … … 571 572 $template->status = $post->post_status; 572 573 $template->has_theme_file = $has_theme_file; 573 $template->is_custom = true;574 $template->is_custom = empty( $is_wp_suggestion ); 574 575 $template->author = $post->post_author; 575 576 … … 680 681 } 681 682 682 if ( $post_type && 683 if ( 684 $post_type && 683 685 isset( $template->post_types ) && 684 686 ! in_array( $post_type, $template->post_types, true ) … … 913 915 */ 914 916 function wp_is_theme_directory_ignored( $path ) { 915 $directories_to_ignore = array( '.svn', '.git', '.hg', '.bzr', 'node_modules', 'vendor' ); 917 $directories_to_ignore = array( '.DS_Store', '.svn', '.git', '.hg', '.bzr', 'node_modules', 'vendor' ); 918 916 919 foreach ( $directories_to_ignore as $directory ) { 917 if ( str pos( $path, $directory ) === 0) {920 if ( str_starts_with( $path, $directory ) ) { 918 921 return true; 919 922 } … … 1024 1027 return $filename; 1025 1028 } 1029 1030 /** 1031 * Gets the template hierarchy for the given template slug to be created. 1032 * 1033 * 1034 * Note: Always add `index` as the last fallback template. 1035 * 1036 * @since 6.1.0 1037 * 1038 * @param string $slug The template slug to be created. 1039 * @param boolean $is_custom Optional. Indicates if a template is custom or 1040 * part of the template hierarchy. Default false. 1041 * @param string $template_prefix Optional. The template prefix for the created template. 1042 * Used to extract the main template type, e.g. 1043 * in `taxonomy-books` the `taxonomy` is extracted. 1044 * Default empty string. 1045 * @return string[] The template hierarchy. 1046 */ 1047 function get_template_hierarchy( $slug, $is_custom = false, $template_prefix = '' ) { 1048 if ( 'index' === $slug ) { 1049 return array( 'index' ); 1050 } 1051 if ( $is_custom ) { 1052 return array( 'page', 'singular', 'index' ); 1053 } 1054 if ( 'front-page' === $slug ) { 1055 return array( 'front-page', 'home', 'index' ); 1056 } 1057 1058 $template_hierarchy = array( $slug ); 1059 1060 // Most default templates don't have `$template_prefix` assigned. 1061 if ( $template_prefix ) { 1062 list( $type ) = explode( '-', $template_prefix ); 1063 // These checks are needed because the `$slug` above is always added. 1064 if ( ! in_array( $template_prefix, array( $slug, $type ), true ) ) { 1065 $template_hierarchy[] = $template_prefix; 1066 } 1067 if ( $slug !== $type ) { 1068 $template_hierarchy[] = $type; 1069 } 1070 } 1071 1072 // Handle `archive` template. 1073 if ( 1074 str_starts_with( $slug, 'author' ) || 1075 str_starts_with( $slug, 'taxonomy' ) || 1076 str_starts_with( $slug, 'category' ) || 1077 str_starts_with( $slug, 'tag' ) || 1078 'date' === $slug 1079 ) { 1080 $template_hierarchy[] = 'archive'; 1081 } 1082 // Handle `single` template. 1083 if ( 'attachment' === $slug ) { 1084 $template_hierarchy[] = 'single'; 1085 } 1086 1087 // Handle `singular` template. 1088 if ( 1089 str_starts_with( $slug, 'single' ) || 1090 str_starts_with( $slug, 'page' ) || 1091 'attachment' === $slug 1092 ) { 1093 $template_hierarchy[] = 'singular'; 1094 } 1095 1096 $template_hierarchy[] = 'index'; 1097 1098 return $template_hierarchy; 1099 };
Note: See TracChangeset
for help on using the changeset viewer.