Changeset 53129 for trunk/src/wp-includes/block-template-utils.php
- Timestamp:
- 04/11/2022 10:36:02 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-template-utils.php
r52923 r53129 120 120 'home' => array( 121 121 'title' => _x( 'Home', 'Template name' ), 122 'description' => __( 'Displays as the site\'s home page, or as the Posts page when a static home page isn\'tset.' ),122 'description' => __( 'Displays posts on the homepage, or on the Posts page if a static homepage is set.' ), 123 123 ), 124 124 'front-page' => array( 125 125 'title' => _x( 'Front Page', 'Template name' ), 126 'description' => __( 'Displays as the site\'s homepage.' ),126 'description' => __( 'Displays the homepage.' ), 127 127 ), 128 128 'singular' => array( … … 163 163 ), 164 164 'attachment' => array( 165 'title' => __( ' Attachment' ),165 'title' => __( 'Media' ), 166 166 'description' => __( 'Displays individual media items or attachments.' ), 167 167 ), 168 168 'search' => array( 169 169 'title' => _x( 'Search', 'Template name' ), 170 'description' => __( ' Template used to displaysearch results.' ),170 'description' => __( 'Displays search results.' ), 171 171 ), 172 172 'privacy-policy' => array( … … 904 904 905 905 /** 906 * Filters theme directories that should be ignored during export. 907 * 908 * @since 6.0.0 909 * 910 * @param string $path The path of the file in the theme. 911 * @return Bool Whether this file is in an ignored directory. 912 */ 913 function wp_is_theme_directory_ignored( $path ) { 914 $directories_to_ignore = array( '.svn', '.git', '.hg', '.bzr', 'node_modules', 'vendor' ); 915 foreach ( $directories_to_ignore as $directory ) { 916 if ( strpos( $path, $directory ) === 0 ) { 917 return true; 918 } 919 } 920 921 return false; 922 } 923 924 /** 906 925 * Creates an export of the current templates and 907 926 * template parts from the site editor at the … … 909 928 * 910 929 * @since 5.9.0 930 * @since 6.0.0 Adds the whole theme to the export archive. 911 931 * 912 932 * @return WP_Error|string Path of the ZIP file or error on failure. … … 917 937 } 918 938 919 $obscura = wp_generate_password( 12, false, false ); 920 $filename = get_temp_dir() . 'edit-site-export-' . $obscura . '.zip'; 939 $obscura = wp_generate_password( 12, false, false ); 940 $theme_name = wp_get_theme()->get( 'TextDomain' ); 941 $filename = get_temp_dir() . $theme_name . $obscura . '.zip'; 921 942 922 943 $zip = new ZipArchive(); 923 if ( true !== $zip->open( $filename, ZipArchive::CREATE ) ) {944 if ( true !== $zip->open( $filename, ZipArchive::CREATE | ZipArchive::OVERWRITE ) ) { 924 945 return new WP_Error( 'unable_to_create_zip', __( 'Unable to open export file (archive) for writing.' ) ); 925 946 } 926 947 927 $zip->addEmptyDir( 'theme' ); 928 $zip->addEmptyDir( 'theme/templates' ); 929 $zip->addEmptyDir( 'theme/parts' ); 948 $zip->addEmptyDir( 'templates' ); 949 $zip->addEmptyDir( 'parts' ); 950 951 // Get path of the theme. 952 $theme_path = wp_normalize_path( get_stylesheet_directory() ); 953 954 // Create recursive directory iterator. 955 $theme_files = new RecursiveIteratorIterator( 956 new RecursiveDirectoryIterator( $theme_path ), 957 RecursiveIteratorIterator::LEAVES_ONLY 958 ); 959 960 // Make a copy of the current theme. 961 foreach ( $theme_files as $file ) { 962 // Skip directories as they are added automatically. 963 if ( ! $file->isDir() ) { 964 // Get real and relative path for current file. 965 $file_path = wp_normalize_path( $file ); 966 $relative_path = substr( $file_path, strlen( $theme_path ) + 1 ); 967 968 if ( ! wp_is_theme_directory_ignored( $relative_path ) ) { 969 $zip->addFile( $file_path, $relative_path ); 970 } 971 } 972 } 930 973 931 974 // Load templates into the zip file. … … 935 978 936 979 $zip->addFromString( 937 't heme/templates/' . $template->slug . '.html',980 'templates/' . $template->slug . '.html', 938 981 $template->content 939 982 ); … … 944 987 foreach ( $template_parts as $template_part ) { 945 988 $zip->addFromString( 946 ' theme/parts/' . $template_part->slug . '.html',989 'parts/' . $template_part->slug . '.html', 947 990 $template_part->content 948 991 ); 949 992 } 950 993 994 // Load theme.json into the zip file. 995 $tree = WP_Theme_JSON_Resolver::get_theme_data( array(), array( 'with_supports' => false ) ); 996 // Merge with user data. 997 $tree->merge( WP_Theme_JSON_Resolver::get_user_data() ); 998 999 $theme_json_raw = $tree->get_data(); 1000 // If a version is defined, add a schema. 1001 if ( $theme_json_raw['version'] ) { 1002 global $wp_version; 1003 $theme_json_version = 'wp/' . substr( $wp_version, 0, 3 ); 1004 $schema = array( '$schema' => 'https://schemas.wp.org/' . $theme_json_version . '/theme.json' ); 1005 $theme_json_raw = array_merge( $schema, $theme_json_raw ); 1006 } 1007 1008 // Convert to a string. 1009 $theme_json_encoded = wp_json_encode( $theme_json_raw, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); 1010 1011 // Replace 4 spaces with a tab. 1012 $theme_json_tabbed = preg_replace( '~(?:^|\G)\h{4}~m', "\t", $theme_json_encoded ); 1013 1014 // Add the theme.json file to the zip. 1015 $zip->addFromString( 1016 'theme.json', 1017 $theme_json_tabbed 1018 ); 1019 951 1020 // Save changes to the zip file. 952 1021 $zip->close();
Note: See TracChangeset
for help on using the changeset viewer.