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/themes.php

    r42217 r42343  
    1818}
    1919
    20 if ( current_user_can( 'switch_themes' ) && isset($_GET['action'] ) ) {
     20if ( current_user_can( 'switch_themes' ) && isset( $_GET['action'] ) ) {
    2121        if ( 'activate' == $_GET['action'] ) {
    22                 check_admin_referer('switch-theme_' . $_GET['stylesheet']);
     22                check_admin_referer( 'switch-theme_' . $_GET['stylesheet'] );
    2323                $theme = wp_get_theme( $_GET['stylesheet'] );
    2424
    … …  
    3232
    3333                switch_theme( $theme->get_stylesheet() );
    34                 wp_redirect( admin_url('themes.php?activated=true') );
     34                wp_redirect( admin_url( 'themes.php?activated=true' ) );
    3535                exit;
    3636        } elseif ( 'delete' == $_GET['action'] ) {
    37                 check_admin_referer('delete-theme_' . $_GET['stylesheet']);
     37                check_admin_referer( 'delete-theme_' . $_GET['stylesheet'] );
    3838                $theme = wp_get_theme( $_GET['stylesheet'] );
    3939
    … …  
    6565}
    6666
    67 $title = __('Manage Themes');
     67$title       = __( 'Manage Themes' );
    6868$parent_file = 'themes.php';
    6969
    7070// Help tab: Overview
    7171if ( current_user_can( 'switch_themes' ) ) {
    72         $help_overview  = '<p>' . __( 'This screen is used for managing your installed themes. Aside from the default theme(s) included with your WordPress installation, themes are designed and developed by third parties.' ) . '</p>' .
     72        $help_overview = '<p>' . __( 'This screen is used for managing your installed themes. Aside from the default theme(s) included with your WordPress installation, themes are designed and developed by third parties.' ) . '</p>' .
    7373                '<p>' . __( 'From this screen you can:' ) . '</p>' .
    7474                '<ul><li>' . __( 'Hover or tap to see Activate and Live Preview buttons' ) . '</li>' .
    … …  
    7878                '<p>' . __( 'The search for installed themes will search for terms in their name, description, author, or tag.' ) . ' <span id="live-search-desc">' . __( 'The search results will be updated as you type.' ) . '</span></p>';
    7979
    80         get_current_screen()->add_help_tab( array(
    81                 'id'      => 'overview',
    82                 'title'   => __( 'Overview' ),
    83                 'content' => $help_overview
    84         ) );
     80        get_current_screen()->add_help_tab(
     81                array(
     82                        'id'      => 'overview',
     83                        'title'   => __( 'Overview' ),
     84                        'content' => $help_overview,
     85                )
     86        );
    8587} // switch_themes
    8688
    … …  
    8890if ( current_user_can( 'install_themes' ) ) {
    8991        if ( is_multisite() ) {
    90                 $help_install = '<p>' . __('Installing themes on Multisite can only be done from the Network Admin section.') . '</p>';
     92                $help_install = '<p>' . __( 'Installing themes on Multisite can only be done from the Network Admin section.' ) . '</p>';
    9193        } else {
    92                 $help_install = '<p>' . sprintf( __('If you would like to see more themes to choose from, click on the &#8220;Add New&#8221; button and you will be able to browse or search for additional themes from the <a href="%s">WordPress Theme Directory</a>. Themes in the WordPress Theme Directory are designed and developed by third parties, and are compatible with the license WordPress uses. Oh, and they&#8217;re free!'), __( 'https://wordpress.org/themes/' ) ) . '</p>';
     94                $help_install = '<p>' . sprintf( __( 'If you would like to see more themes to choose from, click on the &#8220;Add New&#8221; button and you will be able to browse or search for additional themes from the <a href="%s">WordPress Theme Directory</a>. Themes in the WordPress Theme Directory are designed and developed by third parties, and are compatible with the license WordPress uses. Oh, and they&#8217;re free!' ), __( 'https://wordpress.org/themes/' ) ) . '</p>';
    9395        }
    9496
    95         get_current_screen()->add_help_tab( array(
    96                 'id'      => 'adding-themes',
    97                 'title'   => __('Adding Themes'),
    98                 'content' => $help_install
    99         ) );
     97        get_current_screen()->add_help_tab(
     98                array(
     99                        'id'      => 'adding-themes',
     100                        'title'   => __( 'Adding Themes' ),
     101                        'content' => $help_install,
     102                )
     103        );
    100104} // install_themes
    101105
    … …  
    103107if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
    104108        $help_customize =
    105                 '<p>' . __( 'Tap or hover on any theme then click the Live Preview button to see a live preview of that theme and change theme options in a separate, full-screen view. You can also find a Live Preview button at the bottom of the theme details screen. Any installed theme can be previewed and customized in this way.' ) . '</p>'.
     109                '<p>' . __( 'Tap or hover on any theme then click the Live Preview button to see a live preview of that theme and change theme options in a separate, full-screen view. You can also find a Live Preview button at the bottom of the theme details screen. Any installed theme can be previewed and customized in this way.' ) . '</p>' .
    106110                '<p>' . __( 'The theme being previewed is fully interactive &mdash; navigate to different pages to see how the theme handles posts, archives, and other page templates. The settings may differ depending on what theme features the theme being previewed supports. To accept the new settings and activate the theme all in one step, click the Publish &amp; Activate button above the menu.' ) . '</p>' .
    107111                '<p>' . __( 'When previewing on smaller monitors, you can use the collapse icon at the bottom of the left-hand pane. This will hide the pane, giving you more room to preview your site in the new theme. To bring the pane back, click on the collapse icon again.' ) . '</p>';
    108112
    109         get_current_screen()->add_help_tab( array(
    110                 'id'            => 'customize-preview-themes',
    111                 'title'         => __( 'Previewing and Customizing' ),
    112                 'content'       => $help_customize
    113         ) );
     113        get_current_screen()->add_help_tab(
     114                array(
     115                        'id'      => 'customize-preview-themes',
     116                        'title'   => __( 'Previewing and Customizing' ),
     117                        'content' => $help_customize,
     118                )
     119        );
    114120} // edit_theme_options && customize
    115121
    … …  
    127133wp_reset_vars( array( 'theme', 'search' ) );
    128134
    129 wp_localize_script( 'theme', '_wpThemeSettings', array(
    130         'themes'   => $themes,
    131         'settings' => array(
    132                 'canInstall'    => ( ! is_multisite() && current_user_can( 'install_themes' ) ),
    133                 'installURI'    => ( ! is_multisite() && current_user_can( 'install_themes' ) ) ? admin_url( 'theme-install.php' ) : null,
    134                 'confirmDelete' => __( "Are you sure you want to delete this theme?\n\nClick 'Cancel' to go back, 'OK' to confirm the delete." ),
    135                 'adminUrl'      => parse_url( admin_url(), PHP_URL_PATH ),
    136         ),
    137         'l10n' => array(
    138                 'addNew'            => __( 'Add New Theme' ),
    139                 'search'            => __( 'Search Installed Themes' ),
    140                 'searchPlaceholder' => __( 'Search installed themes...' ), // placeholder (no ellipsis)
    141                 'themesFound'       => __( 'Number of Themes found: %d' ),
    142                 'noThemesFound'     => __( 'No themes found. Try a different search.' ),
    143         ),
    144 ) );
     135wp_localize_script(
     136        'theme', '_wpThemeSettings', array(
     137                'themes'   => $themes,
     138                'settings' => array(
     139                        'canInstall'    => ( ! is_multisite() && current_user_can( 'install_themes' ) ),
     140                        'installURI'    => ( ! is_multisite() && current_user_can( 'install_themes' ) ) ? admin_url( 'theme-install.php' ) : null,
     141                        'confirmDelete' => __( "Are you sure you want to delete this theme?\n\nClick 'Cancel' to go back, 'OK' to confirm the delete." ),
     142                        'adminUrl'      => parse_url( admin_url(), PHP_URL_PATH ),
     143                ),
     144                'l10n'     => array(
     145                        'addNew'            => __( 'Add New Theme' ),
     146                        'search'            => __( 'Search Installed Themes' ),
     147                        'searchPlaceholder' => __( 'Search installed themes...' ), // placeholder (no ellipsis)
     148                        'themesFound'       => __( 'Number of Themes found: %d' ),
     149                        'noThemesFound'     => __( 'No themes found. Try a different search.' ),
     150                ),
     151        )
     152);
    145153
    146154add_thickbox();
    … …  
    164172        <hr class="wp-header-end">
    165173<?php
    166 if ( ! validate_current_theme() || isset( $_GET['broken'] ) ) : ?>
    167 <div id="message1" class="updated notice is-dismissible"><p><?php _e('The active theme is broken. Reverting to the default theme.'); ?></p></div>
    168 <?php elseif ( isset($_GET['activated']) ) :
    169                 if ( isset( $_GET['previewed'] ) ) { ?>
     174if ( ! validate_current_theme() || isset( $_GET['broken'] ) ) :
     175?>
     176<div id="message1" class="updated notice is-dismissible"><p><?php _e( 'The active theme is broken. Reverting to the default theme.' ); ?></p></div>
     177<?php
     178elseif ( isset( $_GET['activated'] ) ) :
     179        if ( isset( $_GET['previewed'] ) ) {
     180                ?>
    170181                <div id="message2" class="updated notice is-dismissible"><p><?php _e( 'Settings saved and theme activated.' ); ?> <a href="<?php echo home_url( '/' ); ?>"><?php _e( 'Visit site' ); ?></a></p></div>
    171182                <?php } else { ?>
    172 <div id="message2" class="updated notice is-dismissible"><p><?php _e( 'New theme activated.' ); ?> <a href="<?php echo home_url( '/' ); ?>"><?php _e( 'Visit site' ); ?></a></p></div><?php
    173                 }
    174         elseif ( isset($_GET['deleted']) ) : ?>
    175 <div id="message3" class="updated notice is-dismissible"><p><?php _e('Theme deleted.') ?></p></div>
     183<div id="message2" class="updated notice is-dismissible"><p><?php _e( 'New theme activated.' ); ?> <a href="<?php echo home_url( '/' ); ?>"><?php _e( 'Visit site' ); ?></a></p></div>
     184                                                                                                                                                <?php
     185}
     186        elseif ( isset( $_GET['deleted'] ) ) :
     187        ?>
     188<div id="message3" class="updated notice is-dismissible"><p><?php _e( 'Theme deleted.' ); ?></p></div>
    176189<?php elseif ( isset( $_GET['delete-active-child'] ) ) : ?>
    177190        <div id="message4" class="error"><p><?php _e( 'You cannot delete a theme while it has an active child theme.' ); ?></p></div>
    … …  
    193206        // Pretend you didn't see this.
    194207        $current_theme_actions = array();
    195         if ( is_array( $submenu ) && isset( $submenu['themes.php'] ) ) {
    196                 foreach ( (array) $submenu['themes.php'] as $item) {
    197                         $class = '';
    198                         if ( 'themes.php' == $item[2] || 'theme-editor.php' == $item[2] || 0 === strpos( $item[2], 'customize.php' ) )
    199                                 continue;
    200                         // 0 = name, 1 = capability, 2 = file
    201                         if ( ( strcmp($self, $item[2]) == 0 && empty($parent_file)) || ($parent_file && ($item[2] == $parent_file)) )
    202                                 $class = ' current';
    203                         if ( !empty($submenu[$item[2]]) ) {
    204                                 $submenu[$item[2]] = array_values($submenu[$item[2]]); // Re-index.
    205                                 $menu_hook = get_plugin_page_hook($submenu[$item[2]][0][2], $item[2]);
    206                                 if ( file_exists(WP_PLUGIN_DIR . "/{$submenu[$item[2]][0][2]}") || !empty($menu_hook))
    207                                         $current_theme_actions[] = "<a class='button$class' href='admin.php?page={$submenu[$item[2]][0][2]}'>{$item[0]}</a>";
    208                                 else
    209                                         $current_theme_actions[] = "<a class='button$class' href='{$submenu[$item[2]][0][2]}'>{$item[0]}</a>";
    210                         } elseif ( ! empty( $item[2] ) && current_user_can( $item[1] ) ) {
    211                                 $menu_file = $item[2];
    212 
    213                                 if ( current_user_can( 'customize' ) ) {
    214                                         if ( 'custom-header' === $menu_file ) {
    215                                                 $current_theme_actions[] = "<a class='button hide-if-no-customize$class' href='customize.php?autofocus[control]=header_image'>{$item[0]}</a>";
    216                                         } elseif ( 'custom-background' === $menu_file ) {
    217                                                 $current_theme_actions[] = "<a class='button hide-if-no-customize$class' href='customize.php?autofocus[control]=background_image'>{$item[0]}</a>";
    218                                         }
    219                                 }
    220 
    221                                 if ( false !== ( $pos = strpos( $menu_file, '?' ) ) ) {
    222                                         $menu_file = substr( $menu_file, 0, $pos );
    223                                 }
    224 
    225                                 if ( file_exists( ABSPATH . "wp-admin/$menu_file" ) ) {
    226                                         $current_theme_actions[] = "<a class='button$class' href='{$item[2]}'>{$item[0]}</a>";
    227                                 } else {
    228                                         $current_theme_actions[] = "<a class='button$class' href='themes.php?page={$item[2]}'>{$item[0]}</a>";
     208if ( is_array( $submenu ) && isset( $submenu['themes.php'] ) ) {
     209        foreach ( (array) $submenu['themes.php'] as $item ) {
     210                $class = '';
     211                if ( 'themes.php' == $item[2] || 'theme-editor.php' == $item[2] || 0 === strpos( $item[2], 'customize.php' ) ) {
     212                        continue;
     213                }
     214                // 0 = name, 1 = capability, 2 = file
     215                if ( ( strcmp( $self, $item[2] ) == 0 && empty( $parent_file ) ) || ( $parent_file && ( $item[2] == $parent_file ) ) ) {
     216                        $class = ' current';
     217                }
     218                if ( ! empty( $submenu[ $item[2] ] ) ) {
     219                        $submenu[ $item[2] ] = array_values( $submenu[ $item[2] ] ); // Re-index.
     220                        $menu_hook           = get_plugin_page_hook( $submenu[ $item[2] ][0][2], $item[2] );
     221                        if ( file_exists( WP_PLUGIN_DIR . "/{$submenu[$item[2]][0][2]}" ) || ! empty( $menu_hook ) ) {
     222                                $current_theme_actions[] = "<a class='button$class' href='admin.php?page={$submenu[$item[2]][0][2]}'>{$item[0]}</a>";
     223                        } else {
     224                                $current_theme_actions[] = "<a class='button$class' href='{$submenu[$item[2]][0][2]}'>{$item[0]}</a>";
     225                        }
     226                } elseif ( ! empty( $item[2] ) && current_user_can( $item[1] ) ) {
     227                        $menu_file = $item[2];
     228
     229                        if ( current_user_can( 'customize' ) ) {
     230                                if ( 'custom-header' === $menu_file ) {
     231                                        $current_theme_actions[] = "<a class='button hide-if-no-customize$class' href='customize.php?autofocus[control]=header_image'>{$item[0]}</a>";
     232                                } elseif ( 'custom-background' === $menu_file ) {
     233                                        $current_theme_actions[] = "<a class='button hide-if-no-customize$class' href='customize.php?autofocus[control]=background_image'>{$item[0]}</a>";
    229234                                }
    230235                        }
     236
     237                        if ( false !== ( $pos = strpos( $menu_file, '?' ) ) ) {
     238                                $menu_file = substr( $menu_file, 0, $pos );
     239                        }
     240
     241                        if ( file_exists( ABSPATH . "wp-admin/$menu_file" ) ) {
     242                                $current_theme_actions[] = "<a class='button$class' href='{$item[2]}'>{$item[0]}</a>";
     243                        } else {
     244                                $current_theme_actions[] = "<a class='button$class' href='themes.php?page={$item[2]}'>{$item[0]}</a>";
     245                        }
    231246                }
    232247        }
     248}
    233249
    234250?>
    … …  
    319335<?php
    320336// List broken themes, if any.
    321 if ( ! is_multisite() && current_user_can('edit_themes') && $broken_themes = wp_get_themes( array( 'errors' => true ) ) ) {
     337if ( ! is_multisite() && current_user_can( 'edit_themes' ) && $broken_themes = wp_get_themes( array( 'errors' => true ) ) ) {
    322338?>
    323339
    324340<div class="broken-themes">
    325 <h3><?php _e('Broken Themes'); ?></h3>
     341<h3><?php _e( 'Broken Themes' ); ?></h3>
    326342<p><?php _e( 'The following themes are installed but incomplete.' ); ?></p>
    327343
    328344<?php
    329 $can_delete = current_user_can( 'delete_themes' );
     345$can_delete  = current_user_can( 'delete_themes' );
    330346$can_install = current_user_can( 'install_themes' );
    331347?>
    332348<table>
    333349        <tr>
    334                 <th><?php _ex('Name', 'theme name'); ?></th>
    335                 <th><?php _e('Description'); ?></th>
     350                <th><?php _ex( 'Name', 'theme name' ); ?></th>
     351                <th><?php _e( 'Description' ); ?></th>
    336352                <?php if ( $can_delete ) { ?>
    337353                        <td></td>
    … …  
    348364                        if ( $can_delete ) {
    349365                                $stylesheet = $broken_theme->get_stylesheet();
    350                                 $delete_url = add_query_arg( array(
    351                                         'action'     => 'delete',
    352                                         'stylesheet' => urlencode( $stylesheet ),
    353                                 ), admin_url( 'themes.php' ) );
     366                                $delete_url = add_query_arg(
     367                                        array(
     368                                                'action'     => 'delete',
     369                                                'stylesheet' => urlencode( $stylesheet ),
     370                                        ), admin_url( 'themes.php' )
     371                                );
    354372                                $delete_url = wp_nonce_url( $delete_url, 'delete-theme_' . $stylesheet );
    355373                                ?>
    … …  
    360378                        if ( $can_install && 'theme_no_parent' === $broken_theme->errors()->get_error_code() ) {
    361379                                $parent_theme_name = $broken_theme->get( 'Template' );
    362                                 $parent_theme = themes_api( 'theme_information', array( 'slug' => urlencode( $parent_theme_name ) ) );
     380                                $parent_theme      = themes_api( 'theme_information', array( 'slug' => urlencode( $parent_theme_name ) ) );
    363381
    364382                                if ( ! is_wp_error( $parent_theme ) ) {
    365                                         $install_url = add_query_arg( array(
    366                                                 'action' => 'install-theme',
    367                                                 'theme'  => urlencode( $parent_theme_name ),
    368                                         ), admin_url( 'update.php' ) );
     383                                        $install_url = add_query_arg(
     384                                                array(
     385                                                        'action' => 'install-theme',
     386                                                        'theme'  => urlencode( $parent_theme_name ),
     387                                                ), admin_url( 'update.php' )
     388                                        );
    369389                                        $install_url = wp_nonce_url( $install_url, 'install-theme_' . $parent_theme_name );
    370390                                        ?>
    … …  
    513533wp_print_update_row_templates();
    514534
    515 wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
    516         'totals'  => wp_get_update_data(),
    517 ) );
     535wp_localize_script(
     536        'updates', '_wpUpdatesItemCounts', array(
     537                'totals' => wp_get_update_data(),
     538        )
     539);
    518540
    519541require( ABSPATH . 'wp-admin/admin-footer.php' );
Note: See TracChangeset for help on using the changeset viewer.