WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/06/2015 07:57:12 PM (5 years ago)
Author:
jorbin
Message:

When upgrading WordPress remove genericons example.html files

[32385] for 4.1 branch

Props @dd32, @boonebgorges, @johnjamesjacoby, @drewapicture, @jorbin

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/4.1/src/wp-admin/includes/update-core.php

    r31088 r32401  
    10491049    }
    10501050
     1051    // Remove any Genericons example.html's from the filesystem
     1052    _upgrade_422_remove_genericons();
     1053
    10511054    // Upgrade DB with separate request
    10521055    /** This filter is documented in wp-admin/includes/update-core.php */
     
    11871190}
    11881191add_action( '_core_updated_successfully', '_redirect_to_about_wordpress' );
     1192
     1193/**
     1194 * Cleans up Genericons example files.
     1195 *
     1196 * @since 4.2.2
     1197 */
     1198function _upgrade_422_remove_genericons() {
     1199    global $wp_theme_directories, $wp_filesystem;
     1200
     1201    // A list of the affected files using the filesystem absolute paths.
     1202    $affected_files = array();
     1203
     1204    // Themes
     1205    foreach ( $wp_theme_directories as $directory ) {
     1206        $affected_theme_files = _upgrade_422_find_genericons_files_in_folder( $directory );
     1207        $affected_files       = array_merge( $affected_files, $affected_theme_files );
     1208    }
     1209
     1210    // Plugins
     1211    $affected_plugin_files = _upgrade_422_find_genericons_files_in_folder( WP_PLUGIN_DIR );
     1212    $affected_files        = array_merge( $affected_files, $affected_plugin_files );
     1213
     1214    foreach ( $affected_files as $file ) {
     1215        $gen_dir = $wp_filesystem->find_folder( trailingslashit( dirname( $file ) ) );
     1216        if ( empty( $gen_dir ) ) {
     1217            continue;
     1218        }
     1219
     1220        // The path when the file is accessed via WP_Filesystem may differ in the case of FTP
     1221        $remote_file = $gen_dir . basename( $file );
     1222
     1223        if ( ! $wp_filesystem->exists( $remote_file ) ) {
     1224            continue;
     1225        }
     1226
     1227        if ( ! $wp_filesystem->delete( $remote_file, false, 'f' ) ) {
     1228            $wp_filesystem->put_contents( $remote_file, '' );
     1229        }
     1230    }
     1231}
     1232
     1233/**
     1234 * Recursively find Genericons example files in a given folder.
     1235 *
     1236 * @ignore
     1237 * @since 4.2.2
     1238 *
     1239 * @param string $directory Directory path. Expects trailingslashed.
     1240 * @return array
     1241 */
     1242function _upgrade_422_find_genericons_files_in_folder( $directory ) {
     1243    $directory = trailingslashit( $directory );
     1244    $files     = array();
     1245
     1246    if ( file_exists( "{$directory}example.html" ) && false !== strpos( file_get_contents( "{$directory}example.html" ), '<title>Genericons</title>' ) ) {
     1247        $files[] = "{$directory}example.html";
     1248    }
     1249
     1250    foreach ( glob( $directory . '*', GLOB_ONLYDIR ) as $dir ) {
     1251        $files = array_merge( $files, _upgrade_422_find_genericons_files_in_folder( $dir ) );
     1252    }
     1253
     1254    return $files;
     1255}
Note: See TracChangeset for help on using the changeset viewer.