WordPress.org

Make WordPress Core

Changeset 32411


Ignore:
Timestamp:
05/06/2015 08:49:29 PM (6 years ago)
Author:
jorbin
Message:

When upgrading WordPress remove genericons example.html files

[32385] for 3.7 branch

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

File:
1 edited

Legend:

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

    r27885 r32411  
    882882    }
    883883
     884    // Remove any Genericons example.html's from the filesystem
     885    _upgrade_422_remove_genericons();
     886
    884887    // Upgrade DB with separate request
    885888    apply_filters('update_feedback', __('Upgrading database…'));
     
    10101013}
    10111014add_action( '_core_updated_successfully', '_redirect_to_about_wordpress' );
     1015
     1016/**
     1017 * Cleans up Genericons example files.
     1018 *
     1019 * @since 4.2.2
     1020 */
     1021function _upgrade_422_remove_genericons() {
     1022    global $wp_theme_directories, $wp_filesystem;
     1023
     1024    // A list of the affected files using the filesystem absolute paths.
     1025    $affected_files = array();
     1026
     1027    // Themes
     1028    foreach ( $wp_theme_directories as $directory ) {
     1029        $affected_theme_files = _upgrade_422_find_genericons_files_in_folder( $directory );
     1030        $affected_files       = array_merge( $affected_files, $affected_theme_files );
     1031    }
     1032
     1033    // Plugins
     1034    $affected_plugin_files = _upgrade_422_find_genericons_files_in_folder( WP_PLUGIN_DIR );
     1035    $affected_files        = array_merge( $affected_files, $affected_plugin_files );
     1036
     1037    foreach ( $affected_files as $file ) {
     1038        $gen_dir = $wp_filesystem->find_folder( trailingslashit( dirname( $file ) ) );
     1039        if ( empty( $gen_dir ) ) {
     1040            continue;
     1041        }
     1042
     1043        // The path when the file is accessed via WP_Filesystem may differ in the case of FTP
     1044        $remote_file = $gen_dir . basename( $file );
     1045
     1046        if ( ! $wp_filesystem->exists( $remote_file ) ) {
     1047            continue;
     1048        }
     1049
     1050        if ( ! $wp_filesystem->delete( $remote_file, false, 'f' ) ) {
     1051            $wp_filesystem->put_contents( $remote_file, '' );
     1052        }
     1053    }
     1054}
     1055
     1056/**
     1057 * Recursively find Genericons example files in a given folder.
     1058 *
     1059 * @ignore
     1060 * @since 4.2.2
     1061 *
     1062 * @param string $directory Directory path. Expects trailingslashed.
     1063 * @return array
     1064 */
     1065function _upgrade_422_find_genericons_files_in_folder( $directory ) {
     1066    $directory = trailingslashit( $directory );
     1067    $files     = array();
     1068
     1069    if ( file_exists( "{$directory}example.html" ) && false !== strpos( file_get_contents( "{$directory}example.html" ), '<title>Genericons</title>' ) ) {
     1070        $files[] = "{$directory}example.html";
     1071    }
     1072
     1073    foreach ( glob( $directory . '*', GLOB_ONLYDIR ) as $dir ) {
     1074        $files = array_merge( $files, _upgrade_422_find_genericons_files_in_folder( $dir ) );
     1075    }
     1076
     1077    return $files;
     1078}
Note: See TracChangeset for help on using the changeset viewer.