From c5944fedf8e3bd85b0ec16934996560c038e251e Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Thu, 19 May 2016 21:47:06 +0000 Subject: [PATCH] Multisite: Filter the links displayed on "Edit Site" views Introduce the `network_edit_site_nav` function, which DRYs up the code used to display a common set of links at the top of "Edit Site" views. Introduce the `network_edit_site_nav_links` filter, which allows plugins to modify the list of links displayed at the top of Edit Site views as a "tabbed" interface. Props johnjamesjacoby, c3mdigital, Bueltge. Fixes #15800. git-svn-id: https://develop.svn.wordpress.org/trunk@37466 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/ms.php | 81 ++++++++++++++++++++++++++ src/wp-admin/network/site-info.php | 20 ++----- src/wp-admin/network/site-settings.php | 21 +++---- src/wp-admin/network/site-themes.php | 18 ++---- src/wp-admin/network/site-users.php | 18 ++---- 5 files changed, 104 insertions(+), 54 deletions(-) diff --git a/src/wp-admin/includes/ms.php b/src/wp-admin/includes/ms.php index 5464b61526..2c16456e54 100644 --- a/src/wp-admin/includes/ms.php +++ b/src/wp-admin/includes/ms.php @@ -1028,3 +1028,84 @@ jQuery(document).ready( function($) { array( 'label' => __( 'Info' ), 'url' => 'site-info.php', 'cap' => 'manage_sites' ), + 'site-users' => array( 'label' => __( 'Users' ), 'url' => 'site-users.php', 'cap' => 'manage_sites' ), + 'site-themes' => array( 'label' => __( 'Themes' ), 'url' => 'site-themes.php', 'cap' => 'manage_sites' ), + 'site-settings' => array( 'label' => __( 'Settings' ), 'url' => 'site-settings.php', 'cap' => 'manage_sites' ) + ) ); + + // Parse arguments + $r = wp_parse_args( $args, array( + 'blog_id' => isset( $_GET['blog_id'] ) ? (int) $_GET['blog_id'] : 0, + 'links' => $links, + 'selected' => 'site-info', + ) ); + + // Setup the links array + $screen_links = array(); + + // Loop through tabs + foreach ( $r['links'] as $link_id => $link ) { + + // Skip link if user can't access + if ( ! current_user_can( $link['cap'], $r['blog_id'] ) ) { + continue; + } + + // Link classes + $classes = array( 'nav-tab' ); + + // Selected is set by the parent OR assumed by the $pagenow global + if ( $r['selected'] === $link_id || $link['url'] === $GLOBALS['pagenow'] ) { + $classes[] = 'nav-tab-active'; + } + + // Escape each class + $esc_classes = implode( ' ', array_map( 'esc_attr', $classes ) ); + + // Get the URL for this link + $url = add_query_arg( array( 'id' => $r['blog_id'] ), network_admin_url( $link['url'] ) ); + + // Add link to nav links + $screen_links[ $link_id ] = '' . esc_html( $link['label'] ) . ''; + } + + // Start a buffer + ob_start(); + + // All done! + echo ''; + + // Output the nav + echo ob_get_clean(); +} diff --git a/src/wp-admin/network/site-info.php b/src/wp-admin/network/site-info.php index b18d804438..868e88c74c 100644 --- a/src/wp-admin/network/site-info.php +++ b/src/wp-admin/network/site-info.php @@ -143,21 +143,13 @@ require( ABSPATH . 'wp-admin/admin-header.php' );

|

- $id, + 'selected' => 'site-info' +) ); + if ( ! empty( $messages ) ) { foreach ( $messages as $msg ) { echo '

' . $msg . '

'; diff --git a/src/wp-admin/network/site-settings.php b/src/wp-admin/network/site-settings.php index b945ea74a6..a5cdc6d344 100644 --- a/src/wp-admin/network/site-settings.php +++ b/src/wp-admin/network/site-settings.php @@ -95,21 +95,14 @@ require( ABSPATH . 'wp-admin/admin-header.php' );

|

- + $id, + 'selected' => 'site-settings' +) ); + if ( ! empty( $messages ) ) { foreach ( $messages as $msg ) echo '

' . $msg . '

'; diff --git a/src/wp-admin/network/site-themes.php b/src/wp-admin/network/site-themes.php index d48e2ca8d2..6d13fb2f88 100644 --- a/src/wp-admin/network/site-themes.php +++ b/src/wp-admin/network/site-themes.php @@ -149,20 +149,12 @@ require( ABSPATH . 'wp-admin/admin-header.php' ); ?>

|

- $id, + 'selected' => 'site-themes' +) ); if ( isset( $_GET['enabled'] ) ) { $enabled = absint( $_GET['enabled'] ); diff --git a/src/wp-admin/network/site-users.php b/src/wp-admin/network/site-users.php index 77122e82c2..cced8a4b7a 100644 --- a/src/wp-admin/network/site-users.php +++ b/src/wp-admin/network/site-users.php @@ -204,20 +204,12 @@ var current_site_id = ;

|

- $id, + 'selected' => 'site-users' +) ); if ( isset($_GET['update']) ) : switch($_GET['update']) {