Introduce can_edit_site to replace inline checks on whether or not the site_id is for the current Network. See #15716.

git-svn-id: https://develop.svn.wordpress.org/trunk@16764 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Peter Westwood 2010-12-07 14:28:40 +00:00
parent 0485062f5d
commit 9c2a7dc314
6 changed files with 26 additions and 7 deletions

View File

@ -217,11 +217,12 @@ class WP_MS_Users_List_Table extends WP_List_Table {
echo "<td $attributes>"; echo "<td $attributes>";
if ( is_array( $blogs ) ) { if ( is_array( $blogs ) ) {
foreach ( (array) $blogs as $key => $val ) { foreach ( (array) $blogs as $key => $val ) {
if ( $current_site->id != $val->site_id ) continue; if ( !can_edit_site( $val->site_id ) )
continue;
$path = ( $val->path == '/' ) ? '' : $val->path; $path = ( $val->path == '/' ) ? '' : $val->path;
echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . str_replace( '.' . $current_site->domain, '', $val->domain . $path ) . '</a>'; echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . str_replace( '.' . $current_site->domain, '', $val->domain . $path ) . '</a>';
echo ' <small class="row-actions">'; echo ' <small class="row-actions site-' . $val->site_id . '">';
$actions = array(); $actions = array();
$actions['edit'] = '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a>'; $actions['edit'] = '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a>';

View File

@ -721,4 +721,22 @@ function revoke_super_admin( $user_id ) {
} }
return false; return false;
} }
/**
* Whether or not we can edit this site from this page
*
* By default editing of sites is restricted to the Network Admin for that site_id this allows for this to be overridden
*
* @since 3.1.0
* @param integer $site_id The site id to check.
*/
function can_edit_site( $site_id ) {
global $wpdb;
if ($site_id == $wpdb->siteid )
$result = true;
else
$result = false;
return apply_filters( 'can_edit_site', $result, $site_id );
}
?> ?>

View File

@ -22,7 +22,7 @@ if ( ! $id )
wp_die( __('Invalid site ID.') ); wp_die( __('Invalid site ID.') );
$details = get_blog_details( $id ); $details = get_blog_details( $id );
if ( $details->site_id != $wpdb->siteid ) if ( !can_edit_site( $details->site_id ) )
wp_die( __( 'You do not have permission to access this page.' ) ); wp_die( __( 'You do not have permission to access this page.' ) );
$is_main_site = is_main_site( $id ); $is_main_site = is_main_site( $id );

View File

@ -22,7 +22,7 @@ if ( ! $id )
wp_die( __('Invalid site ID.') ); wp_die( __('Invalid site ID.') );
$details = get_blog_details( $id ); $details = get_blog_details( $id );
if ( $details->site_id != $wpdb->siteid ) if ( !can_edit_site( $details->site_id ) )
wp_die( __( 'You do not have permission to access this page.' ) ); wp_die( __( 'You do not have permission to access this page.' ) );
$is_main_site = is_main_site( $id ); $is_main_site = is_main_site( $id );

View File

@ -31,7 +31,7 @@ if ( ! $id )
$wp_list_table->prepare_items(); $wp_list_table->prepare_items();
$details = get_blog_details( $id ); $details = get_blog_details( $id );
if ( $details->site_id != $wpdb->siteid ) if ( !can_edit_site( $details->site_id ) )
wp_die( __( 'You do not have permission to access this page.' ) ); wp_die( __( 'You do not have permission to access this page.' ) );
$is_main_site = is_main_site( $id ); $is_main_site = is_main_site( $id );

View File

@ -28,7 +28,7 @@ if ( ! $id )
wp_die( __('Invalid site ID.') ); wp_die( __('Invalid site ID.') );
$details = get_blog_details( $id ); $details = get_blog_details( $id );
if ( $details->site_id != $wpdb->siteid ) if ( !can_edit_site( $details->site_id ) )
wp_die( __( 'You do not have permission to access this page.' ) ); wp_die( __( 'You do not have permission to access this page.' ) );
$is_main_site = is_main_site( $id ); $is_main_site = is_main_site( $id );