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

    r39551 r42343  
    1111require_once( dirname( __FILE__ ) . '/admin.php' );
    1212
    13 if ( !current_user_can('manage_network_themes') )
     13if ( ! current_user_can( 'manage_network_themes' ) ) {
    1414        wp_die( __( 'Sorry, you are not allowed to manage network themes.' ) );
    15 
    16 $wp_list_table = _get_list_table('WP_MS_Themes_List_Table');
    17 $pagenum = $wp_list_table->get_pagenum();
     15}
     16
     17$wp_list_table = _get_list_table( 'WP_MS_Themes_List_Table' );
     18$pagenum       = $wp_list_table->get_pagenum();
    1819
    1920$action = $wp_list_table->current_action();
    2021
    21 $s = isset($_REQUEST['s']) ? $_REQUEST['s'] : '';
     22$s = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
    2223
    2324// Clean up request URI from temporary args for screen options/paging uri's to work as expected.
    24 $temp_args = array( 'enabled', 'disabled', 'deleted', 'error' );
     25$temp_args              = array( 'enabled', 'disabled', 'deleted', 'error' );
    2526$_SERVER['REQUEST_URI'] = remove_query_arg( $temp_args, $_SERVER['REQUEST_URI'] );
    26 $referer = remove_query_arg( $temp_args, wp_get_referer() );
     27$referer                = remove_query_arg( $temp_args, wp_get_referer() );
    2728
    2829if ( $action ) {
    2930        switch ( $action ) {
    3031                case 'enable':
    31                         check_admin_referer('enable-theme_' . $_GET['theme']);
     32                        check_admin_referer( 'enable-theme_' . $_GET['theme'] );
    3233                        WP_Theme::network_enable_theme( $_GET['theme'] );
    33                         if ( false === strpos( $referer, '/network/themes.php' ) )
     34                        if ( false === strpos( $referer, '/network/themes.php' ) ) {
    3435                                wp_redirect( network_admin_url( 'themes.php?enabled=1' ) );
    35                         else
     36                        } else {
    3637                                wp_safe_redirect( add_query_arg( 'enabled', 1, $referer ) );
     38                        }
    3739                        exit;
    3840                case 'disable':
    39                         check_admin_referer('disable-theme_' . $_GET['theme']);
     41                        check_admin_referer( 'disable-theme_' . $_GET['theme'] );
    4042                        WP_Theme::network_disable_theme( $_GET['theme'] );
    4143                        wp_safe_redirect( add_query_arg( 'disabled', '1', $referer ) );
    4244                        exit;
    4345                case 'enable-selected':
    44                         check_admin_referer('bulk-themes');
     46                        check_admin_referer( 'bulk-themes' );
    4547                        $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
    46                         if ( empty($themes) ) {
     48                        if ( empty( $themes ) ) {
    4749                                wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
    4850                                exit;
     
    5254                        exit;
    5355                case 'disable-selected':
    54                         check_admin_referer('bulk-themes');
     56                        check_admin_referer( 'bulk-themes' );
    5557                        $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
    56                         if ( empty($themes) ) {
     58                        if ( empty( $themes ) ) {
    5759                                wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
    5860                                exit;
     
    6163                        wp_safe_redirect( add_query_arg( 'disabled', count( $themes ), $referer ) );
    6264                        exit;
    63                 case 'update-selected' :
    64                         check_admin_referer( 'bulk-themes' );
    65 
    66                         if ( isset( $_GET['themes'] ) )
     65                case 'update-selected':
     66                        check_admin_referer( 'bulk-themes' );
     67
     68                        if ( isset( $_GET['themes'] ) ) {
    6769                                $themes = explode( ',', $_GET['themes'] );
    68                         elseif ( isset( $_POST['checked'] ) )
     70                        } elseif ( isset( $_POST['checked'] ) ) {
    6971                                $themes = (array) $_POST['checked'];
    70                         else
     72                        } else {
    7173                                $themes = array();
    72 
    73                         $title = __( 'Update Themes' );
     74                        }
     75
     76                        $title       = __( 'Update Themes' );
    7477                        $parent_file = 'themes.php';
    7578
    76                         require_once(ABSPATH . 'wp-admin/admin-header.php');
     79                        require_once( ABSPATH . 'wp-admin/admin-header.php' );
    7780
    7881                        echo '<div class="wrap">';
    7982                        echo '<h1>' . esc_html( $title ) . '</h1>';
    8083
    81                         $url = self_admin_url('update.php?action=update-selected-themes&amp;themes=' . urlencode( join(',', $themes) ));
    82                         $url = wp_nonce_url($url, 'bulk-update-themes');
     84                        $url = self_admin_url( 'update.php?action=update-selected-themes&amp;themes=' . urlencode( join( ',', $themes ) ) );
     85                        $url = wp_nonce_url( $url, 'bulk-update-themes' );
    8386
    8487                        echo "<iframe src='$url' style='width: 100%; height:100%; min-height:850px;'></iframe>";
    8588                        echo '</div>';
    86                         require_once(ABSPATH . 'wp-admin/admin-footer.php');
     89                        require_once( ABSPATH . 'wp-admin/admin-footer.php' );
    8790                        exit;
    8891                case 'delete-selected':
    8992                        if ( ! current_user_can( 'delete_themes' ) ) {
    90                                 wp_die( __('Sorry, you are not allowed to delete themes for this site.') );
     93                                wp_die( __( 'Sorry, you are not allowed to delete themes for this site.' ) );
    9194                        }
    9295
     
    112115                        }
    113116
    114                         include(ABSPATH . 'wp-admin/update.php');
     117                        include( ABSPATH . 'wp-admin/update.php' );
    115118
    116119                        $parent_file = 'themes.php';
     
    133136                                        <ul class="ul-disc">
    134137                                        <?php
    135                                                 foreach ( $theme_info as $theme ) {
    136                                                         echo '<li>' . sprintf(
    137                                                                 /* translators: 1: theme name, 2: theme author */
    138                                                                 _x( '%1$s by %2$s', 'theme' ),
    139                                                                 '<strong>' . $theme->display( 'Name' ) . '</strong>',
    140                                                                 '<em>' . $theme->display( 'Author' ) . '</em>'
    141                                                         ) . '</li>';
    142                                                 }
     138                                        foreach ( $theme_info as $theme ) {
     139                                                echo '<li>' . sprintf(
     140                                                        /* translators: 1: theme name, 2: theme author */
     141                                                        _x( '%1$s by %2$s', 'theme' ),
     142                                                        '<strong>' . $theme->display( 'Name' ) . '</strong>',
     143                                                        '<em>' . $theme->display( 'Author' ) . '</em>'
     144                                                ) . '</li>';
     145                                        }
    143146                                        ?>
    144147                                        </ul>
     
    148151                                        <p><?php _e( 'Are you sure you wish to delete these themes?' ); ?></p>
    149152                                <?php endif; ?>
    150                                 <form method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" style="display:inline;">
     153                                <form method="post" action="<?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?>" style="display:inline;">
    151154                                        <input type="hidden" name="verify-delete" value="1" />
    152155                                        <input type="hidden" name="action" value="delete-selected" />
    153156                                        <?php
    154                                                 foreach ( (array) $themes as $theme ) {
    155                                                         echo '<input type="hidden" name="checked[]" value="' . esc_attr($theme) . '" />';
    156                                                 }
     157                                        foreach ( (array) $themes as $theme ) {
     158                                                echo '<input type="hidden" name="checked[]" value="' . esc_attr( $theme ) . '" />';
     159                                        }
    157160
    158161                                                wp_nonce_field( 'bulk-themes' );
    159162
    160                                                 if ( 1 == $themes_to_delete ) {
    161                                                         submit_button( __( 'Yes, delete this theme' ), '', 'submit', false );
    162                                                 } else {
    163                                                         submit_button( __( 'Yes, delete these themes' ), '', 'submit', false );
    164                                                 }
     163                                        if ( 1 == $themes_to_delete ) {
     164                                                submit_button( __( 'Yes, delete this theme' ), '', 'submit', false );
     165                                        } else {
     166                                                submit_button( __( 'Yes, delete these themes' ), '', 'submit', false );
     167                                        }
    165168                                        ?>
    166169                                </form>
     
    173176                        </div>
    174177                                <?php
    175                                 require_once(ABSPATH . 'wp-admin/admin-footer.php');
     178                                require_once( ABSPATH . 'wp-admin/admin-footer.php' );
    176179                                exit;
    177180                        } // Endif verify-delete
    178181
    179182                        foreach ( $themes as $theme ) {
    180                                 $delete_result = delete_theme( $theme, esc_url( add_query_arg( array(
    181                                         'verify-delete' => 1,
    182                                         'action' => 'delete-selected',
    183                                         'checked' => $_REQUEST['checked'],
    184                                         '_wpnonce' => $_REQUEST['_wpnonce']
    185                                 ), network_admin_url( 'themes.php' ) ) ) );
     183                                $delete_result = delete_theme(
     184                                        $theme, esc_url(
     185                                                add_query_arg(
     186                                                        array(
     187                                                                'verify-delete' => 1,
     188                                                                'action'        => 'delete-selected',
     189                                                                'checked'       => $_REQUEST['checked'],
     190                                                                '_wpnonce'      => $_REQUEST['_wpnonce'],
     191                                                        ), network_admin_url( 'themes.php' )
     192                                                )
     193                                        )
     194                                );
    186195                        }
    187196
    188197                        $paged = ( $_REQUEST['paged'] ) ? $_REQUEST['paged'] : 1;
    189                         wp_redirect( add_query_arg( array(
    190                                 'deleted' => count( $themes ),
    191                                 'paged' => $paged,
    192                                 's' => $s
    193                         ), network_admin_url( 'themes.php' ) ) );
     198                        wp_redirect(
     199                                add_query_arg(
     200                                        array(
     201                                                'deleted' => count( $themes ),
     202                                                'paged'   => $paged,
     203                                                's'       => $s,
     204                                        ), network_admin_url( 'themes.php' )
     205                                )
     206                        );
    194207                        exit;
    195208                default:
     
    207220                        exit;
    208221        }
    209 
    210222}
    211223
     
    216228add_screen_option( 'per_page' );
    217229
    218 get_current_screen()->add_help_tab( array(
    219         'id'      => 'overview',
    220         'title'   => __('Overview'),
    221         'content' =>
    222                 '<p>' . __('This screen enables and disables the inclusion of themes available to choose in the Appearance menu for each site. It does not activate or deactivate which theme a site is currently using.') . '</p>' .
    223                 '<p>' . __('If the network admin disables a theme that is in use, it can still remain selected on that site. If another theme is chosen, the disabled theme will not appear in the site&#8217;s Appearance > Themes screen.') . '</p>' .
    224                 '<p>' . __('Themes can be enabled on a site by site basis by the network admin on the Edit Site screen (which has a Themes tab); get there via the Edit action link on the All Sites screen. Only network admins are able to install or edit themes.') . '</p>'
    225 ) );
     230get_current_screen()->add_help_tab(
     231        array(
     232                'id'      => 'overview',
     233                'title'   => __( 'Overview' ),
     234                'content' =>
     235                        '<p>' . __( 'This screen enables and disables the inclusion of themes available to choose in the Appearance menu for each site. It does not activate or deactivate which theme a site is currently using.' ) . '</p>' .
     236                        '<p>' . __( 'If the network admin disables a theme that is in use, it can still remain selected on that site. If another theme is chosen, the disabled theme will not appear in the site&#8217;s Appearance > Themes screen.' ) . '</p>' .
     237                        '<p>' . __( 'Themes can be enabled on a site by site basis by the network admin on the Edit Site screen (which has a Themes tab); get there via the Edit action link on the All Sites screen. Only network admins are able to install or edit themes.' ) . '</p>',
     238        )
     239);
    226240
    227241get_current_screen()->set_help_sidebar(
    228         '<p><strong>' . __('For more information:') . '</strong></p>' .
    229         '<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Themes_Screen">Documentation on Network Themes</a>') . '</p>' .
    230         '<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>'
     242        '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
     243        '<p>' . __( '<a href="https://codex.wordpress.org/Network_Admin_Themes_Screen">Documentation on Network Themes</a>' ) . '</p>' .
     244        '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>'
    231245);
    232246
    233 get_current_screen()->set_screen_reader_content( array(
    234         'heading_views'      => __( 'Filter themes list' ),
    235         'heading_pagination' => __( 'Themes list navigation' ),
    236         'heading_list'       => __( 'Themes list' ),
    237 ) );
    238 
    239 $title = __('Themes');
     247get_current_screen()->set_screen_reader_content(
     248        array(
     249                'heading_views'      => __( 'Filter themes list' ),
     250                'heading_pagination' => __( 'Themes list navigation' ),
     251                'heading_list'       => __( 'Themes list' ),
     252        )
     253);
     254
     255$title       = __( 'Themes' );
    240256$parent_file = 'themes.php';
    241257
     
    243259wp_enqueue_script( 'theme-preview' );
    244260
    245 require_once(ABSPATH . 'wp-admin/admin-header.php');
     261require_once( ABSPATH . 'wp-admin/admin-header.php' );
    246262
    247263?>
     
    303319$wp_list_table->views();
    304320
    305 if ( 'broken' == $status )
     321if ( 'broken' == $status ) {
    306322        echo '<p class="clear">' . __( 'The following themes are installed but incomplete.' ) . '</p>';
     323}
    307324?>
    308325
    309326<form id="bulk-action-form" method="post">
    310 <input type="hidden" name="theme_status" value="<?php echo esc_attr($status) ?>" />
    311 <input type="hidden" name="paged" value="<?php echo esc_attr($page) ?>" />
     327<input type="hidden" name="theme_status" value="<?php echo esc_attr( $status ); ?>" />
     328<input type="hidden" name="paged" value="<?php echo esc_attr( $page ); ?>" />
    312329
    313330<?php $wp_list_table->display(); ?>
     
    321338wp_print_update_row_templates();
    322339
    323 include(ABSPATH . 'wp-admin/admin-footer.php');
     340include( ABSPATH . 'wp-admin/admin-footer.php' );
Note: See TracChangeset for help on using the changeset viewer.