Make WordPress Core


Ignore:
Timestamp:
05/19/2016 09:47:06 PM (10 years ago)
Author:
jeremyfelt
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ms.php

    r37342 r37466  
    10291029<?php
    10301030}
     1031
     1032/**
     1033 * Outputs the HTML for a network's "Edit Site" tabular interface
     1034 *
     1035 * @since 4.6.0
     1036 *
     1037 * @link https://core.trac.wordpress.org/ticket/15800 discussion
     1038 *
     1039 * @param $args {
     1040 *     Optional. Array or string of Query parameters.
     1041 *
     1042 *     @type int     $blog_id   The site ID. Default is the current site.
     1043 *     @type array   $links     The tabs to include with (label|url|cap) keys
     1044 *     @type string  $selected  The ID of the selected link
     1045 * }
     1046 */
     1047function network_edit_site_nav( $args = array() ) {
     1048
     1049        /**
     1050         * Filter the links that appear on site-editing network pages
     1051         *
     1052         * Default links: 'site-info', 'site-users', 'site-themes', and 'site-settings'
     1053         *
     1054         * @since 4.6.0
     1055         *
     1056         * @param array Array of link data.
     1057         */
     1058        $links = apply_filters( 'network_edit_site_nav_links', array(
     1059                'site-info'     => array( 'label' => __( 'Info' ),     'url' => 'site-info.php',     'cap' => 'manage_sites' ),
     1060                'site-users'    => array( 'label' => __( 'Users' ),    'url' => 'site-users.php',    'cap' => 'manage_sites' ),
     1061                'site-themes'   => array( 'label' => __( 'Themes' ),   'url' => 'site-themes.php',   'cap' => 'manage_sites' ),
     1062                'site-settings' => array( 'label' => __( 'Settings' ), 'url' => 'site-settings.php', 'cap' => 'manage_sites' )
     1063        ) );
     1064
     1065        // Parse arguments
     1066        $r = wp_parse_args( $args, array(
     1067                'blog_id'  => isset( $_GET['blog_id'] ) ? (int) $_GET['blog_id'] : 0,
     1068                'links'    => $links,
     1069                'selected' => 'site-info',
     1070        ) );
     1071
     1072        // Setup the links array
     1073        $screen_links = array();
     1074
     1075        // Loop through tabs
     1076        foreach ( $r['links'] as $link_id => $link ) {
     1077
     1078                // Skip link if user can't access
     1079                if ( ! current_user_can( $link['cap'], $r['blog_id'] ) ) {
     1080                        continue;
     1081                }
     1082
     1083                // Link classes
     1084                $classes = array( 'nav-tab' );
     1085
     1086                // Selected is set by the parent OR assumed by the $pagenow global
     1087                if ( $r['selected'] === $link_id || $link['url'] === $GLOBALS['pagenow'] ) {
     1088                        $classes[] = 'nav-tab-active';
     1089                }
     1090
     1091                // Escape each class
     1092                $esc_classes = implode( ' ', array_map( 'esc_attr', $classes ) );
     1093
     1094                // Get the URL for this link
     1095                $url = add_query_arg( array( 'id' => $r['blog_id'] ), network_admin_url( $link['url'] ) );
     1096
     1097                // Add link to nav links
     1098                $screen_links[ $link_id ] = '<a href="' . esc_url( $url ) . '" id="' . esc_attr( $link_id ) . '" class="' . $esc_classes . '">' . esc_html( $link['label'] ) . '</a>';
     1099        }
     1100
     1101        // Start a buffer
     1102        ob_start();
     1103
     1104        // All done!
     1105        echo '<h2 class="nav-tab-wrapper wp-clearfix">';
     1106        echo implode( '', $screen_links );
     1107        echo '</h2>';
     1108
     1109        // Output the nav
     1110        echo ob_get_clean();
     1111}
Note: See TracChangeset for help on using the changeset viewer.