( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) ) $file['error'] = sprintf(__('This file is too big. Files must be less than %1$s KB in size.'), get_site_option( 'fileupload_maxk', 1500 ) ); if ( upload_is_user_over_quota( false ) ) { $file['error'] = __( 'You have used your space quota. Please delete files before uploading.' ); } if ( $file['error'] != '0' && !isset($_POST['html-upload']) ) wp_die( $file['error'] . ' ' . __( 'Back' ) . '' ); return $file; } add_filter( 'wp_handle_upload_prefilter', 'check_upload_size' ); /** * Delete a blog * * @since 3.0.0 * * @param int $blog_id Blog ID * @param bool $drop True if blog's table should be dropped. Default is false. * @return void */ function wpmu_delete_blog( $blog_id, $drop = false ) { global $wpdb; $switch = false; if ( $blog_id != $wpdb->blogid ) { $switch = true; switch_to_blog( $blog_id ); } $blog_prefix = $wpdb->get_blog_prefix( $blog_id ); do_action( 'delete_blog', $blog_id, $drop ); $users = get_users( array( 'blog_id' => $blog_id, 'fields' => 'ids' ) ); // Remove users from this blog. if ( ! empty( $users ) ) { foreach ( $users as $user_id ) { remove_user_from_blog( $user_id, $blog_id) ; } } update_blog_status( $blog_id, 'deleted', 1 ); 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 ); reset( $drop_tables ); foreach ( (array) $drop_tables as $drop_table) { $wpdb->query( "DROP TABLE IF EXISTS ". current( $drop_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 ); $top_dir = $dir; $stack = array($dir); $index = 0; while ( $index < count( $stack ) ) { # Get indexed directory from stack $dir = $stack[$index]; $dh = @opendir( $dir ); if ( $dh ) { while ( ( $file = @readdir( $dh ) ) !== false ) { if ( $file == '.' || $file == '..' ) continue; if ( @is_dir( $dir . DIRECTORY_SEPARATOR . $file ) ) $stack[] = $dir . DIRECTORY_SEPARATOR . $file; else if ( @is_file( $dir . DIRECTORY_SEPARATOR . $file ) ) @unlink( $dir . DIRECTORY_SEPARATOR . $file ); } } $index++; } $stack = array_reverse( $stack ); // Last added dirs are deepest foreach( (array) $stack as $dir ) { if ( $dir != $top_dir) @rmdir( $dir ); } } $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 ) restore_current_blog(); } // @todo Merge with wp_delete_user() ? function wpmu_delete_user( $id ) { global $wpdb; $id = (int) $id; do_action( 'wpmu_delete_user', $id ); $blogs = get_blogs_of_user( $id ); if ( ! empty( $blogs ) ) { foreach ( $blogs as $blog ) { switch_to_blog( $blog->userblog_id ); remove_user_from_blog( $id, $blog->userblog_id ); $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id ) ); foreach ( (array) $post_ids as $post_id ) { wp_delete_post( $post_id ); } // Clean links $link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) ); if ( $link_ids ) { foreach ( $link_ids as $link_id ) wp_delete_link( $link_id ); } restore_current_blog(); } } $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->users WHERE ID = %d", $id ) ); $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id = %d", $id ) ); clean_user_cache( $id ); // allow for commit transaction do_action( 'deleted_user', $id ); return true; } function wpmu_get_blog_allowedthemes( $blog_id = 0 ) { $themes = get_themes(); if ( $blog_id != 0 ) switch_to_blog( $blog_id ); $blog_allowed_themes = get_option( 'allowedthemes' ); if ( !is_array( $blog_allowed_themes ) || empty( $blog_allowed_themes ) ) { // convert old allowed_themes to new allowedthemes $blog_allowed_themes = get_option( 'allowed_themes' ); if ( is_array( $blog_allowed_themes ) ) { foreach( (array) $themes as $key => $theme ) { $theme_key = esc_html( $theme['Stylesheet'] ); if ( isset( $blog_allowed_themes[$key] ) == true ) { $blog_allowedthemes[$theme_key] = 1; } } $blog_allowed_themes = $blog_allowedthemes; add_option( 'allowedthemes', $blog_allowed_themes ); delete_option( 'allowed_themes' ); } } if ( $blog_id != 0 ) restore_current_blog(); return $blog_allowed_themes; } function update_option_new_admin_email( $old_value, $value ) { $email = get_option( 'admin_email' ); if ( $value == get_option( 'admin_email' ) || !is_email( $value ) ) return; $hash = md5( $value. time() .mt_rand() ); $new_admin_email = array( 'hash' => $hash, 'newemail' => $value ); update_option( 'adminhash', $new_admin_email ); $content = apply_filters( 'new_admin_email_content', __( "Dear user, You recently requested to have the administration email address on your site changed. If this is correct, please click on the following link to change it: ###ADMIN_URL### You can safely ignore and delete this email if you do not want to take this action. This email has been sent to ###EMAIL### Regards, All at ###SITENAME### ###SITEURL### "), $new_admin_email ); $content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'options.php?adminhash='.$hash ) ), $content ); $content = str_replace( '###EMAIL###', $value, $content ); $content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content ); $content = str_replace( '###SITEURL###', network_home_url(), $content ); wp_mail( $value, sprintf( __( '[%s] New Admin Email Address' ), get_option( 'blogname' ) ), $content ); } add_action( 'update_option_new_admin_email', 'update_option_new_admin_email', 10, 2 ); add_action( 'add_option_new_admin_email', 'update_option_new_admin_email', 10, 2 ); function send_confirmation_on_profile_email() { global $errors, $wpdb; $current_user = wp_get_current_user(); if ( ! is_object($errors) ) $errors = new WP_Error(); if ( $current_user->id != $_POST['user_id'] ) return false; if ( $current_user->user_email != $_POST['email'] ) { if ( !is_email( $_POST['email'] ) ) { $errors->add( 'user_email', __( "ERROR: The e-mail address isn't correct." ), array( 'form-field' => 'email' ) ); return; } if ( $wpdb->get_var( $wpdb->prepare( "SELECT user_email FROM {$wpdb->users} WHERE user_email=%s", $_POST['email'] ) ) ) { $errors->add( 'user_email', __( "ERROR: The e-mail address is already used." ), array( 'form-field' => 'email' ) ); delete_option( $current_user->ID . '_new_email' ); return; } $hash = md5( $_POST['email'] . time() . mt_rand() ); $new_user_email = array( 'hash' => $hash, 'newemail' => $_POST['email'] ); update_option( $current_user->ID . '_new_email', $new_user_email ); $content = apply_filters( 'new_user_email_content', __( "Dear user, You recently requested to have the email address on your account changed. If this is correct, please click on the following link to change it: ###ADMIN_URL### You can safely ignore and delete this email if you do not want to take this action. This email has been sent to ###EMAIL### Regards, All at ###SITENAME### ###SITEURL###" ), $new_user_email ); $content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'profile.php?newuseremail='.$hash ) ), $content ); $content = str_replace( '###EMAIL###', $_POST['email'], $content); $content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content ); $content = str_replace( '###SITEURL###', network_home_url(), $content ); wp_mail( $_POST['email'], sprintf( __( '[%s] New Email Address' ), get_option( 'blogname' ) ), $content ); $_POST['email'] = $current_user->user_email; } } add_action( 'personal_options_update', 'send_confirmation_on_profile_email' ); function new_user_email_admin_notice() { if ( strpos( $_SERVER['PHP_SELF'], 'profile.php' ) && isset( $_GET['updated'] ) && $email = get_option( get_current_user_id() . '_new_email' ) ) echo "
' . sprintf( __( 'You attempted to access the "%s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "Test" dashboard, please contact your network administrator.' ), $blog_name ) . '
'; $output .= '' . __( 'If you reached this screen by accident and meant to visit one your own sites, here are some shortcuts to help you find your way.' ) . '
'; $output .= '"; $output .= "{$blog->blogname}"; $output .= " | "; $output .= ""; $output .= "" . __( 'Visit Dashboard' ) . " | " . __( 'View Site' ) . "" ; $output .= " | "; $output .= "
/* That's all, stop editing! Happy blogging. */
please add this code:" );
$msg .= "$out
";
echo "%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( 'network_admin_notices', 'ms_deprecated_blogs_file' );
/**
* Grants super admin privileges.
*
* @since 3.0.0
* @param int $user_id
*/
function grant_super_admin( $user_id ) {
global $super_admins;
// If global super_admins override is defined, there is nothing to do here.
if ( isset($super_admins) )
return false;
do_action( 'grant_super_admin', $user_id );
// Directly fetch site_admins instead of using get_super_admins()
$super_admins = get_site_option( 'site_admins', array( 'admin' ) );
$user = new WP_User( $user_id );
if ( ! in_array( $user->user_login, $super_admins ) ) {
$super_admins[] = $user->user_login;
update_site_option( 'site_admins' , $super_admins );
do_action( 'granted_super_admin', $user_id );
return true;
}
return false;
}
/**
* Revokes super admin privileges.
*
* @since 3.0.0
* @param int $user_id
*/
function revoke_super_admin( $user_id ) {
global $super_admins;
// If global super_admins override is defined, there is nothing to do here.
if ( isset($super_admins) )
return false;
do_action( 'revoke_super_admin', $user_id );
// Directly fetch site_admins instead of using get_super_admins()
$super_admins = get_site_option( 'site_admins', array( 'admin' ) );
$user = new WP_User( $user_id );
if ( $user->user_email != get_site_option( 'admin_email' ) ) {
if ( false !== ( $key = array_search( $user->user_login, $super_admins ) ) ) {
unset( $super_admins[$key] );
update_site_option( 'site_admins', $super_admins );
do_action( 'revoked_super_admin', $user_id );
return true;
}
}
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() {
?>