Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/update.php

    r41797 r42343  
    77 */
    88
    9 if ( ! defined( 'IFRAME_REQUEST' ) && isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'update-selected', 'activate-plugin', 'update-selected-themes' ) ) )
     9if ( ! defined( 'IFRAME_REQUEST' ) && isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'update-selected', 'activate-plugin', 'update-selected-themes' ) ) ) {
    1010        define( 'IFRAME_REQUEST', true );
     11}
    1112
    1213/** WordPress Administration Bootstrap */
     
    1516include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
    1617
    17 if ( isset($_GET['action']) ) {
    18         $plugin = isset($_REQUEST['plugin']) ? trim($_REQUEST['plugin']) : '';
    19         $theme = isset($_REQUEST['theme']) ? urldecode($_REQUEST['theme']) : '';
    20         $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
     18if ( isset( $_GET['action'] ) ) {
     19        $plugin = isset( $_REQUEST['plugin'] ) ? trim( $_REQUEST['plugin'] ) : '';
     20        $theme  = isset( $_REQUEST['theme'] ) ? urldecode( $_REQUEST['theme'] ) : '';
     21        $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
    2122
    2223        if ( 'update-selected' == $action ) {
    23                 if ( ! current_user_can( 'update_plugins' ) )
     24                if ( ! current_user_can( 'update_plugins' ) ) {
    2425                        wp_die( __( 'Sorry, you are not allowed to update plugins for this site.' ) );
     26                }
    2527
    2628                check_admin_referer( 'bulk-update-plugins' );
    2729
    28                 if ( isset( $_GET['plugins'] ) )
    29                         $plugins = explode( ',', stripslashes($_GET['plugins']) );
    30                 elseif ( isset( $_POST['checked'] ) )
     30                if ( isset( $_GET['plugins'] ) ) {
     31                        $plugins = explode( ',', stripslashes( $_GET['plugins'] ) );
     32                } elseif ( isset( $_POST['checked'] ) ) {
    3133                        $plugins = (array) $_POST['checked'];
    32                 else
     34                } else {
    3335                        $plugins = array();
    34 
    35                 $plugins = array_map('urldecode', $plugins);
    36 
    37                 $url = 'update.php?action=update-selected&plugins=' . urlencode(implode(',', $plugins));
     36                }
     37
     38                $plugins = array_map( 'urldecode', $plugins );
     39
     40                $url   = 'update.php?action=update-selected&plugins=' . urlencode( implode( ',', $plugins ) );
    3841                $nonce = 'bulk-update-plugins';
    3942
     
    4750
    4851        } elseif ( 'upgrade-plugin' == $action ) {
    49                 if ( ! current_user_can('update_plugins') )
    50                         wp_die(__('Sorry, you are not allowed to update plugins for this site.'));
    51 
    52                 check_admin_referer('upgrade-plugin_' . $plugin);
    53 
    54                 $title = __('Update Plugin');
    55                 $parent_file = 'plugins.php';
     52                if ( ! current_user_can( 'update_plugins' ) ) {
     53                        wp_die( __( 'Sorry, you are not allowed to update plugins for this site.' ) );
     54                }
     55
     56                check_admin_referer( 'upgrade-plugin_' . $plugin );
     57
     58                $title        = __( 'Update Plugin' );
     59                $parent_file  = 'plugins.php';
    5660                $submenu_file = 'plugins.php';
    5761
    5862                wp_enqueue_script( 'updates' );
    59                 require_once(ABSPATH . 'wp-admin/admin-header.php');
     63                require_once( ABSPATH . 'wp-admin/admin-header.php' );
    6064
    6165                $nonce = 'upgrade-plugin_' . $plugin;
    62                 $url = 'update.php?action=upgrade-plugin&plugin=' . urlencode( $plugin );
    63 
    64                 $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact('title', 'nonce', 'url', 'plugin') ) );
    65                 $upgrader->upgrade($plugin);
    66 
    67                 include(ABSPATH . 'wp-admin/admin-footer.php');
    68 
    69         } elseif ('activate-plugin' == $action ) {
    70                 if ( ! current_user_can('update_plugins') )
    71                         wp_die(__('Sorry, you are not allowed to update plugins for this site.'));
    72 
    73                 check_admin_referer('activate-plugin_' . $plugin);
    74                 if ( ! isset($_GET['failure']) && ! isset($_GET['success']) ) {
    75                         wp_redirect( admin_url('update.php?action=activate-plugin&failure=true&plugin=' . urlencode( $plugin ) . '&_wpnonce=' . $_GET['_wpnonce']) );
     66                $url   = 'update.php?action=upgrade-plugin&plugin=' . urlencode( $plugin );
     67
     68                $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'plugin' ) ) );
     69                $upgrader->upgrade( $plugin );
     70
     71                include( ABSPATH . 'wp-admin/admin-footer.php' );
     72
     73        } elseif ( 'activate-plugin' == $action ) {
     74                if ( ! current_user_can( 'update_plugins' ) ) {
     75                        wp_die( __( 'Sorry, you are not allowed to update plugins for this site.' ) );
     76                }
     77
     78                check_admin_referer( 'activate-plugin_' . $plugin );
     79                if ( ! isset( $_GET['failure'] ) && ! isset( $_GET['success'] ) ) {
     80                        wp_redirect( admin_url( 'update.php?action=activate-plugin&failure=true&plugin=' . urlencode( $plugin ) . '&_wpnonce=' . $_GET['_wpnonce'] ) );
    7681                        activate_plugin( $plugin, '', ! empty( $_GET['networkwide'] ), true );
    77                         wp_redirect( admin_url('update.php?action=activate-plugin&success=true&plugin=' . urlencode( $plugin ) . '&_wpnonce=' . $_GET['_wpnonce']) );
     82                        wp_redirect( admin_url( 'update.php?action=activate-plugin&success=true&plugin=' . urlencode( $plugin ) . '&_wpnonce=' . $_GET['_wpnonce'] ) );
    7883                        die();
    7984                }
    80                 iframe_header( __('Plugin Reactivation'), true );
    81                 if ( isset($_GET['success']) )
    82                         echo '<p>' . __('Plugin reactivated successfully.') . '</p>';
    83 
    84                 if ( isset($_GET['failure']) ){
    85                         echo '<p>' . __('Plugin failed to reactivate due to a fatal error.') . '</p>';
     85                iframe_header( __( 'Plugin Reactivation' ), true );
     86                if ( isset( $_GET['success'] ) ) {
     87                        echo '<p>' . __( 'Plugin reactivated successfully.' ) . '</p>';
     88                }
     89
     90                if ( isset( $_GET['failure'] ) ) {
     91                        echo '<p>' . __( 'Plugin failed to reactivate due to a fatal error.' ) . '</p>';
    8692
    8793                        error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR );
    88                         @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
     94                        @ini_set( 'display_errors', true ); //Ensure that Fatal errors are displayed.
    8995                        wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin );
    9096                        include( WP_PLUGIN_DIR . '/' . $plugin );
     
    9399        } elseif ( 'install-plugin' == $action ) {
    94100
    95                 if ( ! current_user_can('install_plugins') )
     101                if ( ! current_user_can( 'install_plugins' ) ) {
    96102                        wp_die( __( 'Sorry, you are not allowed to install plugins on this site.' ) );
     103                }
    97104
    98105                include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api..
    99106
    100107                check_admin_referer( 'install-plugin_' . $plugin );
    101                 $api = plugins_api( 'plugin_information', array(
    102                         'slug' => $plugin,
    103                         'fields' => array(
    104                                 'short_description' => false,
    105                                 'sections' => false,
    106                                 'requires' => false,
    107                                 'rating' => false,
    108                                 'ratings' => false,
    109                                 'downloaded' => false,
    110                                 'last_updated' => false,
    111                                 'added' => false,
    112                                 'tags' => false,
    113                                 'compatibility' => false,
    114                                 'homepage' => false,
    115                                 'donate_link' => false,
    116                         ),
    117                 ) );
     108                $api = plugins_api(
     109                        'plugin_information', array(
     110                                'slug'   => $plugin,
     111                                'fields' => array(
     112                                        'short_description' => false,
     113                                        'sections'          => false,
     114                                        'requires'          => false,
     115                                        'rating'            => false,
     116                                        'ratings'           => false,
     117                                        'downloaded'        => false,
     118                                        'last_updated'      => false,
     119                                        'added'             => false,
     120                                        'tags'              => false,
     121                                        'compatibility'     => false,
     122                                        'homepage'          => false,
     123                                        'donate_link'       => false,
     124                                ),
     125                        )
     126                );
    118127
    119128                if ( is_wp_error( $api ) ) {
    120                         wp_die( $api );
    121                 }
    122 
    123                 $title = __('Plugin Installation');
    124                 $parent_file = 'plugins.php';
     129                        wp_die( $api );
     130                }
     131
     132                $title        = __( 'Plugin Installation' );
     133                $parent_file  = 'plugins.php';
    125134                $submenu_file = 'plugin-install.php';
    126                 require_once(ABSPATH . 'wp-admin/admin-header.php');
    127 
    128                 $title = sprintf( __('Installing Plugin: %s'), $api->name . ' ' . $api->version );
     135                require_once( ABSPATH . 'wp-admin/admin-header.php' );
     136
     137                $title = sprintf( __( 'Installing Plugin: %s' ), $api->name . ' ' . $api->version );
    129138                $nonce = 'install-plugin_' . $plugin;
    130                 $url = 'update.php?action=install-plugin&plugin=' . urlencode( $plugin );
    131                 if ( isset($_GET['from']) )
    132                         $url .= '&from=' . urlencode(stripslashes($_GET['from']));
     139                $url   = 'update.php?action=install-plugin&plugin=' . urlencode( $plugin );
     140                if ( isset( $_GET['from'] ) ) {
     141                        $url .= '&from=' . urlencode( stripslashes( $_GET['from'] ) );
     142                }
    133143
    134144                $type = 'web'; //Install plugin type, From Web or an Upload.
    135145
    136                 $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
    137                 $upgrader->install($api->download_link);
    138 
    139                 include(ABSPATH . 'wp-admin/admin-footer.php');
     146                $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact( 'title', 'url', 'nonce', 'plugin', 'api' ) ) );
     147                $upgrader->install( $api->download_link );
     148
     149                include( ABSPATH . 'wp-admin/admin-footer.php' );
    140150
    141151        } elseif ( 'upload-plugin' == $action ) {
     
    145155                }
    146156
    147                 check_admin_referer('plugin-upload');
    148 
    149                 $file_upload = new File_Upload_Upgrader('pluginzip', 'package');
    150 
    151                 $title = __('Upload Plugin');
    152                 $parent_file = 'plugins.php';
     157                check_admin_referer( 'plugin-upload' );
     158
     159                $file_upload = new File_Upload_Upgrader( 'pluginzip', 'package' );
     160
     161                $title        = __( 'Upload Plugin' );
     162                $parent_file  = 'plugins.php';
    153163                $submenu_file = 'plugin-install.php';
    154                 require_once(ABSPATH . 'wp-admin/admin-header.php');
    155 
    156                 $title = sprintf( __('Installing Plugin from uploaded file: %s'), esc_html( basename( $file_upload->filename ) ) );
     164                require_once( ABSPATH . 'wp-admin/admin-header.php' );
     165
     166                $title = sprintf( __( 'Installing Plugin from uploaded file: %s' ), esc_html( basename( $file_upload->filename ) ) );
    157167                $nonce = 'plugin-upload';
    158                 $url = add_query_arg(array('package' => $file_upload->id), 'update.php?action=upload-plugin');
    159                 $type = 'upload'; //Install plugin type, From Web or an Upload.
    160 
    161                 $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
    162                 $result = $upgrader->install( $file_upload->package );
    163 
    164                 if ( $result || is_wp_error($result) )
     168                $url   = add_query_arg( array( 'package' => $file_upload->id ), 'update.php?action=upload-plugin' );
     169                $type  = 'upload'; //Install plugin type, From Web or an Upload.
     170
     171                $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact( 'type', 'title', 'nonce', 'url' ) ) );
     172                $result   = $upgrader->install( $file_upload->package );
     173
     174                if ( $result || is_wp_error( $result ) ) {
    165175                        $file_upload->cleanup();
    166 
    167                 include(ABSPATH . 'wp-admin/admin-footer.php');
     176                }
     177
     178                include( ABSPATH . 'wp-admin/admin-footer.php' );
    168179
    169180        } elseif ( 'upgrade-theme' == $action ) {
    170181
    171                 if ( ! current_user_can('update_themes') )
    172                         wp_die(__('Sorry, you are not allowed to update themes for this site.'));
    173 
    174                 check_admin_referer('upgrade-theme_' . $theme);
     182                if ( ! current_user_can( 'update_themes' ) ) {
     183                        wp_die( __( 'Sorry, you are not allowed to update themes for this site.' ) );
     184                }
     185
     186                check_admin_referer( 'upgrade-theme_' . $theme );
    175187
    176188                wp_enqueue_script( 'updates' );
    177189
    178                 $title = __('Update Theme');
    179                 $parent_file = 'themes.php';
     190                $title        = __( 'Update Theme' );
     191                $parent_file  = 'themes.php';
    180192                $submenu_file = 'themes.php';
    181                 require_once(ABSPATH . 'wp-admin/admin-header.php');
     193                require_once( ABSPATH . 'wp-admin/admin-header.php' );
    182194
    183195                $nonce = 'upgrade-theme_' . $theme;
    184                 $url = 'update.php?action=upgrade-theme&theme=' . urlencode( $theme );
    185 
    186                 $upgrader = new Theme_Upgrader( new Theme_Upgrader_Skin( compact('title', 'nonce', 'url', 'theme') ) );
    187                 $upgrader->upgrade($theme);
    188 
    189                 include(ABSPATH . 'wp-admin/admin-footer.php');
     196                $url   = 'update.php?action=upgrade-theme&theme=' . urlencode( $theme );
     197
     198                $upgrader = new Theme_Upgrader( new Theme_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'theme' ) ) );
     199                $upgrader->upgrade( $theme );
     200
     201                include( ABSPATH . 'wp-admin/admin-footer.php' );
    190202        } elseif ( 'update-selected-themes' == $action ) {
    191                 if ( ! current_user_can( 'update_themes' ) )
     203                if ( ! current_user_can( 'update_themes' ) ) {
    192204                        wp_die( __( 'Sorry, you are not allowed to update themes for this site.' ) );
     205                }
    193206
    194207                check_admin_referer( 'bulk-update-themes' );
    195208
    196                 if ( isset( $_GET['themes'] ) )
    197                         $themes = explode( ',', stripslashes($_GET['themes']) );
    198                 elseif ( isset( $_POST['checked'] ) )
     209                if ( isset( $_GET['themes'] ) ) {
     210                        $themes = explode( ',', stripslashes( $_GET['themes'] ) );
     211                } elseif ( isset( $_POST['checked'] ) ) {
    199212                        $themes = (array) $_POST['checked'];
    200                 else
     213                } else {
    201214                        $themes = array();
    202 
    203                 $themes = array_map('urldecode', $themes);
    204 
    205                 $url = 'update.php?action=update-selected-themes&amp;themes=' . urlencode(implode(',', $themes));
     215                }
     216
     217                $themes = array_map( 'urldecode', $themes );
     218
     219                $url   = 'update.php?action=update-selected-themes&amp;themes=' . urlencode( implode( ',', $themes ) );
    206220                $nonce = 'bulk-update-themes';
    207221
     
    215229        } elseif ( 'install-theme' == $action ) {
    216230
    217                 if ( ! current_user_can('install_themes') )
     231                if ( ! current_user_can( 'install_themes' ) ) {
    218232                        wp_die( __( 'Sorry, you are not allowed to install themes on this site.' ) );
     233                }
    219234
    220235                include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); //for themes_api..
    221236
    222237                check_admin_referer( 'install-theme_' . $theme );
    223                 $api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false, 'tags' => false) ) ); //Save on a bit of bandwidth.
     238                $api = themes_api(
     239                        'theme_information', array(
     240                                'slug'   => $theme,
     241                                'fields' => array(
     242                                        'sections' => false,
     243                                        'tags'     => false,
     244                                ),
     245                        )
     246                ); //Save on a bit of bandwidth.
    224247
    225248                if ( is_wp_error( $api ) ) {
     
    227250                }
    228251
    229                 $title = __('Install Themes');
    230                 $parent_file = 'themes.php';
     252                $title        = __( 'Install Themes' );
     253                $parent_file  = 'themes.php';
    231254                $submenu_file = 'themes.php';
    232                 require_once(ABSPATH . 'wp-admin/admin-header.php');
    233 
    234                 $title = sprintf( __('Installing Theme: %s'), $api->name . ' ' . $api->version );
     255                require_once( ABSPATH . 'wp-admin/admin-header.php' );
     256
     257                $title = sprintf( __( 'Installing Theme: %s' ), $api->name . ' ' . $api->version );
    235258                $nonce = 'install-theme_' . $theme;
    236                 $url = 'update.php?action=install-theme&theme=' . urlencode( $theme );
    237                 $type = 'web'; //Install theme type, From Web or an Upload.
    238 
    239                 $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
    240                 $upgrader->install($api->download_link);
    241 
    242                 include(ABSPATH . 'wp-admin/admin-footer.php');
     259                $url   = 'update.php?action=install-theme&theme=' . urlencode( $theme );
     260                $type  = 'web'; //Install theme type, From Web or an Upload.
     261
     262                $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact( 'title', 'url', 'nonce', 'plugin', 'api' ) ) );
     263                $upgrader->install( $api->download_link );
     264
     265                include( ABSPATH . 'wp-admin/admin-footer.php' );
    243266
    244267        } elseif ( 'upload-theme' == $action ) {
     
    248271                }
    249272
    250                 check_admin_referer('theme-upload');
    251 
    252                 $file_upload = new File_Upload_Upgrader('themezip', 'package');
    253 
    254                 $title = __('Upload Theme');
    255                 $parent_file = 'themes.php';
     273                check_admin_referer( 'theme-upload' );
     274
     275                $file_upload = new File_Upload_Upgrader( 'themezip', 'package' );
     276
     277                $title        = __( 'Upload Theme' );
     278                $parent_file  = 'themes.php';
    256279                $submenu_file = 'theme-install.php';
    257280
    258                 require_once(ABSPATH . 'wp-admin/admin-header.php');
    259 
    260                 $title = sprintf( __('Installing Theme from uploaded file: %s'), esc_html( basename( $file_upload->filename ) ) );
     281                require_once( ABSPATH . 'wp-admin/admin-header.php' );
     282
     283                $title = sprintf( __( 'Installing Theme from uploaded file: %s' ), esc_html( basename( $file_upload->filename ) ) );
    261284                $nonce = 'theme-upload';
    262                 $url = add_query_arg(array('package' => $file_upload->id), 'update.php?action=upload-theme');
    263                 $type = 'upload'; //Install plugin type, From Web or an Upload.
    264 
    265                 $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
    266                 $result = $upgrader->install( $file_upload->package );
    267 
    268                 if ( $result || is_wp_error($result) )
     285                $url   = add_query_arg( array( 'package' => $file_upload->id ), 'update.php?action=upload-theme' );
     286                $type  = 'upload'; //Install plugin type, From Web or an Upload.
     287
     288                $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact( 'type', 'title', 'nonce', 'url' ) ) );
     289                $result   = $upgrader->install( $file_upload->package );
     290
     291                if ( $result || is_wp_error( $result ) ) {
    269292                        $file_upload->cleanup();
    270 
    271                 include(ABSPATH . 'wp-admin/admin-footer.php');
     293                }
     294
     295                include( ABSPATH . 'wp-admin/admin-footer.php' );
    272296
    273297        } else {
Note: See TracChangeset for help on using the changeset viewer.