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
This commit is contained in:
Jeremy Felt
2016-05-19 21:47:06 +00:00
parent 63755028e8
commit c5944fedf8
5 changed files with 104 additions and 54 deletions
+81
View File
@@ -1028,3 +1028,84 @@ jQuery(document).ready( function($) {
</script>
<?php
}
/**
* Outputs the HTML for a network's "Edit Site" tabular interface
*
* @since 4.6.0
*
* @link https://core.trac.wordpress.org/ticket/15800 discussion
*
* @param $args {
* Optional. Array or string of Query parameters.
*
* @type int $blog_id The site ID. Default is the current site.
* @type array $links The tabs to include with (label|url|cap) keys
* @type string $selected The ID of the selected link
* }
*/
function network_edit_site_nav( $args = array() ) {
/**
* Filter the links that appear on site-editing network pages
*
* Default links: 'site-info', 'site-users', 'site-themes', and 'site-settings'
*
* @since 4.6.0
*
* @param array Array of link data.
*/
$links = apply_filters( 'network_edit_site_nav_links', array(
'site-info' => 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 ] = '<a href="' . esc_url( $url ) . '" id="' . esc_attr( $link_id ) . '" class="' . $esc_classes . '">' . esc_html( $link['label'] ) . '</a>';
}
// Start a buffer
ob_start();
// All done!
echo '<h2 class="nav-tab-wrapper wp-clearfix">';
echo implode( '', $screen_links );
echo '</h2>';
// Output the nav
echo ob_get_clean();
}