Make WordPress Core


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

    r42006 r42343  
    1818 * @return void|bool|WP_Error When void, echoes content.
    1919 */
    20 function delete_theme($stylesheet, $redirect = '') {
     20function delete_theme( $stylesheet, $redirect = '' ) {
    2121    global $wp_filesystem;
    2222
    23     if ( empty($stylesheet) )
     23    if ( empty( $stylesheet ) ) {
    2424        return false;
     25    }
    2526
    2627    if ( empty( $redirect ) ) {
    27         $redirect = wp_nonce_url('themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet);
     28        $redirect = wp_nonce_url( 'themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet );
    2829    }
    2930
    3031    ob_start();
    3132    $credentials = request_filesystem_credentials( $redirect );
    32     $data = ob_get_clean();
     33    $data        = ob_get_clean();
    3334
    3435    if ( false === $credentials ) {
    35         if ( ! empty( $data ) ){
    36             include_once( ABSPATH . 'wp-admin/admin-header.php');
     36        if ( ! empty( $data ) ) {
     37            include_once( ABSPATH . 'wp-admin/admin-header.php' );
    3738            echo $data;
    38             include( ABSPATH . 'wp-admin/admin-footer.php');
     39            include( ABSPATH . 'wp-admin/admin-footer.php' );
    3940            exit;
    4041        }
     
    4748        $data = ob_get_clean();
    4849
    49         if ( ! empty($data) ) {
    50             include_once( ABSPATH . 'wp-admin/admin-header.php');
     50        if ( ! empty( $data ) ) {
     51            include_once( ABSPATH . 'wp-admin/admin-header.php' );
    5152            echo $data;
    52             include( ABSPATH . 'wp-admin/admin-footer.php');
     53            include( ABSPATH . 'wp-admin/admin-footer.php' );
    5354            exit;
    5455        }
     
    5657    }
    5758
    58     if ( ! is_object($wp_filesystem) )
    59         return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
    60 
    61     if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )
    62         return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
     59    if ( ! is_object( $wp_filesystem ) ) {
     60        return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) );
     61    }
     62
     63    if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
     64        return new WP_Error( 'fs_error', __( 'Filesystem error.' ), $wp_filesystem->errors );
     65    }
    6366
    6467    // Get the base plugin folder.
     
    6972
    7073    $themes_dir = trailingslashit( $themes_dir );
    71     $theme_dir = trailingslashit( $themes_dir . $stylesheet );
    72     $deleted = $wp_filesystem->delete( $theme_dir, true );
     74    $theme_dir  = trailingslashit( $themes_dir . $stylesheet );
     75    $deleted    = $wp_filesystem->delete( $theme_dir, true );
    7376
    7477    if ( ! $deleted ) {
     
    123126 * @return string
    124127 */
    125 function _get_template_edit_filename($fullpath, $containingfolder) {
    126     return str_replace(dirname(dirname( $containingfolder )) , '', $fullpath);
     128function _get_template_edit_filename( $fullpath, $containingfolder ) {
     129    return str_replace( dirname( dirname( $containingfolder ) ), '', $fullpath );
    127130}
    128131
     
    156159    static $themes_update = null;
    157160
    158     if ( !current_user_can('update_themes' ) )
     161    if ( ! current_user_can( 'update_themes' ) ) {
    159162        return false;
    160 
    161     if ( !isset($themes_update) )
    162         $themes_update = get_site_transient('update_themes');
     163    }
     164
     165    if ( ! isset( $themes_update ) ) {
     166        $themes_update = get_site_transient( 'update_themes' );
     167    }
    163168
    164169    if ( ! ( $theme instanceof WP_Theme ) ) {
     
    170175    $html = '';
    171176
    172     if ( isset($themes_update->response[ $stylesheet ]) ) {
    173         $update = $themes_update->response[ $stylesheet ];
    174         $theme_name = $theme->display('Name');
    175         $details_url = add_query_arg(array('TB_iframe' => 'true', 'width' => 1024, 'height' => 800), $update['url']); //Theme browser inside WP? replace this, Also, theme preview JS will override this on the available list.
    176         $update_url = wp_nonce_url( admin_url( 'update.php?action=upgrade-theme&theme=' . urlencode( $stylesheet ) ), 'upgrade-theme_' . $stylesheet );
    177 
    178         if ( !is_multisite() ) {
    179             if ( ! current_user_can('update_themes') ) {
     177    if ( isset( $themes_update->response[ $stylesheet ] ) ) {
     178        $update      = $themes_update->response[ $stylesheet ];
     179        $theme_name  = $theme->display( 'Name' );
     180        $details_url = add_query_arg(
     181            array(
     182                'TB_iframe' => 'true',
     183                'width'     => 1024,
     184                'height'    => 800,
     185            ), $update['url']
     186        ); //Theme browser inside WP? replace this, Also, theme preview JS will override this on the available list.
     187        $update_url  = wp_nonce_url( admin_url( 'update.php?action=upgrade-theme&theme=' . urlencode( $stylesheet ) ), 'upgrade-theme_' . $stylesheet );
     188
     189        if ( ! is_multisite() ) {
     190            if ( ! current_user_can( 'update_themes' ) ) {
    180191                /* translators: 1: theme name, 2: theme details URL, 3: additional link attributes, 4: version number */
    181                 $html = sprintf( '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ) . '</strong></p>',
     192                $html = sprintf(
     193                    '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ) . '</strong></p>',
    182194                    $theme_name,
    183195                    esc_url( $details_url ),
    184                     sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
     196                    sprintf(
     197                        'class="thickbox open-plugin-details-modal" aria-label="%s"',
    185198                        /* translators: 1: theme name, 2: version number */
    186199                        esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) )
     
    190203            } elseif ( empty( $update['package'] ) ) {
    191204                /* translators: 1: theme name, 2: theme details URL, 3: additional link attributes, 4: version number */
    192                 $html = sprintf( '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>' ) . '</strong></p>',
     205                $html = sprintf(
     206                    '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>' ) . '</strong></p>',
    193207                    $theme_name,
    194208                    esc_url( $details_url ),
    195                     sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
     209                    sprintf(
     210                        'class="thickbox open-plugin-details-modal" aria-label="%s"',
    196211                        /* translators: 1: theme name, 2: version number */
    197212                        esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) )
     
    201216            } else {
    202217                /* translators: 1: theme name, 2: theme details URL, 3: additional link attributes, 4: version number, 5: update URL, 6: additional link attributes */
    203                 $html = sprintf( '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ) . '</strong></p>',
     218                $html = sprintf(
     219                    '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ) . '</strong></p>',
    204220                    $theme_name,
    205221                    esc_url( $details_url ),
    206                     sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
     222                    sprintf(
     223                        'class="thickbox open-plugin-details-modal" aria-label="%s"',
    207224                        /* translators: 1: theme name, 2: version number */
    208225                        esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) )
     
    210227                    $update['new_version'],
    211228                    $update_url,
    212                     sprintf( 'aria-label="%s" id="update-theme" data-slug="%s"',
     229                    sprintf(
     230                        'aria-label="%s" id="update-theme" data-slug="%s"',
    213231                        /* translators: %s: theme name */
    214232                        esc_attr( sprintf( __( 'Update %s now' ), $theme_name ) ),
     
    263281        ),
    264282
    265         __( 'Layout' ) => array(
     283        __( 'Layout' )   => array(
    266284            'grid-layout'   => __( 'Grid Layout' ),
    267285            'one-column'    => __( 'One Column' ),
     
    271289            'left-sidebar'  => __( 'Left Sidebar' ),
    272290            'right-sidebar' => __( 'Right Sidebar' ),
    273         )
     291        ),
    274292
    275293    );
    276294
    277     if ( ! $api || ! current_user_can( 'install_themes' ) )
     295    if ( ! $api || ! current_user_can( 'install_themes' ) ) {
    278296        return $features;
    279 
    280     if ( !$feature_list = get_site_transient( 'wporg_theme_feature_list' ) )
     297    }
     298
     299    if ( ! $feature_list = get_site_transient( 'wporg_theme_feature_list' ) ) {
    281300        set_site_transient( 'wporg_theme_feature_list', array(), 3 * HOUR_IN_SECONDS );
    282 
    283     if ( !$feature_list ) {
     301    }
     302
     303    if ( ! $feature_list ) {
    284304        $feature_list = themes_api( 'feature_list', array() );
    285         if ( is_wp_error( $feature_list ) )
     305        if ( is_wp_error( $feature_list ) ) {
    286306            return $features;
    287     }
    288 
    289     if ( !$feature_list )
     307        }
     308    }
     309
     310    if ( ! $feature_list ) {
    290311        return $features;
     312    }
    291313
    292314    set_site_transient( 'wporg_theme_feature_list', $feature_list, 3 * HOUR_IN_SECONDS );
     
    301323    $wporg_features = array();
    302324    foreach ( (array) $feature_list as $feature_category => $feature_items ) {
    303         if ( isset($category_translations[$feature_category]) )
    304             $feature_category = $category_translations[$feature_category];
    305         $wporg_features[$feature_category] = array();
     325        if ( isset( $category_translations[ $feature_category ] ) ) {
     326            $feature_category = $category_translations[ $feature_category ];
     327        }
     328        $wporg_features[ $feature_category ] = array();
    306329
    307330        foreach ( $feature_items as $feature ) {
    308             if ( isset($features[$feature_category][$feature]) )
    309                 $wporg_features[$feature_category][$feature] = $features[$feature_category][$feature];
    310             else
    311                 $wporg_features[$feature_category][$feature] = $feature;
     331            if ( isset( $features[ $feature_category ][ $feature ] ) ) {
     332                $wporg_features[ $feature_category ][ $feature ] = $features[ $feature_category ][ $feature ];
     333            } else {
     334                $wporg_features[ $feature_category ][ $feature ] = $feature;
     335            }
    312336        }
    313337    }
     
    446470
    447471        $url = $http_url = 'http://api.wordpress.org/themes/info/1.0/';
    448         if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
     472        if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
    449473            $url = set_url_scheme( $url, 'https' );
     474        }
    450475
    451476        $http_args = array(
    452477            'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
    453             'body' => array(
    454                 'action' => $action,
    455                 'request' => serialize( $args )
    456             )
     478            'body'       => array(
     479                'action'  => $action,
     480                'request' => serialize( $args ),
     481            ),
    457482        );
    458         $request = wp_remote_post( $url, $http_args );
     483        $request   = wp_remote_post( $url, $http_args );
    459484
    460485        if ( $ssl && is_wp_error( $request ) ) {
     
    472497        }
    473498
    474         if ( is_wp_error($request) ) {
    475             $res = new WP_Error( 'themes_api_failed',
     499        if ( is_wp_error( $request ) ) {
     500            $res = new WP_Error(
     501                'themes_api_failed',
    476502                sprintf(
    477503                    /* translators: %s: support forums URL */
     
    484510            $res = maybe_unserialize( wp_remote_retrieve_body( $request ) );
    485511            if ( ! is_object( $res ) && ! is_array( $res ) ) {
    486                 $res = new WP_Error( 'themes_api_failed',
     512                $res = new WP_Error(
     513                    'themes_api_failed',
    487514                    sprintf(
    488515                        /* translators: %s: support forums URL */
     
    563590
    564591    foreach ( $themes as $theme ) {
    565         $slug = $theme->get_stylesheet();
     592        $slug         = $theme->get_stylesheet();
    566593        $encoded_slug = urlencode( $slug );
    567594
    568595        $parent = false;
    569596        if ( $theme->parent() ) {
    570             $parent = $theme->parent();
     597            $parent           = $theme->parent();
    571598            $parents[ $slug ] = $parent->get_stylesheet();
    572             $parent = $parent->display( 'Name' );
     599            $parent           = $parent->display( 'Name' );
    573600        }
    574601
    575602        $customize_action = null;
    576603        if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
    577             $customize_action = esc_url( add_query_arg(
    578                 array(
    579                     'return' => urlencode( esc_url_raw( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ),
    580                 ),
    581                 wp_customize_url( $slug )
    582             ) );
     604            $customize_action = esc_url(
     605                add_query_arg(
     606                    array(
     607                        'return' => urlencode( esc_url_raw( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ),
     608                    ),
     609                    wp_customize_url( $slug )
     610                )
     611            );
    583612        }
    584613
     
    595624            'active'       => $slug === $current_theme,
    596625            'hasUpdate'    => isset( $updates[ $slug ] ),
    597             'hasPackage'   => isset( $updates[ $slug ] ) && ! empty( $updates[ $slug ][ 'package' ] ),
     626            'hasPackage'   => isset( $updates[ $slug ] ) && ! empty( $updates[ $slug ]['package'] ),
    598627            'update'       => get_theme_update_available( $theme ),
    599628            'actions'      => array(
    600                 'activate' => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&amp;stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null,
     629                'activate'  => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&amp;stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null,
    601630                'customize' => $customize_action,
    602                 'delete'   => current_user_can( 'delete_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&amp;stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null,
     631                'delete'    => current_user_can( 'delete_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&amp;stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null,
    603632            ),
    604633        );
Note: See TracChangeset for help on using the changeset viewer.