From 381a4f7750129eea913b0e384fda57619822a826 Mon Sep 17 00:00:00 2001 From: westi Date: Tue, 7 Dec 2010 14:28:40 +0000 Subject: [PATCH] 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: http://svn.automattic.com/wordpress/trunk@16764 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../includes/class-wp-ms-users-list-table.php | 7 ++++--- wp-admin/includes/ms.php | 18 ++++++++++++++++++ wp-admin/network/site-info.php | 2 +- wp-admin/network/site-options.php | 2 +- wp-admin/network/site-themes.php | 2 +- wp-admin/network/site-users.php | 2 +- 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/wp-admin/includes/class-wp-ms-users-list-table.php b/wp-admin/includes/class-wp-ms-users-list-table.php index 3d0734e083..70c9bad106 100644 --- a/wp-admin/includes/class-wp-ms-users-list-table.php +++ b/wp-admin/includes/class-wp-ms-users-list-table.php @@ -217,11 +217,12 @@ class WP_MS_Users_List_Table extends WP_List_Table { echo ""; if ( is_array( $blogs ) ) { 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 '' . str_replace( '.' . $current_site->domain, '', $val->domain . $path ) . ''; - echo ' '; + echo ' '; $actions = array(); $actions['edit'] = '' . __( 'Edit' ) . ''; diff --git a/wp-admin/includes/ms.php b/wp-admin/includes/ms.php index b72e735f0d..f45a83d31d 100644 --- a/wp-admin/includes/ms.php +++ b/wp-admin/includes/ms.php @@ -721,4 +721,22 @@ function revoke_super_admin( $user_id ) { } 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 ); +} ?> diff --git a/wp-admin/network/site-info.php b/wp-admin/network/site-info.php index 0f0dd47f94..bff04e2bce 100644 --- a/wp-admin/network/site-info.php +++ b/wp-admin/network/site-info.php @@ -22,7 +22,7 @@ if ( ! $id ) wp_die( __('Invalid site 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.' ) ); $is_main_site = is_main_site( $id ); diff --git a/wp-admin/network/site-options.php b/wp-admin/network/site-options.php index ecdb320e3f..31a4796062 100644 --- a/wp-admin/network/site-options.php +++ b/wp-admin/network/site-options.php @@ -22,7 +22,7 @@ if ( ! $id ) wp_die( __('Invalid site 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.' ) ); $is_main_site = is_main_site( $id ); diff --git a/wp-admin/network/site-themes.php b/wp-admin/network/site-themes.php index 5a94da7dfb..6b72e3d6b8 100644 --- a/wp-admin/network/site-themes.php +++ b/wp-admin/network/site-themes.php @@ -31,7 +31,7 @@ if ( ! $id ) $wp_list_table->prepare_items(); $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.' ) ); $is_main_site = is_main_site( $id ); diff --git a/wp-admin/network/site-users.php b/wp-admin/network/site-users.php index fe15095a68..3c3b940fb4 100644 --- a/wp-admin/network/site-users.php +++ b/wp-admin/network/site-users.php @@ -28,7 +28,7 @@ if ( ! $id ) wp_die( __('Invalid site 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.' ) ); $is_main_site = is_main_site( $id );