Make WordPress Core


Ignore:
Timestamp:
05/06/2015 08:04:19 PM (11 years ago)
Author:
jorbin
Message:

When upgrading WordPress remove genericons example.html files

[32385] for 4.0 branch

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

File:
1 edited

Legend:

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

    r29206 r32404  
    10121012    }
    10131013
     1014    // Remove any Genericons example.html's from the filesystem
     1015    _upgrade_422_remove_genericons();
     1016
    10141017    // Upgrade DB with separate request
    10151018    /** This filter is documented in wp-admin/includes/update-core.php */
     
    11501153}
    11511154add_action( '_core_updated_successfully', '_redirect_to_about_wordpress' );
     1155
     1156/**
     1157 * Cleans up Genericons example files.
     1158 *
     1159 * @since 4.2.2
     1160 */
     1161function _upgrade_422_remove_genericons() {
     1162    global $wp_theme_directories, $wp_filesystem;
     1163
     1164    // A list of the affected files using the filesystem absolute paths.
     1165    $affected_files = array();
     1166
     1167    // Themes
     1168    foreach ( $wp_theme_directories as $directory ) {
     1169        $affected_theme_files = _upgrade_422_find_genericons_files_in_folder( $directory );
     1170        $affected_files       = array_merge( $affected_files, $affected_theme_files );
     1171    }
     1172
     1173    // Plugins
     1174    $affected_plugin_files = _upgrade_422_find_genericons_files_in_folder( WP_PLUGIN_DIR );
     1175    $affected_files        = array_merge( $affected_files, $affected_plugin_files );
     1176
     1177    foreach ( $affected_files as $file ) {
     1178        $gen_dir = $wp_filesystem->find_folder( trailingslashit( dirname( $file ) ) );
     1179        if ( empty( $gen_dir ) ) {
     1180            continue;
     1181        }
     1182
     1183        // The path when the file is accessed via WP_Filesystem may differ in the case of FTP
     1184        $remote_file = $gen_dir . basename( $file );
     1185
     1186        if ( ! $wp_filesystem->exists( $remote_file ) ) {
     1187            continue;
     1188        }
     1189
     1190        if ( ! $wp_filesystem->delete( $remote_file, false, 'f' ) ) {
     1191            $wp_filesystem->put_contents( $remote_file, '' );
     1192        }
     1193    }
     1194}
     1195
     1196/**
     1197 * Recursively find Genericons example files in a given folder.
     1198 *
     1199 * @ignore
     1200 * @since 4.2.2
     1201 *
     1202 * @param string $directory Directory path. Expects trailingslashed.
     1203 * @return array
     1204 */
     1205function _upgrade_422_find_genericons_files_in_folder( $directory ) {
     1206    $directory = trailingslashit( $directory );
     1207    $files     = array();
     1208
     1209    if ( file_exists( "{$directory}example.html" ) && false !== strpos( file_get_contents( "{$directory}example.html" ), '<title>Genericons</title>' ) ) {
     1210        $files[] = "{$directory}example.html";
     1211    }
     1212
     1213    foreach ( glob( $directory . '*', GLOB_ONLYDIR ) as $dir ) {
     1214        $files = array_merge( $files, _upgrade_422_find_genericons_files_in_folder( $dir ) );
     1215    }
     1216
     1217    return $files;
     1218}
Note: See TracChangeset for help on using the changeset viewer.