WordPress.org

Make WordPress Core

Ticket #15800: 15800.2.patch

File 15800.2.patch, 10.0 KB (added by johnjamesjacoby, 6 years ago)

Refresh, and refactor the original patch a bit

  • src/wp-admin/includes/ms.php

    diff --git a/src/wp-admin/includes/ms.php b/src/wp-admin/includes/ms.php
    index 6e8fb07..1657da2 100644
    a b  
    11241124</script>
    11251125<?php
    11261126}
     1127
     1128/**
     1129 * Output the HTML for a network's "Edit Site" tabular interface
     1130 *
     1131 * @since 4.6.0
     1132 *
     1133 * @link https://core.trac.wordpress.org/ticket/15800 discussion
     1134 *
     1135 * @param $args {
     1136 *     Optional. Array or string of Query parameters.
     1137 *
     1138 *     @type int          $blog_id     The site ID. Default is the current site.
     1139 *     @type string|array $before      The HTML to echo before the tabs
     1140 *     @type string|array $after       The HTML to echo after the tabs
     1141 *     @type array        $tabs        The tabs to include with (label|url|cap) keys
     1142 *     @type array        $screen_tabs Pre-rendered HTML tabs if you wish to own their output
     1143 * }
     1144 */
     1145function network_edit_site_tabs( $args = array() ) {
     1146        global $pagenow;
     1147
     1148        /**
     1149         * Filter the tabs that appear on site-editing network pages
     1150         *
     1151         * Default tabs: 'site-info', 'site-users', 'site-themes', and 'site-settings'
     1152         *
     1153         * @since 4.6.0
     1154         *
     1155         * @param array         $search_columns Array of column names to be searched.
     1156         * @param string        $search         Text being searched.
     1157         * @param WP_User_Query $this           The current WP_User_Query instance.
     1158         */
     1159        $tabs = apply_filters( 'network_edit_site_tabs', array(
     1160                'site-info'     => array( 'label' => __( 'Info' ),     'url' => 'site-info.php',     'cap' => 'manage_site_info'     ),
     1161                'site-users'    => array( 'label' => __( 'Users' ),    'url' => 'site-users.php',    'cap' => 'manage_site_users'    ),
     1162                'site-themes'   => array( 'label' => __( 'Themes' ),   'url' => 'site-themes.php',   'cap' => 'manage_site_themes'   ),
     1163                'site-settings' => array( 'label' => __( 'Settings' ), 'url' => 'site-settings.php', 'cap' => 'manage_site_settings' )
     1164        ) );
     1165
     1166        // Parse arguments
     1167        $r = wp_parse_args( $args, array(
     1168                'blog_id'     => 0,
     1169                'before'      => '<h2 class="nav-tab-wrapper wp-clearfix" role="tablist">',
     1170                'after'       => '</h2>',
     1171                'tabs'        => $tabs,
     1172                'screen_tabs' => array()
     1173        ) );
     1174
     1175        /**
     1176         * Filter the arguments used to output tabs that appear on site-editing network pages
     1177         *
     1178         * @since 4.6.0
     1179         *
     1180         * @param array $r    Parsed arguments
     1181         * @param array $args Original arguments
     1182         */
     1183        $r = apply_filters( 'network_edit_site_tabs_args', $r, $args );
     1184
     1185        // Loop through tabs
     1186        foreach ( $r['tabs'] as $tab_id => $tab ) {
     1187
     1188                // Skip tab if user can't access
     1189                if ( ! current_user_can( $tab['cap'], $r['blog_id'] ) ) {
     1190                        continue;
     1191                }
     1192
     1193                // Skip if tab is pre-loaded
     1194                if ( isset( $r['screen_tabs'][ $tab_id ] ) ) {
     1195                        continue;
     1196                }
     1197
     1198                // Is this tab active?
     1199                $class = ( $tab['url'] === $pagenow )
     1200                        ? ' nav-tab-active'
     1201                        : '';
     1202
     1203                // Aria selected
     1204                $selected = ( $tab['url'] === $pagenow )
     1205                        ? 'true'
     1206                        : 'false';
     1207
     1208                // Get the URL for this tab
     1209                $url = add_query_arg( array( 'id' => $r['blog_id'] ), network_admin_url( $tab['url'] ) );
     1210
     1211                // Add tab to screen tabs
     1212                $r['screen_tabs'][ $tab_id ] = '<a href="' . esc_url( $url ) . '" class="nav-tab' . esc_attr( $class ) . '" aria-controls="' . sanitize_title( $tab_id ) . '" aria-selected="' . esc_attr( $selected ) . '">' . esc_html( $tab['label'] ) . '</a>';
     1213        }
     1214
     1215        // Start a buffer
     1216        ob_start();
     1217
     1218        // All done!
     1219        echo $r['before'];
     1220        echo implode( '', $r['screen_tabs'] );
     1221        echo $r['after'];
     1222
     1223        // Put out the tabs
     1224        ob_end_flush();
     1225}
  • src/wp-admin/network/site-info.php

    diff --git a/src/wp-admin/network/site-info.php b/src/wp-admin/network/site-info.php
    index b18d804..e9e7b57 100644
    a b  
    1414        wp_die( __( 'Multisite support is not enabled.' ) );
    1515}
    1616
    17 if ( ! current_user_can( 'manage_sites' ) ) {
     17if ( ! current_user_can( 'manage_site_info' ) ) {
    1818        wp_die( __( 'You do not have sufficient permissions to edit this site.' ) );
    1919}
    2020
     
    143143<div class="wrap">
    144144<h1 id="edit-site"><?php echo $title; ?></h1>
    145145<p class="edit-site-actions"><a href="<?php echo esc_url( get_home_url( $id, '/' ) ); ?>"><?php _e( 'Visit' ); ?></a> | <a href="<?php echo esc_url( get_admin_url( $id ) ); ?>"><?php _e( 'Dashboard' ); ?></a></p>
    146 <h2 class="nav-tab-wrapper nav-tab-small wp-clearfix">
    147146<?php
    148 $tabs = array(
    149         'site-info'     => array( 'label' => __( 'Info' ),     'url' => 'site-info.php'     ),
    150         'site-users'    => array( 'label' => __( 'Users' ),    'url' => 'site-users.php'    ),
    151         'site-themes'   => array( 'label' => __( 'Themes' ),   'url' => 'site-themes.php'   ),
    152         'site-settings' => array( 'label' => __( 'Settings' ), 'url' => 'site-settings.php' ),
    153 );
    154 foreach ( $tabs as $tab_id => $tab ) {
    155         $class = ( $tab['url'] == $pagenow ) ? ' nav-tab-active' : '';
    156         echo '<a href="' . $tab['url'] . '?id=' . $id .'" class="nav-tab' . $class . '">' . esc_html( $tab['label'] ) . '</a>';
    157 }
    158 ?>
    159 </h2>
    160 <?php
     147
     148network_edit_site_tabs( array( 'blog_id' => $id ) );
     149
    161150if ( ! empty( $messages ) ) {
    162151        foreach ( $messages as $msg ) {
    163152                echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
  • src/wp-admin/network/site-settings.php

    diff --git a/src/wp-admin/network/site-settings.php b/src/wp-admin/network/site-settings.php
    index b945ea7..86985a4 100644
    a b  
    1313if ( ! is_multisite() )
    1414        wp_die( __( 'Multisite support is not enabled.' ) );
    1515
    16 if ( ! current_user_can( 'manage_sites' ) )
     16if ( ! current_user_can( 'manage_site_settings' ) )
    1717        wp_die( __( 'You do not have sufficient permissions to edit this site.' ) );
    1818
    1919get_current_screen()->add_help_tab( array(
     
    9595<div class="wrap">
    9696<h1 id="edit-site"><?php echo $title; ?></h1>
    9797<p class="edit-site-actions"><a href="<?php echo esc_url( get_home_url( $id, '/' ) ); ?>"><?php _e( 'Visit' ); ?></a> | <a href="<?php echo esc_url( get_admin_url( $id ) ); ?>"><?php _e( 'Dashboard' ); ?></a></p>
    98 <h2 class="nav-tab-wrapper nav-tab-small wp-clearfix">
     98
    9999<?php
    100 $tabs = array(
    101         'site-info'     => array( 'label' => __( 'Info' ),     'url' => 'site-info.php'     ),
    102         'site-users'    => array( 'label' => __( 'Users' ),    'url' => 'site-users.php'    ),
    103         'site-themes'   => array( 'label' => __( 'Themes' ),   'url' => 'site-themes.php'   ),
    104         'site-settings' => array( 'label' => __( 'Settings' ), 'url' => 'site-settings.php' ),
    105 );
    106 foreach ( $tabs as $tab_id => $tab ) {
    107         $class = ( $tab['url'] == $pagenow ) ? ' nav-tab-active' : '';
    108         echo '<a href="' . $tab['url'] . '?id=' . $id .'" class="nav-tab' . $class . '">' . esc_html( $tab['label'] ) . '</a>';
    109 }
    110 ?>
    111 </h2>
    112 <?php
     100
     101network_edit_site_tabs( array( 'blog_id' => $id ) );
     102
    113103if ( ! empty( $messages ) ) {
    114104        foreach ( $messages as $msg )
    115105                echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
  • src/wp-admin/network/site-themes.php

    diff --git a/src/wp-admin/network/site-themes.php b/src/wp-admin/network/site-themes.php
    index d48e2ca..fadea0d 100644
    a b  
    1313if ( ! is_multisite() )
    1414        wp_die( __( 'Multisite support is not enabled.' ) );
    1515
    16 if ( ! current_user_can( 'manage_sites' ) )
     16if ( ! current_user_can( 'manage_site_themes' ) )
    1717        wp_die( __( 'You do not have sufficient permissions to manage themes for this site.' ) );
    1818
    1919get_current_screen()->add_help_tab( array(
     
    149149<div class="wrap">
    150150<h1 id="edit-site"><?php echo $title; ?></h1>
    151151<p class="edit-site-actions"><a href="<?php echo esc_url( get_home_url( $id, '/' ) ); ?>"><?php _e( 'Visit' ); ?></a> | <a href="<?php echo esc_url( get_admin_url( $id ) ); ?>"><?php _e( 'Dashboard' ); ?></a></p>
    152 <h2 class="nav-tab-wrapper nav-tab-small wp-clearfix">
    153152<?php
    154 $tabs = array(
    155         'site-info'     => array( 'label' => __( 'Info' ),     'url' => 'site-info.php'     ),
    156         'site-users'    => array( 'label' => __( 'Users' ),    'url' => 'site-users.php'    ),
    157         'site-themes'   => array( 'label' => __( 'Themes' ),   'url' => 'site-themes.php'   ),
    158         'site-settings' => array( 'label' => __( 'Settings' ), 'url' => 'site-settings.php' ),
    159 );
    160 foreach ( $tabs as $tab_id => $tab ) {
    161         $class = ( $tab['url'] == $pagenow ) ? ' nav-tab-active' : '';
    162         echo '<a href="' . $tab['url'] . '?id=' . $id .'" class="nav-tab' . $class . '">' . esc_html( $tab['label'] ) . '</a>';
    163 }
    164 ?>
    165 </h2><?php
     153
     154network_edit_site_tabs( array( 'blog_id' => $id ) );
    166155
    167156if ( isset( $_GET['enabled'] ) ) {
    168157        $enabled = absint( $_GET['enabled'] );
  • src/wp-admin/network/site-users.php

    diff --git a/src/wp-admin/network/site-users.php b/src/wp-admin/network/site-users.php
    index 77122e8..922528b 100644
    a b  
    1313if ( ! is_multisite() )
    1414        wp_die( __( 'Multisite support is not enabled.' ) );
    1515
    16 if ( ! current_user_can('manage_sites') )
     16if ( ! current_user_can( 'manage_site_users' ) )
    1717        wp_die(__('You do not have sufficient permissions to edit this site.'));
    1818
    1919$wp_list_table = _get_list_table('WP_Users_List_Table');
     
    204204<div class="wrap">
    205205<h1 id="edit-site"><?php echo $title; ?></h1>
    206206<p class="edit-site-actions"><a href="<?php echo esc_url( get_home_url( $id, '/' ) ); ?>"><?php _e( 'Visit' ); ?></a> | <a href="<?php echo esc_url( get_admin_url( $id ) ); ?>"><?php _e( 'Dashboard' ); ?></a></p>
    207 <h2 class="nav-tab-wrapper nav-tab-small wp-clearfix">
    208207<?php
    209 $tabs = array(
    210         'site-info'     => array( 'label' => __( 'Info' ),     'url' => 'site-info.php'     ),
    211         'site-users'    => array( 'label' => __( 'Users' ),    'url' => 'site-users.php'    ),
    212         'site-themes'   => array( 'label' => __( 'Themes' ),   'url' => 'site-themes.php'   ),
    213         'site-settings' => array( 'label' => __( 'Settings' ), 'url' => 'site-settings.php' ),
    214 );
    215 foreach ( $tabs as $tab_id => $tab ) {
    216         $class = ( $tab['url'] == $pagenow ) ? ' nav-tab-active' : '';
    217         echo '<a href="' . $tab['url'] . '?id=' . $id .'" class="nav-tab' . $class . '">' . esc_html( $tab['label'] ) . '</a>';
    218 }
    219 ?>
    220 </h2><?php
     208
     209network_edit_site_tabs( array( 'blog_id' => $id ) );
    221210
    222211if ( isset($_GET['update']) ) :
    223212        switch($_GET['update']) {