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:
parent
63755028e8
commit
c5944fedf8
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -143,21 +143,13 @@ require( ABSPATH . 'wp-admin/admin-header.php' );
|
|||
<div class="wrap">
|
||||
<h1 id="edit-site"><?php echo $title; ?></h1>
|
||||
<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>
|
||||
<h2 class="nav-tab-wrapper nav-tab-small wp-clearfix">
|
||||
<?php
|
||||
$tabs = array(
|
||||
'site-info' => array( 'label' => __( 'Info' ), 'url' => 'site-info.php' ),
|
||||
'site-users' => array( 'label' => __( 'Users' ), 'url' => 'site-users.php' ),
|
||||
'site-themes' => array( 'label' => __( 'Themes' ), 'url' => 'site-themes.php' ),
|
||||
'site-settings' => array( 'label' => __( 'Settings' ), 'url' => 'site-settings.php' ),
|
||||
);
|
||||
foreach ( $tabs as $tab_id => $tab ) {
|
||||
$class = ( $tab['url'] == $pagenow ) ? ' nav-tab-active' : '';
|
||||
echo '<a href="' . $tab['url'] . '?id=' . $id .'" class="nav-tab' . $class . '">' . esc_html( $tab['label'] ) . '</a>';
|
||||
}
|
||||
?>
|
||||
</h2>
|
||||
<?php
|
||||
|
||||
network_edit_site_nav( array(
|
||||
'blog_id' => $id,
|
||||
'selected' => 'site-info'
|
||||
) );
|
||||
|
||||
if ( ! empty( $messages ) ) {
|
||||
foreach ( $messages as $msg ) {
|
||||
echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
|
||||
|
|
|
@ -95,21 +95,14 @@ require( ABSPATH . 'wp-admin/admin-header.php' );
|
|||
<div class="wrap">
|
||||
<h1 id="edit-site"><?php echo $title; ?></h1>
|
||||
<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>
|
||||
<h2 class="nav-tab-wrapper nav-tab-small wp-clearfix">
|
||||
<?php
|
||||
$tabs = array(
|
||||
'site-info' => array( 'label' => __( 'Info' ), 'url' => 'site-info.php' ),
|
||||
'site-users' => array( 'label' => __( 'Users' ), 'url' => 'site-users.php' ),
|
||||
'site-themes' => array( 'label' => __( 'Themes' ), 'url' => 'site-themes.php' ),
|
||||
'site-settings' => array( 'label' => __( 'Settings' ), 'url' => 'site-settings.php' ),
|
||||
);
|
||||
foreach ( $tabs as $tab_id => $tab ) {
|
||||
$class = ( $tab['url'] == $pagenow ) ? ' nav-tab-active' : '';
|
||||
echo '<a href="' . $tab['url'] . '?id=' . $id .'" class="nav-tab' . $class . '">' . esc_html( $tab['label'] ) . '</a>';
|
||||
}
|
||||
?>
|
||||
</h2>
|
||||
|
||||
<?php
|
||||
|
||||
network_edit_site_nav( array(
|
||||
'blog_id' => $id,
|
||||
'selected' => 'site-settings'
|
||||
) );
|
||||
|
||||
if ( ! empty( $messages ) ) {
|
||||
foreach ( $messages as $msg )
|
||||
echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
|
||||
|
|
|
@ -149,20 +149,12 @@ require( ABSPATH . 'wp-admin/admin-header.php' ); ?>
|
|||
<div class="wrap">
|
||||
<h1 id="edit-site"><?php echo $title; ?></h1>
|
||||
<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>
|
||||
<h2 class="nav-tab-wrapper nav-tab-small wp-clearfix">
|
||||
<?php
|
||||
$tabs = array(
|
||||
'site-info' => array( 'label' => __( 'Info' ), 'url' => 'site-info.php' ),
|
||||
'site-users' => array( 'label' => __( 'Users' ), 'url' => 'site-users.php' ),
|
||||
'site-themes' => array( 'label' => __( 'Themes' ), 'url' => 'site-themes.php' ),
|
||||
'site-settings' => array( 'label' => __( 'Settings' ), 'url' => 'site-settings.php' ),
|
||||
);
|
||||
foreach ( $tabs as $tab_id => $tab ) {
|
||||
$class = ( $tab['url'] == $pagenow ) ? ' nav-tab-active' : '';
|
||||
echo '<a href="' . $tab['url'] . '?id=' . $id .'" class="nav-tab' . $class . '">' . esc_html( $tab['label'] ) . '</a>';
|
||||
}
|
||||
?>
|
||||
</h2><?php
|
||||
|
||||
network_edit_site_nav( array(
|
||||
'blog_id' => $id,
|
||||
'selected' => 'site-themes'
|
||||
) );
|
||||
|
||||
if ( isset( $_GET['enabled'] ) ) {
|
||||
$enabled = absint( $_GET['enabled'] );
|
||||
|
|
|
@ -204,20 +204,12 @@ var current_site_id = <?php echo $id; ?>;
|
|||
<div class="wrap">
|
||||
<h1 id="edit-site"><?php echo $title; ?></h1>
|
||||
<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>
|
||||
<h2 class="nav-tab-wrapper nav-tab-small wp-clearfix">
|
||||
<?php
|
||||
$tabs = array(
|
||||
'site-info' => array( 'label' => __( 'Info' ), 'url' => 'site-info.php' ),
|
||||
'site-users' => array( 'label' => __( 'Users' ), 'url' => 'site-users.php' ),
|
||||
'site-themes' => array( 'label' => __( 'Themes' ), 'url' => 'site-themes.php' ),
|
||||
'site-settings' => array( 'label' => __( 'Settings' ), 'url' => 'site-settings.php' ),
|
||||
);
|
||||
foreach ( $tabs as $tab_id => $tab ) {
|
||||
$class = ( $tab['url'] == $pagenow ) ? ' nav-tab-active' : '';
|
||||
echo '<a href="' . $tab['url'] . '?id=' . $id .'" class="nav-tab' . $class . '">' . esc_html( $tab['label'] ) . '</a>';
|
||||
}
|
||||
?>
|
||||
</h2><?php
|
||||
|
||||
network_edit_site_nav( array(
|
||||
'blog_id' => $id,
|
||||
'selected' => 'site-users'
|
||||
) );
|
||||
|
||||
if ( isset($_GET['update']) ) :
|
||||
switch($_GET['update']) {
|
||||
|
|
Loading…
Reference in New Issue