X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/256a3b381f63716209b3527d0a14442ae570c283..7f1521bf193b382565eb753043c161f4cb3fcda7:/wp-includes/ms-functions.php diff --git a/wp-includes/ms-functions.php b/wp-includes/ms-functions.php index b7b4b6af..6dbcf086 100644 --- a/wp-includes/ms-functions.php +++ b/wp-includes/ms-functions.php @@ -11,8 +11,6 @@ * Gets the network's site and user counts. * * @since MU 1.0 - * @uses get_blog_count() - * @uses get_user_count() * * @return array Site and user count for the network. */ @@ -58,9 +56,6 @@ function get_admin_users_for_domain( $sitedomain = '', $path = '' ) { * is returned. * * @since MU 1.0 - * @uses get_blogs_of_user() - * @uses add_user_to_blog() - * @uses get_blog_details() * * @param int $user_id The unique ID of the user * @return object The blog object @@ -275,8 +270,18 @@ function remove_user_from_blog($user_id, $blog_id = '', $reassign = '') { if ( $reassign != '' ) { $reassign = (int) $reassign; - $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_author = %d WHERE post_author = %d", $reassign, $user_id) ); - $wpdb->query( $wpdb->prepare("UPDATE $wpdb->links SET link_owner = %d WHERE link_owner = %d", $reassign, $user_id) ); + $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $user_id ) ); + $link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $user_id ) ); + + if ( ! empty( $post_ids ) ) { + $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_author = %d WHERE post_author = %d", $reassign, $user_id ) ); + array_walk( $post_ids, 'clean_post_cache' ); + } + + if ( ! empty( $link_ids ) ) { + $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->links SET link_owner = %d WHERE link_owner = %d", $reassign, $user_id ) ); + array_walk( $link_ids, 'clean_bookmark_cache' ); + } } restore_current_blog(); @@ -288,7 +293,6 @@ function remove_user_from_blog($user_id, $blog_id = '', $reassign = '') { * Create an empty blog. * * @since MU 1.0 - * @uses install_blog() * * @param string $domain The new blog's domain. * @param string $path The new blog's path. @@ -430,26 +434,20 @@ function is_email_address_unsafe( $user_email ) { } /** - * Processes new user registrations. + * Sanitize and validate data required for a user sign-up. * - * Checks the data provided by the user during signup. Verifies - * the validity and uniqueness of user names and user email addresses, - * and checks email addresses against admin-provided domain - * whitelists and blacklists. + * Verifies the validity and uniqueness of user names and user email addresses, + * and checks email addresses against admin-provided domain whitelists and blacklists. * - * The hook 'wpmu_validate_user_signup' provides an easy way - * to modify the signup process. The value $result, which is passed - * to the hook, contains both the user-provided info and the error - * messages created by the function. 'wpmu_validate_user_signup' allows - * you to process the data in any way you'd like, and unset the - * relevant errors if necessary. + * The {@see 'wpmu_validate_user_signup'} hook provides an easy way to modify the sign-up + * process. The value $result, which is passed to the hook, contains both the user-provided + * info and the error messages created by the function. {@see 'wpmu_validate_user_signup'} + * allows you to process the data in any way you'd like, and unset the relevant errors if + * necessary. * * @since MU - * @uses is_email_address_unsafe() - * @uses username_exists() - * @uses email_exists() * - * @param string $user_name The login name provided by the user. + * @param string $user_name The login name provided by the user. * @param string $user_email The email provided by the user. * @return array Contains username, email, and error messages. */ @@ -570,8 +568,6 @@ function wpmu_validate_user_signup($user_name, $user_email) { * the way that WordPress validates new site signups. * * @since MU - * @uses domain_exists() - * @uses username_exists() * * @param string $blogname The blog name provided by the user. Must be unique. * @param string $blog_title The blog title provided by the user. @@ -703,7 +699,6 @@ function wpmu_validate_blog_signup( $blogname, $blog_title, $user = '' ) { * Record site signup information for future activation. * * @since MU - * @uses wpmu_signup_blog_notification() * * @param string $domain The requested domain. * @param string $path The requested path. @@ -739,7 +734,6 @@ function wpmu_signup_blog( $domain, $path, $title, $user, $user_email, $meta = a * new site registration is not. * * @since MU - * @uses wpmu_signup_user_notification() * * @param string $user The user's requested login name. * @param string $user_email The user's email address. @@ -870,7 +864,7 @@ function wpmu_signup_blog_notification( $domain, $path, $title, $user, $user_ema $from_name, esc_url( 'http://' . $domain . $path ) ); - wp_mail($user_email, $subject, $message, $message_headers); + wp_mail( $user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); return true; } @@ -955,7 +949,7 @@ function wpmu_signup_user_notification( $user, $user_email, $key, $meta = array( $from_name, $user ); - wp_mail($user_email, $subject, $message, $message_headers); + wp_mail( $user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); return true; } @@ -968,12 +962,6 @@ function wpmu_signup_user_notification( $user, $user_email, $key, $meta = array( * by a Super Admin). * * @since MU - * @uses wp_generate_password() - * @uses wpmu_welcome_user_notification() - * @uses add_user_to_blog() - * @uses wpmu_create_user() - * @uses wpmu_create_blog() - * @uses wpmu_welcome_notification() * * @param string $key The activation key provided to the user. * @return array An array containing information about the activated user and/or blog @@ -1068,12 +1056,11 @@ function wpmu_activate_signup($key) { * use 'user_register'). * * @since MU - * @uses wp_create_user() * * @param string $user_name The new user's login name. * @param string $password The new user's password. * @param string $email The new user's email address. - * @return mixed Returns false on failure, or int $user_id on success + * @return int|bool Returns false on failure, or int $user_id on success */ function wpmu_create_user( $user_name, $password, $email ) { $user_name = preg_replace( '/\s+/', '', sanitize_user( $user_name, true ) ); @@ -1111,10 +1098,6 @@ function wpmu_create_user( $user_name, $password, $email ) { * root domain (eg 'blog1.example.com'), and $path is '/'. * * @since MU - * @uses domain_exists() - * @uses insert_blog() - * @uses wp_install_defaults() - * @uses add_user_to_blog() * * @param string $domain The new site's domain. * @param string $path The new site's path. @@ -1238,7 +1221,6 @@ Disable these notifications: %4$s' ), $blogname, $siteurl, wp_unslash( $_SERVER[ * the notification email. * * @since MU - * @uses apply_filters() Filter newuser_notify_siteadmin to change the content of the email message * * @param int $user_id The new user's ID. * @return bool @@ -1289,7 +1271,9 @@ Disable these notifications: %3$s'), $user->user_login, wp_unslash( $_SERVER['RE */ function domain_exists($domain, $path, $site_id = 1) { global $wpdb; + $path = trailingslashit( $path ); $result = $wpdb->get_var( $wpdb->prepare("SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s AND site_id = %d", $domain, $path, $site_id) ); + /** * Filter whether a blogname is taken. * @@ -1342,8 +1326,6 @@ function insert_blog($domain, $path, $site_id) { * points to the new blog. * * @since MU - * @uses make_db_current_silent() - * @uses populate_roles() * * @param int $blog_id The value returned by insert_blog(). * @param string $blog_title The title of the new site. @@ -1367,7 +1349,9 @@ function install_blog( $blog_id, $blog_title = '' ) { make_db_current_silent( 'blog' ); populate_options(); populate_roles(); - $wp_roles->_init(); + + // populate_roles() clears previous role definitions so we start over. + $wp_roles = new WP_Roles(); $url = untrailingslashit( $url ); @@ -1396,7 +1380,6 @@ function install_blog( $blog_id, $blog_title = '' ) { * @since MU * @deprecated MU * @deprecated Use wp_install_defaults() - * @uses wp_install_defaults() * * @param int $blog_id Ignored in this function. * @param int $user_id @@ -1451,12 +1434,13 @@ function wpmu_welcome_notification( $blog_id, $user_id, $password, $title, $meta $welcome_email = get_site_option( 'welcome_email' ); if ( $welcome_email == false ) - $welcome_email = __( 'Dear User, + $welcome_email = __( 'Howdy USERNAME, Your new SITE_NAME site has been successfully set up at: BLOG_URL You can log in to the administrator account with the following information: + Username: USERNAME Password: PASSWORD Log in here: BLOG_URLwp-login.php @@ -1509,7 +1493,7 @@ We hope you enjoy your new site. Thanks! * @param string $subject Subject of the email. */ $subject = apply_filters( 'update_welcome_subject', sprintf( __( 'New %1$s Site: %2$s' ), $current_site->site_name, wp_unslash( $title ) ) ); - wp_mail($user->user_email, $subject, $message, $message_headers); + wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); return true; } @@ -1587,7 +1571,7 @@ function wpmu_welcome_user_notification( $user_id, $password, $meta = array() ) * @param string $subject Subject of the email. */ $subject = apply_filters( 'update_welcome_user_subject', sprintf( __( 'New %1$s User: %2$s' ), $current_site->site_name, $user->user_login) ); - wp_mail($user->user_email, $subject, $message, $message_headers); + wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); return true; } @@ -1615,7 +1599,6 @@ function get_current_site() { * the most recent post_date_gmt. * * @since MU - * @uses get_blogs_of_user() * * @param int $user_id * @return array Contains the blog_id, post_id, post_date_gmt, and post_gmt_ts @@ -1662,7 +1645,6 @@ function get_most_recent_post_of_user( $user_id ) { * a blog has exceeded its allowed upload space. * * @since MU - * @uses recurse_dirsize() * * @param string $directory * @return int @@ -1733,7 +1715,8 @@ function recurse_dirsize( $directory ) { * @return array */ function check_upload_mimes( $mimes ) { - $site_exts = explode( ' ', get_site_option( 'upload_filetypes' ) ); + $site_exts = explode( ' ', get_site_option( 'upload_filetypes', 'jpg jpeg png gif' ) ); + $site_mimes = array(); foreach ( $site_exts as $ext ) { foreach ( $mimes as $ext_pattern => $mime ) { if ( $ext != '' && strpos( $ext_pattern, $ext ) !== false ) @@ -1749,7 +1732,7 @@ function check_upload_mimes( $mimes ) { * WordPress MS stores a blog's post count as an option so as * to avoid extraneous COUNTs when a blog's details are fetched * with get_blog_details(). This function is called when posts - * are published to make sure the count stays current. + * are published or unpublished to make sure the count stays current. * * @since MU */ @@ -1818,11 +1801,13 @@ function global_terms( $term_id, $deprecated = '' ) { $global_id = $wpdb->insert_id; } } elseif ( $global_id != $term_id ) { - $local_id = $wpdb->get_row( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms WHERE term_id = %d", $global_id ) ); - if ( null != $local_id ) - $local_id = global_terms( $local_id ); - if ( 10 < $global_terms_recurse ) + $local_id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms WHERE term_id = %d", $global_id ) ); + if ( null != $local_id ) { + global_terms( $local_id ); + if ( 10 < $global_terms_recurse ) { $global_id = $term_id; + } + } } if ( $global_id != $term_id ) { @@ -1875,7 +1860,6 @@ function upload_is_file_too_big( $upload ) { * Add a nonce field to the signup page. * * @since MU - * @uses wp_nonce_field() */ function signup_nonce_fields() { $id = mt_rand(); @@ -1887,7 +1871,6 @@ function signup_nonce_fields() { * Process the signup nonce created in signup_nonce_fields(). * * @since MU - * @uses wp_create_nonce() * * @param array $result * @return array @@ -1933,7 +1916,6 @@ function maybe_redirect_404() { * added, as when a user is invited through the regular WP Add User interface. * * @since MU - * @uses add_existing_user_to_blog() */ function maybe_add_existing_user_to_blog() { if ( false === strpos( $_SERVER[ 'REQUEST_URI' ], '/newbloguser/' ) ) @@ -1952,14 +1934,13 @@ function maybe_add_existing_user_to_blog() { if ( empty( $details ) || is_wp_error( add_existing_user_to_blog( $details ) ) ) wp_die( sprintf(__('An error occurred adding you to this site. Back to the homepage.'), home_url() ) ); - wp_die( sprintf( __( 'You have been added to this site. Please visit the homepage or log in using your username and password.' ), home_url(), admin_url() ), __( 'WordPress › Success' ) ); + wp_die( sprintf( __( 'You have been added to this site. Please visit the homepage or log in using your username and password.' ), home_url(), admin_url() ), __( 'WordPress › Success' ), array( 'response' => 200 ) ); } /** * Add a user to a blog based on details from maybe_add_existing_user_to_blog(). * * @since MU - * @uses add_user_to_blog() * * @param array $details */ @@ -2017,18 +1998,18 @@ function fix_phpmailer_messageid( $phpmailer ) { * Check to see whether a user is marked as a spammer, based on user login. * * @since MU - * @uses get_user_by() * * @param string|WP_User $user Optional. Defaults to current user. WP_User object, * or user login name as a string. * @return bool */ function is_user_spammy( $user = null ) { - if ( ! is_a( $user, 'WP_User' ) ) { - if ( $user ) + if ( ! ( $user instanceof WP_User ) ) { + if ( $user ) { $user = get_user_by( 'login', $user ); - else + } else { $user = wp_get_current_user(); + } } return $user && isset( $user->spam ) && 1 == $user->spam; @@ -2040,22 +2021,18 @@ function is_user_spammy( $user = null ) { * Public blogs have a setting of 1, private blogs are 0. * * @since MU - * @uses update_blog_status() * * @param int $old_value * @param int $value The new public value - * @return bool */ function update_blog_public( $old_value, $value ) { update_blog_status( get_current_blog_id(), 'public', (int) $value ); } -add_action('update_option_blog_public', 'update_blog_public', 10, 2); /** * Check whether a usermeta key has to do with the current blog. * * @since MU - * @uses wp_get_current_user() * * @param string $key * @param int $user_id Optional. Defaults to current user. @@ -2066,11 +2043,9 @@ function is_user_option_local( $key, $user_id = 0, $blog_id = 0 ) { global $wpdb; $current_user = wp_get_current_user(); - if ( $user_id == 0 ) - $user_id = $current_user->ID; - if ( $blog_id == 0 ) + if ( $blog_id == 0 ) { $blog_id = $wpdb->blogid; - + } $local_key = $wpdb->get_blog_prefix( $blog_id ) . $key; if ( isset( $current_user->$local_key ) ) @@ -2093,7 +2068,6 @@ function users_can_register_signup_filter() { return false; } -add_filter('option_users_can_register', 'users_can_register_signup_filter'); /** * Ensure that the welcome message is not empty. Currently unused. @@ -2106,7 +2080,7 @@ add_filter('option_users_can_register', 'users_can_register_signup_filter'); function welcome_user_msg_filter( $text ) { if ( !$text ) { remove_filter( 'site_option_welcome_user_email', 'welcome_user_msg_filter' ); - $text = __( 'Dear User, + $text = __( 'Howdy USERNAME, Your new account is set up. @@ -2122,7 +2096,6 @@ Thanks! } return $text; } -add_filter( 'site_option_welcome_user_email', 'welcome_user_msg_filter' ); /** * Whether to force SSL on content. @@ -2194,8 +2167,6 @@ function wp_update_network_counts() { * on a network when a site is created or its status is updated. * * @since 3.7.0 - * - * @uses wp_update_network_site_counts() */ function wp_maybe_update_network_site_counts() { $is_small_network = ! wp_is_large_network( 'sites' ); @@ -2223,8 +2194,6 @@ function wp_maybe_update_network_site_counts() { * on a network when a user is created or its status is updated. * * @since 3.7.0 - * - * @uses wp_update_network_user_counts() */ function wp_maybe_update_network_user_counts() { $is_small_network = ! wp_is_large_network( 'users' );