Make WordPress Core

Ticket #15800: 15800.3.patch

File 15800.3.patch, 10.2 KB (added by johnjamesjacoby, 9 years ago)

Add selected argument, and pass from each core file. This makes it easier for custom pages to target and render what tab is "active" without needing to guess at globals or callback hooks.

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

    diff --git a/src/wp-admin/includes/ms.php b/src/wp-admin/includes/ms.php
    index 6e8fb07..983dba5 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
     1147        /**
     1148         * Filter the tabs that appear on site-editing network pages
     1149         *
     1150         * Default tabs: 'site-info', 'site-users', 'site-themes', and 'site-settings'
     1151         *
     1152         * @since 4.6.0
     1153         *
     1154         * @param array         $search_columns Array of column names to be searched.
     1155         * @param string        $search         Text being searched.
     1156         * @param WP_User_Query $this           The current WP_User_Query instance.
     1157         */
     1158        $tabs = apply_filters( 'network_edit_site_tabs', array(
     1159                'site-info'     => array( 'label' => __( 'Info' ),     'url' => 'site-info.php',     'cap' => 'manage_site_info'     ),
     1160                'site-users'    => array( 'label' => __( 'Users' ),    'url' => 'site-users.php',    'cap' => 'manage_site_users'    ),
     1161                'site-themes'   => array( 'label' => __( 'Themes' ),   'url' => 'site-themes.php',   'cap' => 'manage_site_themes'   ),
     1162                'site-settings' => array( 'label' => __( 'Settings' ), 'url' => 'site-settings.php', 'cap' => 'manage_site_settings' )
     1163        ) );
     1164
     1165        // Parse arguments
     1166        $r = wp_parse_args( $args, array(
     1167                'blog_id'     => 0,
     1168                'before'      => '<h2 class="nav-tab-wrapper wp-clearfix" role="tablist">',
     1169                'after'       => '</h2>',
     1170                'tabs'        => $tabs,
     1171                'selected'    => 'site-info',
     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                // Tab class and aria selected values
     1199                $class    = '';
     1200                $selected = 'false';
     1201                if ( ( $r['selected'] === $tab_id ) || ( $tab['url'] === $GLOBALS['pagenow'] ) ) {
     1202                        $class    = ' nav-tab-active';
     1203                        $selected = 'true';
     1204                }
     1205
     1206                // Get the URL for this tab
     1207                $url = add_query_arg( array( 'id' => $r['blog_id'] ), network_admin_url( $tab['url'] ) );
     1208
     1209                // Add tab to screen tabs
     1210                $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>';
     1211        }
     1212
     1213        // Start a buffer
     1214        ob_start();
     1215
     1216        // All done!
     1217        echo $r['before'];
     1218        echo implode( '', $r['screen_tabs'] );
     1219        echo $r['after'];
     1220
     1221        // Put out the tabs
     1222        ob_end_flush();
     1223}
  • 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..bce5048 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(
     149        'blog_id'  => $id,
     150        'selected' => 'site-info'
     151) );
     152
    161153if ( ! empty( $messages ) ) {
    162154        foreach ( $messages as $msg ) {
    163155                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..f7fbf7f 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(
     102        'blog_id'  => $id,
     103        'selected' => 'site-settings'
     104) );
     105
    113106if ( ! empty( $messages ) ) {
    114107        foreach ( $messages as $msg )
    115108                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..e04880f 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(
     155        'blog_id'  => $id,
     156        'selected' => 'site-themes'
     157) );
    166158
    167159if ( isset( $_GET['enabled'] ) ) {
    168160        $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..da28ec1 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(
     210        'blog_id'  => $id,
     211        'selected' => 'site-users'
     212) );
    221213
    222214if ( isset($_GET['update']) ) :
    223215        switch($_GET['update']) {