X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/699231ae09f7057a4d0000cdf32e50a3df6a04ca..5aa86a9053fb0fa15846bb60aac2fb8fdfff524a:/wp-admin/includes/ms.php diff --git a/wp-admin/includes/ms.php b/wp-admin/includes/ms.php index ae23b7f8..1b2c7e78 100644 --- a/wp-admin/includes/ms.php +++ b/wp-admin/includes/ms.php @@ -53,40 +53,42 @@ add_filter( 'wp_handle_upload_prefilter', 'check_upload_size' ); * @return void */ function wpmu_delete_blog( $blog_id, $drop = false ) { - global $wpdb; + global $wpdb, $current_site; $switch = false; if ( $blog_id != $wpdb->blogid ) { $switch = true; switch_to_blog( $blog_id ); + $blog = get_blog_details( $blog_id ); + } else { + $blog = $GLOBALS['current_blog']; } - $blog_prefix = $wpdb->get_blog_prefix( $blog_id ); - do_action( 'delete_blog', $blog_id, $drop ); - $users = get_users_of_blog( $blog_id ); + $users = get_users( array( 'blog_id' => $blog_id, 'fields' => 'ids' ) ); // Remove users from this blog. if ( ! empty( $users ) ) { - foreach ( $users as $user ) { - remove_user_from_blog( $user->user_id, $blog_id) ; + foreach ( $users as $user_id ) { + remove_user_from_blog( $user_id, $blog_id ); } } update_blog_status( $blog_id, 'deleted', 1 ); + // Don't destroy the initial, main, or root blog. + if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->domain ) ) ) + $drop = false; + if ( $drop ) { - if ( substr( $blog_prefix, -1 ) == '_' ) - $blog_prefix = substr( $blog_prefix, 0, -1 ) . '\_'; - $drop_tables = $wpdb->get_results( "SHOW TABLES LIKE '{$blog_prefix}%'", ARRAY_A ); - $drop_tables = apply_filters( 'wpmu_drop_tables', $drop_tables ); + $drop_tables = apply_filters( 'wpmu_drop_tables', $wpdb->tables( 'blog' ) ); - reset( $drop_tables ); - foreach ( (array) $drop_tables as $drop_table) { - $wpdb->query( "DROP TABLE IF EXISTS ". current( $drop_table ) ."" ); + foreach ( (array) $drop_tables as $table ) { + $wpdb->query( "DROP TABLE IF EXISTS `$table`" ); } + $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->blogs WHERE blog_id = %d", $blog_id ) ); $dir = apply_filters( 'wpmu_delete_blog_upload_dir', WP_CONTENT_DIR . "/blogs.dir/{$blog_id}/files/", $blog_id ); $dir = rtrim( $dir, DIRECTORY_SEPARATOR ); @@ -120,17 +122,7 @@ function wpmu_delete_blog( $blog_id, $drop = false ) { } } - $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key = '{$blog_prefix}autosave_draft_ids'" ); - $blogs = get_site_option( 'blog_list' ); - if ( is_array( $blogs ) ) { - foreach ( $blogs as $n => $blog ) { - if ( $blog['blog_id'] == $blog_id ) - unset( $blogs[$n] ); - } - update_site_option( 'blog_list', $blogs ); - } - - if ( $switch === true ) + if ( $switch ) restore_current_blog(); } @@ -177,72 +169,6 @@ function wpmu_delete_user( $id ) { return true; } -function confirm_delete_users( $users ) { - global $current_user; - if ( !is_array( $users ) ) - return false; - - screen_icon(); - ?> -

-

-
- - ID'>$current_user->user_login"; - - foreach ( ( $allusers = (array) $_POST['allusers'] ) as $key => $val ) { - if ( $val != '' && $val != '0' ) { - $delete_user = new WP_User( $val ); - - if ( in_array( $delete_user->user_login, $site_admins ) ) - wp_die( sprintf( __( 'Warning! User cannot be deleted. The user %s is a network admnistrator.' ), $delete_user->user_login ) ); - - echo "\n"; - $blogs = get_blogs_of_user( $val, true ); - - if ( !empty( $blogs ) ) { - ?> -

%s?" ), $delete_user->user_login ); ?>

- $details ) { - $blog_users = get_users_of_blog( $details->userblog_id ); - if ( is_array( $blog_users ) && !empty( $blog_users ) ) { - $user_site = "{$details->blogname}"; - $user_dropdown = "\n"; - ?> - - "; - } - } - } - ?> -

- - id != $_POST['user_id'] ) + if ( $current_user->ID != $_POST['user_id'] ) return false; if ( $current_user->user_email != $_POST['email'] ) { @@ -364,8 +291,7 @@ All at ###SITENAME### add_action( 'personal_options_update', 'send_confirmation_on_profile_email' ); function new_user_email_admin_notice() { - global $current_user; - if ( strpos( $_SERVER['PHP_SELF'], 'profile.php' ) && isset( $_GET['updated'] ) && $email = get_option( $current_user->ID . '_new_email' ) ) + if ( strpos( $_SERVER['PHP_SELF'], 'profile.php' ) && isset( $_GET['updated'] ) && $email = get_option( get_current_user_id() . '_new_email' ) ) echo "
" . sprintf( __( "Your email address has not been updated yet. Please check your inbox at %s for a confirmation email." ), $email['newemail'] ) . "
"; } add_action( 'admin_notices', 'new_user_email_admin_notice' ); @@ -406,13 +332,16 @@ function is_upload_space_available() { return true; } -/* +/** * @since 3.0.0 * * @return int of upload size limit in bytes */ function upload_size_limit_filter( $size ) { $fileupload_maxk = 1024 * get_site_option( 'fileupload_maxk', 1500 ); + if ( get_site_option( 'upload_space_check_disabled' ) ) + return min( $size, $fileupload_maxk ); + return min( $size, $fileupload_maxk, get_upload_space_available() ); } /** @@ -456,7 +385,7 @@ function get_upload_space_available() { */ function get_space_allowed() { $space_allowed = get_option( 'blog_upload_space' ); - if ( $space_allowed == false ) + if ( $space_allowed === false ) $space_allowed = get_site_option( 'blog_upload_space' ); if ( empty( $space_allowed ) || !is_numeric( $space_allowed ) ) $space_allowed = 50; @@ -483,46 +412,6 @@ function display_space_usage() { $quota ) - $percentused = '100'; - else - $percentused = ( $used / $quota ) * 100; - $used_color = ( $percentused < 70 ) ? ( ( $percentused >= 40 ) ? 'waiting' : 'approved' ) : 'spam'; - $used = round( $used, 2 ); - $percentused = number_format( $percentused ); - - ?> -

-
- - - - - -
%2$sMB' ), esc_url( admin_url( 'upload.php' ) ), $quota ); ?>
-
-
- - - - - -
%2$sMB (%3$s%%)' ), esc_url( admin_url( 'upload.php' ) ), $used, $percentused ); ?>
-
-
- update( $wpdb->users, array( $pref => $value ), array( 'ID' => $id ) ); - if ( $refresh == 1 ) - refresh_user_details( $id ); + clean_user_cache( $id ); if ( $pref == 'spam' ) { if ( $value == 1 ) @@ -597,44 +488,41 @@ function sync_category_tag_slugs( $term, $taxonomy ) { } add_filter( 'get_term', 'sync_category_tag_slugs', 10, 2 ); -function redirect_user_to_blog() { - global $current_user; - $c = 0; - if ( isset( $_GET['c'] ) ) - $c = (int) $_GET['c']; +function _access_denied_splash() { + if ( ! is_user_logged_in() || is_network_admin() ) + return; - if ( $c >= 5 ) { - wp_die( __( "You don’t have permission to view this site. Please contact the system administrator." ) ); - } - $c ++; + $blogs = get_blogs_of_user( get_current_user_id() ); - $blog = get_active_blog_for_user( $current_user->ID ); - $dashboard_blog = get_dashboard_blog(); - if ( is_object( $blog ) ) { - wp_redirect( get_admin_url( $blog->blog_id, '?c=' . $c ) ); // redirect and count to 5, "just in case" - exit; - } + if ( wp_list_filter( $blogs, array( 'userblog_id' => get_current_blog_id() ) ) ) + return; - /* - If the user is a member of only 1 blog and the user's primary_blog isn't set to that blog, - then update the primary_blog record to match the user's blog - */ - $blogs = get_blogs_of_user( $current_user->ID ); - - if ( !empty( $blogs ) ) { - foreach( $blogs as $blogid => $blog ) { - if ( $blogid != $dashboard_blog->blog_id && get_user_meta( $current_user->ID , 'primary_blog', true ) == $dashboard_blog->blog_id ) { - update_user_meta( $current_user->ID, 'primary_blog', $blogid ); - continue; - } - } - $blog = get_blog_details( get_user_meta( $current_user->ID, 'primary_blog', true ) ); - wp_redirect( get_admin_url( $blog->blog_id, '?c=' . $c ) ); - exit; + $blog_name = get_bloginfo( 'name' ); + + if ( empty( $blogs ) ) + wp_die( sprintf( __( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ), $blog_name ) ); + + $output = '

' . sprintf( __( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ), $blog_name ) . '

'; + $output .= '

' . __( 'If you reached this screen by accident and meant to visit one of your own sites, here are some shortcuts to help you find your way.' ) . '

'; + + $output .= '

' . __('Your Sites') . '

'; + $output .= ''; + + foreach ( $blogs as $blog ) { + $output .= ""; + $output .= ""; + $output .= ""; + $output .= ""; } - wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); + $output .= '
"; + $output .= "{$blog->blogname}"; + $output .= ""; + $output .= "" . __( 'Visit Dashboard' ) . " | " . __( 'View Site' ) . "" ; + $output .= "
'; + + wp_die( $output ); } -add_action( 'admin_page_access_denied', 'redirect_user_to_blog', 99 ); +add_action( 'admin_page_access_denied', '_access_denied_splash', 99 ); function check_import_new_users( $permission ) { if ( !is_super_admin() ) @@ -654,20 +542,20 @@ function mu_dropdown_languages( $lang_files = array(), $current = '' ) { if ( $code_lang == 'en_US' ) { // American English $flag = true; $ae = __( 'American English' ); - $output[$ae] = ''; + $output[$ae] = ''; } elseif ( $code_lang == 'en_GB' ) { // British English $flag = true; $be = __( 'British English' ); - $output[$be] = ''; + $output[$be] = ''; } else { $translated = format_code_lang( $code_lang ); - $output[$translated] = ''; + $output[$translated] = ''; } } if ( $flag === false ) // WordPress english - $output[] = '"; + $output[] = '"; // Order by name uksort( $output, 'strnatcasecmp' ); @@ -694,47 +582,17 @@ function secret_salt_warning() { echo "
$msg
"; } } -add_action( 'admin_notices', 'secret_salt_warning' ); - -function admin_notice_feed() { - global $current_user, $current_screen; - if ( $current_screen->id != 'dashboard' ) - return; - - if ( !empty( $_GET['feed_dismiss'] ) ) { - update_user_option( $current_user->id, 'admin_feed_dismiss', $_GET['feed_dismiss'], true ); - return; - } - - $url = get_site_option( 'admin_notice_feed' ); - if ( empty( $url ) ) - return; - - $rss = fetch_feed( $url ); - if ( ! is_wp_error( $rss ) && $item = $rss->get_item() ) { - $title = $item->get_title(); - if ( md5( $title ) == get_user_option( 'admin_feed_dismiss' ) ) - return; - $msg = "

" . esc_html( $title ) . "

\n"; - $content = $item->get_description(); - $content = $content ? wp_html_excerpt( $content, 200 ) . ' … ' : ''; - $link = esc_url( strip_tags( $item->get_link() ) ); - $msg .= "

" . $content . "" . __( 'Read More' ) . " " . __( 'Dismiss' ) . "

"; - echo "
$msg
"; - } elseif ( is_super_admin() ) { - printf( '
' . __( 'Your feed at %s is empty.' ) . '
', esc_html( $url ) ); - } -} -add_action( 'admin_notices', 'admin_notice_feed' ); +add_action( 'network_admin_notices', 'secret_salt_warning' ); function site_admin_notice() { - global $current_user, $wp_db_version; + global $wp_db_version; if ( !is_super_admin() ) return false; if ( get_site_option( 'wpmu_upgrade_site' ) != $wp_db_version ) - echo "
" . sprintf( __( 'Thank you for Updating! Please visit the Update Network page to update all your sites.' ), esc_url( admin_url( 'ms-upgrade-network.php' ) ) ) . "
"; + echo "
" . sprintf( __( 'Thank you for Updating! Please visit the Update Network page to update all your sites.' ), esc_url( network_admin_url( 'upgrade.php' ) ) ) . "
"; } add_action( 'admin_notices', 'site_admin_notice' ); +add_action( 'network_admin_notices', 'site_admin_notice' ); function avoid_blog_page_permalink_collision( $data, $postarr ) { if ( is_subdomain_install() ) @@ -760,7 +618,6 @@ function avoid_blog_page_permalink_collision( $data, $postarr ) { add_filter( 'wp_insert_post_data', 'avoid_blog_page_permalink_collision', 10, 2 ); function choose_primary_blog() { - global $current_user; ?> @@ -768,8 +625,8 @@ function choose_primary_blog() {
ID ); - $primary_blog = get_user_meta( $current_user->ID, 'primary_blog', true ); + $all_blogs = get_blogs_of_user( get_current_user_id() ); + $primary_blog = get_user_meta( get_current_user_id(), 'primary_blog', true ); if ( count( $all_blogs ) > 1 ) { $found = false; ?> @@ -783,13 +640,13 @@ function choose_primary_blog() { ID, 'primary_blog', $blog->userblog_id ); + update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id ); } } elseif ( count( $all_blogs ) == 1 ) { $blog = array_shift( $all_blogs ); echo $blog->domain; if ( $primary_blog != $blog->userblog_id ) // Set the primary blog again if it's out of sync with blog list. - update_user_meta( $current_user->ID, 'primary_blog', $blog->userblog_id ); + update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id ); } else { echo "N/A"; } @@ -807,16 +664,6 @@ function choose_primary_blog() { " . sprintf( __( "Warning! The current theme supports Featured Images. You must enable image uploads on the options page for it to work." ), esc_url( admin_url( 'ms-options.php' ) ) ) . ""; - } -} -add_action( 'admin_notices', 'show_post_thumbnail_warning' ); - function ms_deprecated_blogs_file() { if ( ! is_super_admin() ) return; @@ -824,24 +671,13 @@ function ms_deprecated_blogs_file() { return; echo '
' . sprintf( __( 'The %1$s file is deprecated. Please remove it and update your server rewrite rules to use %2$s instead.' ), 'wp-content/blogs.php', 'wp-includes/ms-files.php' ) . '
'; } -add_action( 'admin_notices', 'ms_deprecated_blogs_file' ); - -/** - * Outputs the notice message for multisite regarding activation of plugin page. - * - * @since 3.0.0 - * @return none - */ -function _admin_notice_multisite_activate_plugins_page() { - $message = sprintf( __( 'The plugins page is not visible to normal users. It must be activated first. %s' ), '' . __( 'Activate' ) . '' ); - echo "

$message

"; -} +add_action( 'network_admin_notices', 'ms_deprecated_blogs_file' ); /** * Grants super admin privileges. * * @since 3.0.0 - * @param $user_id + * @param int $user_id */ function grant_super_admin( $user_id ) { global $super_admins; @@ -869,7 +705,7 @@ function grant_super_admin( $user_id ) { * Revokes super admin privileges. * * @since 3.0.0 - * @param $user_id + * @param int $user_id */ function revoke_super_admin( $user_id ) { global $super_admins; @@ -894,4 +730,60 @@ function revoke_super_admin( $user_id ) { } return false; } + +/** + * Whether or not we can edit this network from this page + * + * By default editing of network 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 network/site id to check. + */ +function can_edit_network( $site_id ) { + global $wpdb; + + if ($site_id == $wpdb->siteid ) + $result = true; + else + $result = false; + + return apply_filters( 'can_edit_network', $result, $site_id ); +} + +/** + * Thickbox image paths for Network Admin. + * + * @since 3.1.0 + * @access private + */ +function _thickbox_path_admin_subfolder() { +?> + + 10000, 'users', $count ); + } + + $count = get_blog_count(); + return apply_filters( 'wp_is_large_network', $count > 10000, 'sites', $count ); +} ?>