Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 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/includes/plugin.php

    r42242 r42343  
    2323 *     Version: Must be set in the plugin for WordPress 2.3+
    2424 *     Text Domain: Optional. Unique identifier, should be same as the one used in
    25  *          load_plugin_textdomain()
     25 *          load_plugin_textdomain()
    2626 *     Domain Path: Optional. Only useful if the translations are located in a
    27  *          folder above the plugin's base path. For example, if .mo files are
    28  *          located in the locale folder then Domain Path will be "/locale/" and
    29  *          must have the first slash. Defaults to the base folder the plugin is
    30  *          located in.
     27 *          folder above the plugin's base path. For example, if .mo files are
     28 *          located in the locale folder then Domain Path will be "/locale/" and
     29 *          must have the first slash. Defaults to the base folder the plugin is
     30 *          located in.
    3131 *     Network: Optional. Specify "Network: true" to require that a plugin is activated
    32  *          across all sites in an installation. This will prevent a plugin from being
    33  *          activated on a single site when Multisite is enabled.
     32 *          across all sites in an installation. This will prevent a plugin from being
     33 *          activated on a single site when Multisite is enabled.
    3434 *      * / # Remove the space to close comment
    3535 *
     
    6969
    7070    $default_headers = array(
    71         'Name' => 'Plugin Name',
    72         'PluginURI' => 'Plugin URI',
    73         'Version' => 'Version',
     71        'Name'        => 'Plugin Name',
     72        'PluginURI'   => 'Plugin URI',
     73        'Version'     => 'Version',
    7474        'Description' => 'Description',
    75         'Author' => 'Author',
    76         'AuthorURI' => 'Author URI',
    77         'TextDomain' => 'Text Domain',
    78         'DomainPath' => 'Domain Path',
    79         'Network' => 'Network',
     75        'Author'      => 'Author',
     76        'AuthorURI'   => 'Author URI',
     77        'TextDomain'  => 'Text Domain',
     78        'DomainPath'  => 'Domain Path',
     79        'Network'     => 'Network',
    8080        // Site Wide Only is deprecated in favor of Network.
    81         '_sitewide' => 'Site Wide Only',
     81        '_sitewide'   => 'Site Wide Only',
    8282    );
    8383
     
    137137        }
    138138        if ( $textdomain ) {
    139             foreach ( array( 'Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version' ) as $field )
     139            foreach ( array( 'Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version' ) as $field ) {
    140140                $plugin_data[ $field ] = translate( $plugin_data[ $field ], $textdomain );
     141            }
    141142        }
    142143    }
    143144
    144145    // Sanitize fields
    145     $allowed_tags = $allowed_tags_in_links = array(
     146    $allowed_tags      = $allowed_tags_in_links = array(
    146147        'abbr'    => array( 'title' => true ),
    147148        'acronym' => array( 'title' => true ),
     
    150151        'strong'  => true,
    151152    );
    152     $allowed_tags['a'] = array( 'href' => true, 'title' => true );
     153    $allowed_tags['a'] = array(
     154        'href'  => true,
     155        'title' => true,
     156    );
    153157
    154158    // Name is marked up inside <a> tags. Don't allow these.
    155159    // Author is too, but some plugins have used <a> here (omitting Author URI).
    156     $plugin_data['Name']        = wp_kses( $plugin_data['Name'],        $allowed_tags_in_links );
    157     $plugin_data['Author']      = wp_kses( $plugin_data['Author'],      $allowed_tags );
     160    $plugin_data['Name']   = wp_kses( $plugin_data['Name'], $allowed_tags_in_links );
     161    $plugin_data['Author'] = wp_kses( $plugin_data['Author'], $allowed_tags );
    158162
    159163    $plugin_data['Description'] = wp_kses( $plugin_data['Description'], $allowed_tags );
    160     $plugin_data['Version']     = wp_kses( $plugin_data['Version'],     $allowed_tags );
    161 
    162     $plugin_data['PluginURI']   = esc_url( $plugin_data['PluginURI'] );
    163     $plugin_data['AuthorURI']   = esc_url( $plugin_data['AuthorURI'] );
     164    $plugin_data['Version']     = wp_kses( $plugin_data['Version'], $allowed_tags );
     165
     166    $plugin_data['PluginURI'] = esc_url( $plugin_data['PluginURI'] );
     167    $plugin_data['AuthorURI'] = esc_url( $plugin_data['AuthorURI'] );
    164168
    165169    $plugin_data['Title']      = $plugin_data['Name'];
     
    168172    // Apply markup
    169173    if ( $markup ) {
    170         if ( $plugin_data['PluginURI'] && $plugin_data['Name'] )
     174        if ( $plugin_data['PluginURI'] && $plugin_data['Name'] ) {
    171175            $plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '">' . $plugin_data['Name'] . '</a>';
    172 
    173         if ( $plugin_data['AuthorURI'] && $plugin_data['Author'] )
     176        }
     177
     178        if ( $plugin_data['AuthorURI'] && $plugin_data['Author'] ) {
    174179            $plugin_data['Author'] = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>';
     180        }
    175181
    176182        $plugin_data['Description'] = wptexturize( $plugin_data['Description'] );
    177183
    178         if ( $plugin_data['Author'] )
    179             $plugin_data['Description'] .= ' <cite>' . sprintf( __('By %s.'), $plugin_data['Author'] ) . '</cite>';
     184        if ( $plugin_data['Author'] ) {
     185            $plugin_data['Description'] .= ' <cite>' . sprintf( __( 'By %s.' ), $plugin_data['Author'] ) . '</cite>';
     186        }
    180187    }
    181188
     
    193200function get_plugin_files( $plugin ) {
    194201    $plugin_file = WP_PLUGIN_DIR . '/' . $plugin;
    195     $dir = dirname( $plugin_file );
     202    $dir         = dirname( $plugin_file );
    196203
    197204    $plugin_files = array( plugin_basename( $plugin_file ) );
     
    238245 * @return array Key is the plugin file path and the value is an array of the plugin data.
    239246 */
    240 function get_plugins($plugin_folder = '') {
    241 
    242     if ( ! $cache_plugins = wp_cache_get('plugins', 'plugins') )
     247function get_plugins( $plugin_folder = '' ) {
     248
     249    if ( ! $cache_plugins = wp_cache_get( 'plugins', 'plugins' ) ) {
    243250        $cache_plugins = array();
    244 
    245     if ( isset($cache_plugins[ $plugin_folder ]) )
     251    }
     252
     253    if ( isset( $cache_plugins[ $plugin_folder ] ) ) {
    246254        return $cache_plugins[ $plugin_folder ];
    247 
    248     $wp_plugins = array ();
     255    }
     256
     257    $wp_plugins  = array();
    249258    $plugin_root = WP_PLUGIN_DIR;
    250     if ( !empty($plugin_folder) )
     259    if ( ! empty( $plugin_folder ) ) {
    251260        $plugin_root .= $plugin_folder;
     261    }
    252262
    253263    // Files in wp-content/plugins directory
    254     $plugins_dir = @ opendir( $plugin_root);
     264    $plugins_dir  = @ opendir( $plugin_root );
    255265    $plugin_files = array();
    256266    if ( $plugins_dir ) {
    257         while (($file = readdir( $plugins_dir ) ) !== false ) {
    258             if ( substr($file, 0, 1) == '.' )
     267        while ( ( $file = readdir( $plugins_dir ) ) !== false ) {
     268            if ( substr( $file, 0, 1 ) == '.' ) {
    259269                continue;
    260             if ( is_dir( $plugin_root.'/'.$file ) ) {
    261                 $plugins_subdir = @ opendir( $plugin_root.'/'.$file );
     270            }
     271            if ( is_dir( $plugin_root . '/' . $file ) ) {
     272                $plugins_subdir = @ opendir( $plugin_root . '/' . $file );
    262273                if ( $plugins_subdir ) {
    263                     while (($subfile = readdir( $plugins_subdir ) ) !== false ) {
    264                         if ( substr($subfile, 0, 1) == '.' )
     274                    while ( ( $subfile = readdir( $plugins_subdir ) ) !== false ) {
     275                        if ( substr( $subfile, 0, 1 ) == '.' ) {
    265276                            continue;
    266                         if ( substr($subfile, -4) == '.php' )
     277                        }
     278                        if ( substr( $subfile, -4 ) == '.php' ) {
    267279                            $plugin_files[] = "$file/$subfile";
     280                        }
    268281                    }
    269282                    closedir( $plugins_subdir );
    270283                }
    271284            } else {
    272                 if ( substr($file, -4) == '.php' )
     285                if ( substr( $file, -4 ) == '.php' ) {
    273286                    $plugin_files[] = $file;
     287                }
    274288            }
    275289        }
     
    277291    }
    278292
    279     if ( empty($plugin_files) )
     293    if ( empty( $plugin_files ) ) {
    280294        return $wp_plugins;
     295    }
    281296
    282297    foreach ( $plugin_files as $plugin_file ) {
    283         if ( !is_readable( "$plugin_root/$plugin_file" ) )
     298        if ( ! is_readable( "$plugin_root/$plugin_file" ) ) {
    284299            continue;
     300        }
    285301
    286302        $plugin_data = get_plugin_data( "$plugin_root/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached.
    287303
    288         if ( empty ( $plugin_data['Name'] ) )
     304        if ( empty( $plugin_data['Name'] ) ) {
    289305            continue;
    290 
    291         $wp_plugins[plugin_basename( $plugin_file )] = $plugin_data;
     306        }
     307
     308        $wp_plugins[ plugin_basename( $plugin_file ) ] = $plugin_data;
    292309    }
    293310
     
    295312
    296313    $cache_plugins[ $plugin_folder ] = $wp_plugins;
    297     wp_cache_set('plugins', $cache_plugins, 'plugins');
     314    wp_cache_set( 'plugins', $cache_plugins, 'plugins' );
    298315
    299316    return $wp_plugins;
     
    313330    $plugin_files = array();
    314331
    315     if ( ! is_dir( WPMU_PLUGIN_DIR ) )
     332    if ( ! is_dir( WPMU_PLUGIN_DIR ) ) {
    316333        return $wp_plugins;
     334    }
    317335    if ( $plugins_dir = @ opendir( WPMU_PLUGIN_DIR ) ) {
    318336        while ( ( $file = readdir( $plugins_dir ) ) !== false ) {
    319             if ( substr( $file, -4 ) == '.php' )
     337            if ( substr( $file, -4 ) == '.php' ) {
    320338                $plugin_files[] = $file;
     339            }
    321340        }
    322341    } else {
     
    326345    @closedir( $plugins_dir );
    327346
    328     if ( empty($plugin_files) )
     347    if ( empty( $plugin_files ) ) {
    329348        return $wp_plugins;
     349    }
    330350
    331351    foreach ( $plugin_files as $plugin_file ) {
    332         if ( !is_readable( WPMU_PLUGIN_DIR . "/$plugin_file" ) )
     352        if ( ! is_readable( WPMU_PLUGIN_DIR . "/$plugin_file" ) ) {
    333353            continue;
     354        }
    334355
    335356        $plugin_data = get_plugin_data( WPMU_PLUGIN_DIR . "/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached.
    336357
    337         if ( empty ( $plugin_data['Name'] ) )
     358        if ( empty( $plugin_data['Name'] ) ) {
    338359            $plugin_data['Name'] = $plugin_file;
     360        }
    339361
    340362        $wp_plugins[ $plugin_file ] = $plugin_data;
    341363    }
    342364
    343     if ( isset( $wp_plugins['index.php'] ) && filesize( WPMU_PLUGIN_DIR . '/index.php') <= 30 ) // silence is golden
     365    if ( isset( $wp_plugins['index.php'] ) && filesize( WPMU_PLUGIN_DIR . '/index.php' ) <= 30 ) { // silence is golden
    344366        unset( $wp_plugins['index.php'] );
     367    }
    345368
    346369    uasort( $wp_plugins, '_sort_uname_callback' );
     
    366389 */
    367390function get_dropins() {
    368     $dropins = array();
     391    $dropins      = array();
    369392    $plugin_files = array();
    370393
     
    374397    if ( $plugins_dir = @ opendir( WP_CONTENT_DIR ) ) {
    375398        while ( ( $file = readdir( $plugins_dir ) ) !== false ) {
    376             if ( isset( $_dropins[ $file ] ) )
     399            if ( isset( $_dropins[ $file ] ) ) {
    377400                $plugin_files[] = $file;
     401            }
    378402        }
    379403    } else {
     
    383407    @closedir( $plugins_dir );
    384408
    385     if ( empty($plugin_files) )
     409    if ( empty( $plugin_files ) ) {
    386410        return $dropins;
     411    }
    387412
    388413    foreach ( $plugin_files as $plugin_file ) {
    389         if ( !is_readable( WP_CONTENT_DIR . "/$plugin_file" ) )
     414        if ( ! is_readable( WP_CONTENT_DIR . "/$plugin_file" ) ) {
    390415            continue;
     416        }
    391417        $plugin_data = get_plugin_data( WP_CONTENT_DIR . "/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached.
    392         if ( empty( $plugin_data['Name'] ) )
     418        if ( empty( $plugin_data['Name'] ) ) {
    393419            $plugin_data['Name'] = $plugin_file;
     420        }
    394421        $dropins[ $plugin_file ] = $plugin_data;
    395422    }
     
    407434 * @since 3.0.0
    408435 * @return array Key is file name. The value is an array, with the first value the
    409  *  purpose of the drop-in and the second value the name of the constant that must be
    410  *  true for the drop-in to be used, or true if no constant is required.
     436 *  purpose of the drop-in and the second value the name of the constant that must be
     437 *  true for the drop-in to be used, or true if no constant is required.
    411438 */
    412439function _get_dropins() {
    413440    $dropins = array(
    414         'advanced-cache.php' => array( __( 'Advanced caching plugin.'       ), 'WP_CACHE' ), // WP_CACHE
    415         'db.php'             => array( __( 'Custom database class.'         ), true ), // auto on load
     441        'advanced-cache.php' => array( __( 'Advanced caching plugin.' ), 'WP_CACHE' ), // WP_CACHE
     442        'db.php'             => array( __( 'Custom database class.' ), true ), // auto on load
    416443        'db-error.php'       => array( __( 'Custom database error message.' ), true ), // auto on error
    417         'install.php'        => array( __( 'Custom installation script.'    ), true ), // auto on installation
    418         'maintenance.php'    => array( __( 'Custom maintenance message.'    ), true ), // auto on maintenance
    419         'object-cache.php'   => array( __( 'External object cache.'         ), true ), // auto on load
     444        'install.php'        => array( __( 'Custom installation script.' ), true ), // auto on installation
     445        'maintenance.php'    => array( __( 'Custom maintenance message.' ), true ), // auto on maintenance
     446        'object-cache.php'   => array( __( 'External object cache.' ), true ), // auto on load
    420447    );
    421448
    422449    if ( is_multisite() ) {
    423         $dropins['sunrise.php'       ] = array( __( 'Executed before Multisite is loaded.' ), 'SUNRISE' ); // SUNRISE
    424         $dropins['blog-deleted.php'  ] = array( __( 'Custom site deleted message.'  ), true ); // auto on deleted blog
    425         $dropins['blog-inactive.php' ] = array( __( 'Custom site inactive message.' ), true ); // auto on inactive blog
     450        $dropins['sunrise.php']        = array( __( 'Executed before Multisite is loaded.' ), 'SUNRISE' ); // SUNRISE
     451        $dropins['blog-deleted.php']   = array( __( 'Custom site deleted message.' ), true ); // auto on deleted blog
     452        $dropins['blog-inactive.php']  = array( __( 'Custom site inactive message.' ), true ); // auto on inactive blog
    426453        $dropins['blog-suspended.php'] = array( __( 'Custom site suspended message.' ), true ); // auto on archived or spammed blog
    427454    }
     
    476503 */
    477504function is_plugin_active_for_network( $plugin ) {
    478     if ( !is_multisite() )
     505    if ( ! is_multisite() ) {
    479506        return false;
    480 
    481     $plugins = get_site_option( 'active_sitewide_plugins');
    482     if ( isset($plugins[$plugin]) )
     507    }
     508
     509    $plugins = get_site_option( 'active_sitewide_plugins' );
     510    if ( isset( $plugins[ $plugin ] ) ) {
    483511        return true;
     512    }
    484513
    485514    return false;
     
    500529function is_network_only_plugin( $plugin ) {
    501530    $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
    502     if ( $plugin_data )
     531    if ( $plugin_data ) {
    503532        return $plugin_data['Network'];
     533    }
    504534    return false;
    505535}
     
    535565    $plugin = plugin_basename( trim( $plugin ) );
    536566
    537     if ( is_multisite() && ( $network_wide || is_network_only_plugin($plugin) ) ) {
    538         $network_wide = true;
    539         $current = get_site_option( 'active_sitewide_plugins', array() );
     567    if ( is_multisite() && ( $network_wide || is_network_only_plugin( $plugin ) ) ) {
     568        $network_wide        = true;
     569        $current             = get_site_option( 'active_sitewide_plugins', array() );
    540570        $_GET['networkwide'] = 1; // Back compat for plugins looking for this value.
    541571    } else {
     
    543573    }
    544574
    545     $valid = validate_plugin($plugin);
    546     if ( is_wp_error($valid) )
     575    $valid = validate_plugin( $plugin );
     576    if ( is_wp_error( $valid ) ) {
    547577        return $valid;
     578    }
    548579
    549580    if ( ( $network_wide && ! isset( $current[ $plugin ] ) ) || ( ! $network_wide && ! in_array( $plugin, $current ) ) ) {
    550         if ( !empty($redirect) )
    551             wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect)); // we'll override this later if the plugin can be included without fatal error
     581        if ( ! empty( $redirect ) ) {
     582            wp_redirect( add_query_arg( '_error_nonce', wp_create_nonce( 'plugin-activation-error_' . $plugin ), $redirect ) ); // we'll override this later if the plugin can be included without fatal error
     583        }
    552584        ob_start();
    553585        wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin );
     
    588620
    589621        if ( $network_wide ) {
    590             $current = get_site_option( 'active_sitewide_plugins', array() );
    591             $current[$plugin] = time();
     622            $current            = get_site_option( 'active_sitewide_plugins', array() );
     623            $current[ $plugin ] = time();
    592624            update_site_option( 'active_sitewide_plugins', $current );
    593625        } else {
    594             $current = get_option( 'active_plugins', array() );
     626            $current   = get_option( 'active_plugins', array() );
    595627            $current[] = $plugin;
    596             sort($current);
    597             update_option('active_plugins', $current);
     628            sort( $current );
     629            update_option( 'active_plugins', $current );
    598630        }
    599631
     
    616648        if ( ob_get_length() > 0 ) {
    617649            $output = ob_get_clean();
    618             return new WP_Error('unexpected_output', __('The plugin generated unexpected output.'), $output);
     650            return new WP_Error( 'unexpected_output', __( 'The plugin generated unexpected output.' ), $output );
    619651        }
    620652        ob_end_clean();
     
    635667 * @param bool $silent Prevent calling deactivation hooks. Default is false.
    636668 * @param mixed $network_wide Whether to deactivate the plugin for all sites in the network.
    637  *  A value of null (the default) will deactivate plugins for both the site and the network.
     669 *  A value of null (the default) will deactivate plugins for both the site and the network.
    638670 */
    639671function deactivate_plugins( $plugins, $silent = false, $network_wide = null ) {
    640     if ( is_multisite() )
     672    if ( is_multisite() ) {
    641673        $network_current = get_site_option( 'active_sitewide_plugins', array() );
     674    }
    642675    $current = get_option( 'active_plugins', array() );
    643676    $do_blog = $do_network = false;
     
    645678    foreach ( (array) $plugins as $plugin ) {
    646679        $plugin = plugin_basename( trim( $plugin ) );
    647         if ( ! is_plugin_active($plugin) )
     680        if ( ! is_plugin_active( $plugin ) ) {
    648681            continue;
     682        }
    649683
    650684        $network_deactivating = false !== $network_wide && is_plugin_active_for_network( $plugin );
     
    715749    }
    716750
    717     if ( $do_blog )
    718         update_option('active_plugins', $current);
    719     if ( $do_network )
     751    if ( $do_blog ) {
     752        update_option( 'active_plugins', $current );
     753    }
     754    if ( $do_network ) {
    720755        update_site_option( 'active_sitewide_plugins', $network_current );
     756    }
    721757}
    722758
     
    738774 */
    739775function activate_plugins( $plugins, $redirect = '', $network_wide = false, $silent = false ) {
    740     if ( !is_array($plugins) )
    741         $plugins = array($plugins);
     776    if ( ! is_array( $plugins ) ) {
     777        $plugins = array( $plugins );
     778    }
    742779
    743780    $errors = array();
    744781    foreach ( $plugins as $plugin ) {
    745         if ( !empty($redirect) )
    746             $redirect = add_query_arg('plugin', $plugin, $redirect);
    747         $result = activate_plugin($plugin, $redirect, $network_wide, $silent);
    748         if ( is_wp_error($result) )
    749             $errors[$plugin] = $result;
    750     }
    751 
    752     if ( !empty($errors) )
    753         return new WP_Error('plugins_invalid', __('One of the plugins is invalid.'), $errors);
     782        if ( ! empty( $redirect ) ) {
     783            $redirect = add_query_arg( 'plugin', $plugin, $redirect );
     784        }
     785        $result = activate_plugin( $plugin, $redirect, $network_wide, $silent );
     786        if ( is_wp_error( $result ) ) {
     787            $errors[ $plugin ] = $result;
     788        }
     789    }
     790
     791    if ( ! empty( $errors ) ) {
     792        return new WP_Error( 'plugins_invalid', __( 'One of the plugins is invalid.' ), $errors );
     793    }
    754794
    755795    return true;
     
    771811    global $wp_filesystem;
    772812
    773     if ( empty($plugins) )
     813    if ( empty( $plugins ) ) {
    774814        return false;
     815    }
    775816
    776817    $checked = array();
    777     foreach ( $plugins as $plugin )
     818    foreach ( $plugins as $plugin ) {
    778819        $checked[] = 'checked[]=' . $plugin;
    779 
    780     $url = wp_nonce_url('plugins.php?action=delete-selected&verify-delete=1&' . implode('&', $checked), 'bulk-plugins');
     820    }
     821
     822    $url = wp_nonce_url( 'plugins.php?action=delete-selected&verify-delete=1&' . implode( '&', $checked ), 'bulk-plugins' );
    781823
    782824    ob_start();
    783825    $credentials = request_filesystem_credentials( $url );
    784     $data = ob_get_clean();
     826    $data        = ob_get_clean();
    785827
    786828    if ( false === $credentials ) {
    787         if ( ! empty($data) ){
    788             include_once( ABSPATH . 'wp-admin/admin-header.php');
     829        if ( ! empty( $data ) ) {
     830            include_once( ABSPATH . 'wp-admin/admin-header.php' );
    789831            echo $data;
    790             include( ABSPATH . 'wp-admin/admin-footer.php');
     832            include( ABSPATH . 'wp-admin/admin-footer.php' );
    791833            exit;
    792834        }
     
    799841        $data = ob_get_clean();
    800842
    801         if ( ! empty($data) ){
    802             include_once( ABSPATH . 'wp-admin/admin-header.php');
     843        if ( ! empty( $data ) ) {
     844            include_once( ABSPATH . 'wp-admin/admin-header.php' );
    803845            echo $data;
    804             include( ABSPATH . 'wp-admin/admin-footer.php');
     846            include( ABSPATH . 'wp-admin/admin-footer.php' );
    805847            exit;
    806848        }
     
    808850    }
    809851
    810     if ( ! is_object($wp_filesystem) )
    811         return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
    812 
    813     if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )
    814         return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
     852    if ( ! is_object( $wp_filesystem ) ) {
     853        return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) );
     854    }
     855
     856    if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
     857        return new WP_Error( 'fs_error', __( 'Filesystem error.' ), $wp_filesystem->errors );
     858    }
    815859
    816860    // Get the base plugin folder.
     
    829873        // Run Uninstall hook.
    830874        if ( is_uninstallable_plugin( $plugin_file ) ) {
    831             uninstall_plugin($plugin_file);
     875            uninstall_plugin( $plugin_file );
    832876        }
    833877
     
    878922
    879923    // Remove deleted plugins from the plugin updates list.
    880     if ( $current = get_site_transient('update_plugins') ) {
     924    if ( $current = get_site_transient( 'update_plugins' ) ) {
    881925        // Don't remove the plugins that weren't deleted.
    882926        $deleted = array_diff( $plugins, $errors );
     
    923967    if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
    924968        $network_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
    925         $plugins = array_merge( $plugins, array_keys( $network_plugins ) );
    926     }
    927 
    928     if ( empty( $plugins ) )
     969        $plugins         = array_merge( $plugins, array_keys( $network_plugins ) );
     970    }
     971
     972    if ( empty( $plugins ) ) {
    929973        return array();
     974    }
    930975
    931976    $invalid = array();
     
    935980        $result = validate_plugin( $plugin );
    936981        if ( is_wp_error( $result ) ) {
    937             $invalid[$plugin] = $result;
     982            $invalid[ $plugin ] = $result;
    938983            deactivate_plugins( $plugin, true );
    939984        }
     
    952997 * @return WP_Error|int 0 on success, WP_Error on failure.
    953998 */
    954 function validate_plugin($plugin) {
    955     if ( validate_file($plugin) )
    956         return new WP_Error('plugin_invalid', __('Invalid plugin path.'));
    957     if ( ! file_exists(WP_PLUGIN_DIR . '/' . $plugin) )
    958         return new WP_Error('plugin_not_found', __('Plugin file does not exist.'));
     999function validate_plugin( $plugin ) {
     1000    if ( validate_file( $plugin ) ) {
     1001        return new WP_Error( 'plugin_invalid', __( 'Invalid plugin path.' ) );
     1002    }
     1003    if ( ! file_exists( WP_PLUGIN_DIR . '/' . $plugin ) ) {
     1004        return new WP_Error( 'plugin_not_found', __( 'Plugin file does not exist.' ) );
     1005    }
    9591006
    9601007    $installed_plugins = get_plugins();
    961     if ( ! isset($installed_plugins[$plugin]) )
    962         return new WP_Error('no_plugin_header', __('The plugin does not have a valid header.'));
     1008    if ( ! isset( $installed_plugins[ $plugin ] ) ) {
     1009        return new WP_Error( 'no_plugin_header', __( 'The plugin does not have a valid header.' ) );
     1010    }
    9631011    return 0;
    9641012}
     
    9721020 * @return bool Whether plugin can be uninstalled.
    9731021 */
    974 function is_uninstallable_plugin($plugin) {
    975     $file = plugin_basename($plugin);
    976 
    977     $uninstallable_plugins = (array) get_option('uninstall_plugins');
    978     if ( isset( $uninstallable_plugins[$file] ) || file_exists( WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php' ) )
     1022function is_uninstallable_plugin( $plugin ) {
     1023    $file = plugin_basename( $plugin );
     1024
     1025    $uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
     1026    if ( isset( $uninstallable_plugins[ $file ] ) || file_exists( WP_PLUGIN_DIR . '/' . dirname( $file ) . '/uninstall.php' ) ) {
    9791027        return true;
     1028    }
    9801029
    9811030    return false;
     
    9921041 * @return true True if a plugin's uninstall.php file has been found and included.
    9931042 */
    994 function uninstall_plugin($plugin) {
    995     $file = plugin_basename($plugin);
    996 
    997     $uninstallable_plugins = (array) get_option('uninstall_plugins');
     1043function uninstall_plugin( $plugin ) {
     1044    $file = plugin_basename( $plugin );
     1045
     1046    $uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
    9981047
    9991048    /**
     
    10071056    do_action( 'pre_uninstall_plugin', $plugin, $uninstallable_plugins );
    10081057
    1009     if ( file_exists( WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php' ) ) {
    1010         if ( isset( $uninstallable_plugins[$file] ) ) {
    1011             unset($uninstallable_plugins[$file]);
    1012             update_option('uninstall_plugins', $uninstallable_plugins);
    1013         }
    1014         unset($uninstallable_plugins);
    1015 
    1016         define('WP_UNINSTALL_PLUGIN', $file);
     1058    if ( file_exists( WP_PLUGIN_DIR . '/' . dirname( $file ) . '/uninstall.php' ) ) {
     1059        if ( isset( $uninstallable_plugins[ $file ] ) ) {
     1060            unset( $uninstallable_plugins[ $file ] );
     1061            update_option( 'uninstall_plugins', $uninstallable_plugins );
     1062        }
     1063        unset( $uninstallable_plugins );
     1064
     1065        define( 'WP_UNINSTALL_PLUGIN', $file );
    10171066        wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $file );
    1018         include( WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php' );
     1067        include( WP_PLUGIN_DIR . '/' . dirname( $file ) . '/uninstall.php' );
    10191068
    10201069        return true;
    10211070    }
    10221071
    1023     if ( isset( $uninstallable_plugins[$file] ) ) {
    1024         $callable = $uninstallable_plugins[$file];
    1025         unset($uninstallable_plugins[$file]);
    1026         update_option('uninstall_plugins', $uninstallable_plugins);
    1027         unset($uninstallable_plugins);
     1072    if ( isset( $uninstallable_plugins[ $file ] ) ) {
     1073        $callable = $uninstallable_plugins[ $file ];
     1074        unset( $uninstallable_plugins[ $file ] );
     1075        update_option( 'uninstall_plugins', $uninstallable_plugins );
     1076        unset( $uninstallable_plugins );
    10281077
    10291078        wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $file );
     
    10831132    $menu_slug = plugin_basename( $menu_slug );
    10841133
    1085     $admin_page_hooks[$menu_slug] = sanitize_title( $menu_title );
     1134    $admin_page_hooks[ $menu_slug ] = sanitize_title( $menu_title );
    10861135
    10871136    $hookname = get_plugin_page_hookname( $menu_slug, '' );
    10881137
    1089     if ( !empty( $function ) && !empty( $hookname ) && current_user_can( $capability ) )
     1138    if ( ! empty( $function ) && ! empty( $hookname ) && current_user_can( $capability ) ) {
    10901139        add_action( $hookname, $function );
    1091 
    1092     if ( empty($icon_url) ) {
    1093         $icon_url = 'dashicons-admin-generic';
     1140    }
     1141
     1142    if ( empty( $icon_url ) ) {
     1143        $icon_url   = 'dashicons-admin-generic';
    10941144        $icon_class = 'menu-icon-generic ';
    10951145    } else {
    1096         $icon_url = set_url_scheme( $icon_url );
     1146        $icon_url   = set_url_scheme( $icon_url );
    10971147        $icon_class = '';
    10981148    }
     
    11031153        $menu[] = $new_menu;
    11041154    } elseif ( isset( $menu[ "$position" ] ) ) {
    1105         $position = $position + substr( base_convert( md5( $menu_slug . $menu_title ), 16, 10 ) , -5 ) * 0.00001;
     1155        $position            = $position + substr( base_convert( md5( $menu_slug . $menu_title ), 16, 10 ), -5 ) * 0.00001;
    11061156        $menu[ "$position" ] = $new_menu;
    11071157    } else {
     
    11091159    }
    11101160
    1111     $_registered_pages[$hookname] = true;
     1161    $_registered_pages[ $hookname ] = true;
    11121162
    11131163    // No parent as top level
    1114     $_parent_pages[$menu_slug] = false;
     1164    $_parent_pages[ $menu_slug ] = false;
    11151165
    11161166    return $hookname;
     
    11491199        $_registered_pages, $_parent_pages;
    11501200
    1151     $menu_slug = plugin_basename( $menu_slug );
    1152     $parent_slug = plugin_basename( $parent_slug);
    1153 
    1154     if ( isset( $_wp_real_parent_file[$parent_slug] ) )
    1155         $parent_slug = $_wp_real_parent_file[$parent_slug];
    1156 
    1157     if ( !current_user_can( $capability ) ) {
    1158         $_wp_submenu_nopriv[$parent_slug][$menu_slug] = true;
     1201    $menu_slug   = plugin_basename( $menu_slug );
     1202    $parent_slug = plugin_basename( $parent_slug );
     1203
     1204    if ( isset( $_wp_real_parent_file[ $parent_slug ] ) ) {
     1205        $parent_slug = $_wp_real_parent_file[ $parent_slug ];
     1206    }
     1207
     1208    if ( ! current_user_can( $capability ) ) {
     1209        $_wp_submenu_nopriv[ $parent_slug ][ $menu_slug ] = true;
    11591210        return false;
    11601211    }
     
    11661217     * this case, don't automatically add a link back to avoid duplication.
    11671218     */
    1168     if (!isset( $submenu[$parent_slug] ) && $menu_slug != $parent_slug ) {
    1169         foreach ( (array)$menu as $parent_menu ) {
    1170             if ( $parent_menu[2] == $parent_slug && current_user_can( $parent_menu[1] ) )
    1171                 $submenu[$parent_slug][] = array_slice( $parent_menu, 0, 4 );
    1172         }
    1173     }
    1174 
    1175     $submenu[$parent_slug][] = array ( $menu_title, $capability, $menu_slug, $page_title );
    1176 
    1177     $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug);
    1178     if (!empty ( $function ) && !empty ( $hookname ))
     1219    if ( ! isset( $submenu[ $parent_slug ] ) && $menu_slug != $parent_slug ) {
     1220        foreach ( (array) $menu as $parent_menu ) {
     1221            if ( $parent_menu[2] == $parent_slug && current_user_can( $parent_menu[1] ) ) {
     1222                $submenu[ $parent_slug ][] = array_slice( $parent_menu, 0, 4 );
     1223            }
     1224        }
     1225    }
     1226
     1227    $submenu[ $parent_slug ][] = array( $menu_title, $capability, $menu_slug, $page_title );
     1228
     1229    $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug );
     1230    if ( ! empty( $function ) && ! empty( $hookname ) ) {
    11791231        add_action( $hookname, $function );
    1180 
    1181     $_registered_pages[$hookname] = true;
     1232    }
     1233
     1234    $_registered_pages[ $hookname ] = true;
    11821235
    11831236    /*
     
    11851238     * See wp-admin/admin.php for redirect from edit.php to tools.php
    11861239     */
    1187     if ( 'tools.php' == $parent_slug )
    1188         $_registered_pages[get_plugin_page_hookname( $menu_slug, 'edit.php')] = true;
     1240    if ( 'tools.php' == $parent_slug ) {
     1241        $_registered_pages[ get_plugin_page_hookname( $menu_slug, 'edit.php' ) ] = true;
     1242    }
    11891243
    11901244    // No parent as top level.
    1191     $_parent_pages[$menu_slug] = $parent_slug;
     1245    $_parent_pages[ $menu_slug ] = $parent_slug;
    11921246
    11931247    return $hookname;
     
    12911345 */
    12921346function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    1293     if ( current_user_can('edit_users') )
     1347    if ( current_user_can( 'edit_users' ) ) {
    12941348        $parent = 'users.php';
    1295     else
     1349    } else {
    12961350        $parent = 'profile.php';
     1351    }
    12971352    return add_submenu_page( $parent, $page_title, $menu_title, $capability, $menu_slug, $function );
    12981353}
     
    14321487    foreach ( $menu as $i => $item ) {
    14331488        if ( $menu_slug == $item[2] ) {
    1434             unset( $menu[$i] );
     1489            unset( $menu[ $i ] );
    14351490            return $item;
    14361491        }
     
    14541509    global $submenu;
    14551510
    1456     if ( !isset( $submenu[$menu_slug] ) )
     1511    if ( ! isset( $submenu[ $menu_slug ] ) ) {
    14571512        return false;
    1458 
    1459     foreach ( $submenu[$menu_slug] as $i => $item ) {
     1513    }
     1514
     1515    foreach ( $submenu[ $menu_slug ] as $i => $item ) {
    14601516        if ( $submenu_slug == $item[2] ) {
    1461             unset( $submenu[$menu_slug][$i] );
     1517            unset( $submenu[ $menu_slug ][ $i ] );
    14621518            return $item;
    14631519        }
     
    14801536 * @return string the url
    14811537 */
    1482 function menu_page_url($menu_slug, $echo = true) {
     1538function menu_page_url( $menu_slug, $echo = true ) {
    14831539    global $_parent_pages;
    14841540
    1485     if ( isset( $_parent_pages[$menu_slug] ) ) {
    1486         $parent_slug = $_parent_pages[$menu_slug];
    1487         if ( $parent_slug && ! isset( $_parent_pages[$parent_slug] ) ) {
     1541    if ( isset( $_parent_pages[ $menu_slug ] ) ) {
     1542        $parent_slug = $_parent_pages[ $menu_slug ];
     1543        if ( $parent_slug && ! isset( $_parent_pages[ $parent_slug ] ) ) {
    14881544            $url = admin_url( add_query_arg( 'page', $menu_slug, $parent_slug ) );
    14891545        } else {
     
    14941550    }
    14951551
    1496     $url = esc_url($url);
    1497 
    1498     if ( $echo )
     1552    $url = esc_url( $url );
     1553
     1554    if ( $echo ) {
    14991555        echo $url;
     1556    }
    15001557
    15011558    return $url;
     
    15061563//
    15071564/**
    1508  *
    15091565 * @global string $parent_file
    15101566 * @global array $menu
     
    15211577        $plugin_page, $_wp_real_parent_file, $_wp_menu_nopriv, $_wp_submenu_nopriv;
    15221578
    1523     if ( !empty ( $parent ) && 'admin.php' != $parent ) {
    1524         if ( isset( $_wp_real_parent_file[$parent] ) )
    1525             $parent = $_wp_real_parent_file[$parent];
     1579    if ( ! empty( $parent ) && 'admin.php' != $parent ) {
     1580        if ( isset( $_wp_real_parent_file[ $parent ] ) ) {
     1581            $parent = $_wp_real_parent_file[ $parent ];
     1582        }
    15261583        return $parent;
    15271584    }
    15281585
    15291586    if ( $pagenow == 'admin.php' && isset( $plugin_page ) ) {
    1530         foreach ( (array)$menu as $parent_menu ) {
     1587        foreach ( (array) $menu as $parent_menu ) {
    15311588            if ( $parent_menu[2] == $plugin_page ) {
    15321589                $parent_file = $plugin_page;
    1533                 if ( isset( $_wp_real_parent_file[$parent_file] ) )
    1534                     $parent_file = $_wp_real_parent_file[$parent_file];
     1590                if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) {
     1591                    $parent_file = $_wp_real_parent_file[ $parent_file ];
     1592                }
    15351593                return $parent_file;
    15361594            }
    15371595        }
    1538         if ( isset( $_wp_menu_nopriv[$plugin_page] ) ) {
     1596        if ( isset( $_wp_menu_nopriv[ $plugin_page ] ) ) {
    15391597            $parent_file = $plugin_page;
    1540             if ( isset( $_wp_real_parent_file[$parent_file] ) )
    1541                     $parent_file = $_wp_real_parent_file[$parent_file];
     1598            if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) {
     1599                    $parent_file = $_wp_real_parent_file[ $parent_file ];
     1600            }
    15421601            return $parent_file;
    15431602        }
    15441603    }
    15451604
    1546     if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) {
     1605    if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $pagenow ][ $plugin_page ] ) ) {
    15471606        $parent_file = $pagenow;
    1548         if ( isset( $_wp_real_parent_file[$parent_file] ) )
    1549             $parent_file = $_wp_real_parent_file[$parent_file];
     1607        if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) {
     1608            $parent_file = $_wp_real_parent_file[ $parent_file ];
     1609        }
    15501610        return $parent_file;
    15511611    }
    15521612
    1553     foreach (array_keys( (array)$submenu ) as $parent) {
    1554         foreach ( $submenu[$parent] as $submenu_array ) {
    1555             if ( isset( $_wp_real_parent_file[$parent] ) )
    1556                 $parent = $_wp_real_parent_file[$parent];
    1557             if ( !empty($typenow) && ($submenu_array[2] == "$pagenow?post_type=$typenow") ) {
     1613    foreach ( array_keys( (array) $submenu ) as $parent ) {
     1614        foreach ( $submenu[ $parent ] as $submenu_array ) {
     1615            if ( isset( $_wp_real_parent_file[ $parent ] ) ) {
     1616                $parent = $_wp_real_parent_file[ $parent ];
     1617            }
     1618            if ( ! empty( $typenow ) && ( $submenu_array[2] == "$pagenow?post_type=$typenow" ) ) {
    15581619                $parent_file = $parent;
    15591620                return $parent;
    1560             } elseif ( $submenu_array[2] == $pagenow && empty($typenow) && ( empty($parent_file) || false === strpos($parent_file, '?') ) ) {
     1621            } elseif ( $submenu_array[2] == $pagenow && empty( $typenow ) && ( empty( $parent_file ) || false === strpos( $parent_file, '?' ) ) ) {
    15611622                $parent_file = $parent;
    15621623                return $parent;
    1563             } elseif ( isset( $plugin_page ) && ($plugin_page == $submenu_array[2] ) ) {
     1624            } elseif ( isset( $plugin_page ) && ( $plugin_page == $submenu_array[2] ) ) {
    15641625                $parent_file = $parent;
    15651626                return $parent;
     
    15681629    }
    15691630
    1570     if ( empty($parent_file) )
     1631    if ( empty( $parent_file ) ) {
    15711632        $parent_file = '';
     1633    }
    15721634    return '';
    15731635}
    15741636
    15751637/**
    1576  *
    15771638 * @global string $title
    15781639 * @global array $menu
     
    15851646    global $title, $menu, $submenu, $pagenow, $plugin_page, $typenow;
    15861647
    1587     if ( ! empty ( $title ) )
     1648    if ( ! empty( $title ) ) {
    15881649        return $title;
     1650    }
    15891651
    15901652    $hook = get_plugin_page_hook( $plugin_page, $pagenow );
     
    15921654    $parent = $parent1 = get_admin_page_parent();
    15931655
    1594     if ( empty ( $parent) ) {
    1595         foreach ( (array)$menu as $menu_array ) {
     1656    if ( empty( $parent ) ) {
     1657        foreach ( (array) $menu as $menu_array ) {
    15961658            if ( isset( $menu_array[3] ) ) {
    15971659                if ( $menu_array[2] == $pagenow ) {
    15981660                    $title = $menu_array[3];
    15991661                    return $menu_array[3];
    1600                 } elseif ( isset( $plugin_page ) && ($plugin_page == $menu_array[2] ) && ($hook == $menu_array[3] ) ) {
     1662                } elseif ( isset( $plugin_page ) && ( $plugin_page == $menu_array[2] ) && ( $hook == $menu_array[3] ) ) {
    16011663                    $title = $menu_array[3];
    16021664                    return $menu_array[3];
     
    16091671    } else {
    16101672        foreach ( array_keys( $submenu ) as $parent ) {
    1611             foreach ( $submenu[$parent] as $submenu_array ) {
     1673            foreach ( $submenu[ $parent ] as $submenu_array ) {
    16121674                if ( isset( $plugin_page ) &&
    16131675                    ( $plugin_page == $submenu_array[2] ) &&
     
    16171679                        ( $plugin_page == $hook ) ||
    16181680                        ( $pagenow == 'admin.php' && $parent1 != $submenu_array[2] ) ||
    1619                         ( !empty($typenow) && $parent == $pagenow . '?post_type=' . $typenow)
     1681                        ( ! empty( $typenow ) && $parent == $pagenow . '?post_type=' . $typenow )
    16201682                    )
    16211683                    ) {
    16221684                        $title = $submenu_array[3];
    16231685                        return $submenu_array[3];
    1624                     }
    1625 
    1626                 if ( $submenu_array[2] != $pagenow || isset( $_GET['page'] ) ) // not the current page
     1686                }
     1687
     1688                if ( $submenu_array[2] != $pagenow || isset( $_GET['page'] ) ) { // not the current page
    16271689                    continue;
     1690                }
    16281691
    16291692                if ( isset( $submenu_array[3] ) ) {
     
    16361699            }
    16371700        }
    1638         if ( empty ( $title ) ) {
     1701        if ( empty( $title ) ) {
    16391702            foreach ( $menu as $menu_array ) {
    16401703                if ( isset( $plugin_page ) &&
    16411704                    ( $plugin_page == $menu_array[2] ) &&
    16421705                    ( $pagenow == 'admin.php' ) &&
    1643                     ( $parent1 == $menu_array[2] ) )
    1644                     {
     1706                    ( $parent1 == $menu_array[2] ) ) {
    16451707                        $title = $menu_array[3];
    16461708                        return $menu_array[3];
    1647                     }
     1709                }
    16481710            }
    16491711        }
     
    16621724function get_plugin_page_hook( $plugin_page, $parent_page ) {
    16631725    $hook = get_plugin_page_hookname( $plugin_page, $parent_page );
    1664     if ( has_action($hook) )
     1726    if ( has_action( $hook ) ) {
    16651727        return $hook;
    1666     else
     1728    } else {
    16671729        return null;
    1668 }
    1669 
    1670 /**
    1671  *
     1730    }
     1731}
     1732
     1733/**
    16721734 * @global array $admin_page_hooks
    16731735 * @param string $plugin_page
     
    16801742
    16811743    $page_type = 'admin';
    1682     if ( empty ( $parent_page ) || 'admin.php' == $parent_page || isset( $admin_page_hooks[$plugin_page] ) ) {
    1683         if ( isset( $admin_page_hooks[$plugin_page] ) ) {
     1744    if ( empty( $parent_page ) || 'admin.php' == $parent_page || isset( $admin_page_hooks[ $plugin_page ] ) ) {
     1745        if ( isset( $admin_page_hooks[ $plugin_page ] ) ) {
    16841746            $page_type = 'toplevel';
    1685         } elseif ( isset( $admin_page_hooks[$parent] )) {
    1686             $page_type = $admin_page_hooks[$parent];
    1687         }
    1688     } elseif ( isset( $admin_page_hooks[$parent] ) ) {
    1689         $page_type = $admin_page_hooks[$parent];
     1747        } elseif ( isset( $admin_page_hooks[ $parent ] ) ) {
     1748            $page_type = $admin_page_hooks[ $parent ];
     1749        }
     1750    } elseif ( isset( $admin_page_hooks[ $parent ] ) ) {
     1751        $page_type = $admin_page_hooks[ $parent ];
    16901752    }
    16911753
     
    16961758
    16971759/**
    1698  *
    16991760 * @global string $pagenow
    17001761 * @global array $menu
     
    17111772    $parent = get_admin_page_parent();
    17121773
    1713     if ( !isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$parent][$pagenow] ) )
     1774    if ( ! isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $parent ][ $pagenow ] ) ) {
    17141775        return false;
     1776    }
    17151777
    17161778    if ( isset( $plugin_page ) ) {
    1717         if ( isset( $_wp_submenu_nopriv[$parent][$plugin_page] ) )
     1779        if ( isset( $_wp_submenu_nopriv[ $parent ][ $plugin_page ] ) ) {
    17181780            return false;
    1719 
    1720         $hookname = get_plugin_page_hookname($plugin_page, $parent);
    1721 
    1722         if ( !isset($_registered_pages[$hookname]) )
     1781        }
     1782
     1783        $hookname = get_plugin_page_hookname( $plugin_page, $parent );
     1784
     1785        if ( ! isset( $_registered_pages[ $hookname ] ) ) {
    17231786            return false;
    1724     }
    1725 
    1726     if ( empty( $parent) ) {
    1727         if ( isset( $_wp_menu_nopriv[$pagenow] ) )
     1787        }
     1788    }
     1789
     1790    if ( empty( $parent ) ) {
     1791        if ( isset( $_wp_menu_nopriv[ $pagenow ] ) ) {
    17281792            return false;
    1729         if ( isset( $_wp_submenu_nopriv[$pagenow][$pagenow] ) )
     1793        }
     1794        if ( isset( $_wp_submenu_nopriv[ $pagenow ][ $pagenow ] ) ) {
    17301795            return false;
    1731         if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) )
     1796        }
     1797        if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $pagenow ][ $plugin_page ] ) ) {
    17321798            return false;
    1733         if ( isset( $plugin_page ) && isset( $_wp_menu_nopriv[$plugin_page] ) )
     1799        }
     1800        if ( isset( $plugin_page ) && isset( $_wp_menu_nopriv[ $plugin_page ] ) ) {
    17341801            return false;
    1735         foreach (array_keys( $_wp_submenu_nopriv ) as $key ) {
    1736             if ( isset( $_wp_submenu_nopriv[$key][$pagenow] ) )
     1802        }
     1803        foreach ( array_keys( $_wp_submenu_nopriv ) as $key ) {
     1804            if ( isset( $_wp_submenu_nopriv[ $key ][ $pagenow ] ) ) {
    17371805                return false;
    1738             if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$key][$plugin_page] ) )
    1739             return false;
     1806            }
     1807            if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $key ][ $plugin_page ] ) ) {
     1808                return false;
     1809            }
    17401810        }
    17411811        return true;
    17421812    }
    17431813
    1744     if ( isset( $plugin_page ) && ( $plugin_page == $parent ) && isset( $_wp_menu_nopriv[$plugin_page] ) )
     1814    if ( isset( $plugin_page ) && ( $plugin_page == $parent ) && isset( $_wp_menu_nopriv[ $plugin_page ] ) ) {
    17451815        return false;
    1746 
    1747     if ( isset( $submenu[$parent] ) ) {
    1748         foreach ( $submenu[$parent] as $submenu_array ) {
     1816    }
     1817
     1818    if ( isset( $submenu[ $parent ] ) ) {
     1819        foreach ( $submenu[ $parent ] as $submenu_array ) {
    17491820            if ( isset( $plugin_page ) && ( $submenu_array[2] == $plugin_page ) ) {
    1750                 if ( current_user_can( $submenu_array[1] ))
     1821                if ( current_user_can( $submenu_array[1] ) ) {
    17511822                    return true;
    1752                 else
     1823                } else {
    17531824                    return false;
     1825                }
    17541826            } elseif ( $submenu_array[2] == $pagenow ) {
    1755                 if ( current_user_can( $submenu_array[1] ))
     1827                if ( current_user_can( $submenu_array[1] ) ) {
    17561828                    return true;
    1757                 else
     1829                } else {
    17581830                    return false;
     1831                }
    17591832            }
    17601833        }
     
    17621835
    17631836    foreach ( $menu as $menu_array ) {
    1764         if ( $menu_array[2] == $parent) {
    1765             if ( current_user_can( $menu_array[1] ))
     1837        if ( $menu_array[2] == $parent ) {
     1838            if ( current_user_can( $menu_array[1] ) ) {
    17661839                return true;
    1767             else
     1840            } else {
    17681841                return false;
     1842            }
    17691843        }
    17701844    }
     
    17901864    global $new_whitelist_options;
    17911865
    1792     if ( is_array( $new_whitelist_options ) )
     1866    if ( is_array( $new_whitelist_options ) ) {
    17931867        $options = add_option_whitelist( $new_whitelist_options, $options );
     1868    }
    17941869
    17951870    return $options;
     
    18081883 */
    18091884function add_option_whitelist( $new_options, $options = '' ) {
    1810     if ( $options == '' )
     1885    if ( $options == '' ) {
    18111886        global $whitelist_options;
    1812     else
     1887    } else {
    18131888        $whitelist_options = $options;
     1889    }
    18141890
    18151891    foreach ( $new_options as $page => $keys ) {
    18161892        foreach ( $keys as $key ) {
    1817             if ( !isset($whitelist_options[ $page ]) || !is_array($whitelist_options[ $page ]) ) {
    1818                 $whitelist_options[ $page ] = array();
     1893            if ( ! isset( $whitelist_options[ $page ] ) || ! is_array( $whitelist_options[ $page ] ) ) {
     1894                $whitelist_options[ $page ]   = array();
    18191895                $whitelist_options[ $page ][] = $key;
    18201896            } else {
    18211897                $pos = array_search( $key, $whitelist_options[ $page ] );
    1822                 if ( $pos === false )
     1898                if ( $pos === false ) {
    18231899                    $whitelist_options[ $page ][] = $key;
     1900                }
    18241901            }
    18251902        }
     
    18411918 */
    18421919function remove_option_whitelist( $del_options, $options = '' ) {
    1843     if ( $options == '' )
     1920    if ( $options == '' ) {
    18441921        global $whitelist_options;
    1845     else
     1922    } else {
    18461923        $whitelist_options = $options;
     1924    }
    18471925
    18481926    foreach ( $del_options as $page => $keys ) {
    18491927        foreach ( $keys as $key ) {
    1850             if ( isset($whitelist_options[ $page ]) && is_array($whitelist_options[ $page ]) ) {
     1928            if ( isset( $whitelist_options[ $page ] ) && is_array( $whitelist_options[ $page ] ) ) {
    18511929                $pos = array_search( $key, $whitelist_options[ $page ] );
    1852                 if ( $pos !== false )
     1930                if ( $pos !== false ) {
    18531931                    unset( $whitelist_options[ $page ][ $pos ] );
     1932                }
    18541933            }
    18551934        }
     
    18661945 * @param string $option_group A settings group name. This should match the group name used in register_setting().
    18671946 */
    1868 function settings_fields($option_group) {
    1869     echo "<input type='hidden' name='option_page' value='" . esc_attr($option_group) . "' />";
     1947function settings_fields( $option_group ) {
     1948    echo "<input type='hidden' name='option_page' value='" . esc_attr( $option_group ) . "' />";
    18701949    echo '<input type="hidden" name="action" value="update" />';
    1871     wp_nonce_field("$option_group-options");
     1950    wp_nonce_field( "$option_group-options" );
    18721951}
    18731952
     
    18801959 */
    18811960function wp_clean_plugins_cache( $clear_update_cache = true ) {
    1882     if ( $clear_update_cache )
     1961    if ( $clear_update_cache ) {
    18831962        delete_site_transient( 'update_plugins' );
     1963    }
    18841964    wp_cache_delete( 'plugins', 'plugins' );
    18851965}
Note: See TracChangeset for help on using the changeset viewer.