wp/wp-admin/includes/ms.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * Multisite administration functions.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage Multisite
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 * Determine if uploaded file exceeds space quota.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 * @param array $file $_FILES array for a given file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 * @return array $_FILES array with 'error' key set if file exceeds quota. 'error' is empty otherwise.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
function check_upload_size( $file ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
	if ( get_site_option( 'upload_space_check_disabled' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
		return $file;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
	if ( $file['error'] != '0' ) // there's already an error
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
		return $file;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
	if ( defined( 'WP_IMPORTING' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
		return $file;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
	$space_left = get_upload_space_available();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
	$file_size = filesize( $file['tmp_name'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
	if ( $space_left < $file_size )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
		$file['error'] = sprintf( __( 'Not enough space to upload. %1$s KB needed.' ), number_format( ($file_size - $space_left) /1024 ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
	if ( $file_size > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
		$file['error'] = sprintf(__('This file is too big. Files must be less than %1$s KB in size.'), get_site_option( 'fileupload_maxk', 1500 ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
	if ( upload_is_user_over_quota( false ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
		$file['error'] = __( 'You have used your space quota. Please delete files before uploading.' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    38
	if ( $file['error'] != '0' && ! isset( $_POST['html-upload'] ) && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
		wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    40
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
	return $file;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
add_filter( 'wp_handle_upload_prefilter', 'check_upload_size' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    47
 * Delete a blog.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    51
 * @param int  $blog_id Blog ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    52
 * @param bool $drop    True if blog's table should be dropped. Default is false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
function wpmu_delete_blog( $blog_id, $drop = false ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    55
	global $wpdb;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
	$switch = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
	if ( get_current_blog_id() != $blog_id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
		$switch = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
		switch_to_blog( $blog_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
	$blog = get_blog_details( $blog_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
	 * Fires before a blog is deleted.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
	 * @since MU
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
	 * @param int  $blog_id The blog ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
	 * @param bool $drop    True if blog's table should be dropped. Default is false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
	do_action( 'delete_blog', $blog_id, $drop );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
	$users = get_users( array( 'blog_id' => $blog_id, 'fields' => 'ids' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
	// Remove users from this blog.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
	if ( ! empty( $users ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
		foreach ( $users as $user_id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
			remove_user_from_blog( $user_id, $blog_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
	update_blog_status( $blog_id, 'deleted', 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    85
	$current_site = get_current_site();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    86
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    87
	// If a full blog object is not available, do not destroy anything.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    88
	if ( $drop && ! $blog ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    89
		$drop = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    90
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    91
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
	// Don't destroy the initial, main, or root blog.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    93
	if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->domain ) ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
		$drop = false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    95
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    96
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    97
	$upload_path = trim( get_option( 'upload_path' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    98
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    99
	// If ms_files_rewriting is enabled and upload_path is empty, wp_upload_dir is not reliable.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   100
	if ( $drop && get_site_option( 'ms_files_rewriting' ) && empty( $upload_path ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   101
		$drop = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   102
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
	if ( $drop ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   105
		$uploads = wp_upload_dir();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   106
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
		$tables = $wpdb->tables( 'blog' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
		 * Filter the tables to drop when the blog is deleted.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
		 * @since MU
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
		 * @param array $tables  The blog tables to be dropped.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
		 * @param int   $blog_id The ID of the blog to drop tables for.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
		$drop_tables = apply_filters( 'wpmu_drop_tables', $tables, $blog_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
		foreach ( (array) $drop_tables as $table ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
			$wpdb->query( "DROP TABLE IF EXISTS `$table`" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
		$wpdb->delete( $wpdb->blogs, array( 'blog_id' => $blog_id ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
		 * Filter the upload base directory to delete when the blog is deleted.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
		 * @since MU
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
		 * @param string $uploads['basedir'] Uploads path without subdirectory. @see wp_upload_dir()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
		 * @param int    $blog_id            The blog ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
		$dir = apply_filters( 'wpmu_delete_blog_upload_dir', $uploads['basedir'], $blog_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
		$dir = rtrim( $dir, DIRECTORY_SEPARATOR );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
		$top_dir = $dir;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
		$stack = array($dir);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
		$index = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
		while ( $index < count( $stack ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   139
			// Get indexed directory from stack
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
			$dir = $stack[$index];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
			$dh = @opendir( $dir );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
			if ( $dh ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
				while ( ( $file = @readdir( $dh ) ) !== false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
					if ( $file == '.' || $file == '..' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
						continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   148
					if ( @is_dir( $dir . DIRECTORY_SEPARATOR . $file ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
						$stack[] = $dir . DIRECTORY_SEPARATOR . $file;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   150
					} elseif ( @is_file( $dir . DIRECTORY_SEPARATOR . $file ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
						@unlink( $dir . DIRECTORY_SEPARATOR . $file );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   152
					}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
				@closedir( $dh );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
			$index++;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
		$stack = array_reverse( $stack ); // Last added dirs are deepest
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
		foreach( (array) $stack as $dir ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
			if ( $dir != $top_dir)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
			@rmdir( $dir );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
		clean_blog_cache( $blog );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
	if ( $switch )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
		restore_current_blog();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   172
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   173
 * Delete a user from the network and remove from all sites.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   174
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   175
 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   176
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   177
 * @todo Merge with wp_delete_user() ?
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   178
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   179
 * @param int $id The user ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   180
 * @return bool True if the user was deleted, otherwise false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   181
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
function wpmu_delete_user( $id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
	$id = (int) $id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
	$user = new WP_User( $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
	if ( !$user->exists() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
	 * Fires before a user is deleted from the network.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
	 * @since MU
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
	 * @param int $id ID of the user about to be deleted from the network.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
	do_action( 'wpmu_delete_user', $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
	$blogs = get_blogs_of_user( $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
	if ( ! empty( $blogs ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
		foreach ( $blogs as $blog ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
			switch_to_blog( $blog->userblog_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
			remove_user_from_blog( $id, $blog->userblog_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
			$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
			foreach ( (array) $post_ids as $post_id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
				wp_delete_post( $post_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
			// Clean links
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
			$link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
			if ( $link_ids ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
				foreach ( $link_ids as $link_id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
					wp_delete_link( $link_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
			restore_current_blog();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
	$meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
	foreach ( $meta as $mid )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
		delete_metadata_by_mid( 'user', $mid );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
	$wpdb->delete( $wpdb->users, array( 'ID' => $id ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
	clean_user_cache( $user );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   231
	/** This action is documented in wp-admin/includes/user.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
	do_action( 'deleted_user', $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   237
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   238
 * Sends an email when a site administrator email address is changed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   239
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   240
 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   241
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   242
 * @param string $old_value The old email address. Not currently used.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   243
 * @param string $value     The new email address.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   244
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
function update_option_new_admin_email( $old_value, $value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
	if ( $value == get_option( 'admin_email' ) || !is_email( $value ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
	$hash = md5( $value. time() .mt_rand() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
	$new_admin_email = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
		'hash' => $hash,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
		'newemail' => $value
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
	update_option( 'adminhash', $new_admin_email );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   256
	$email_text = __( 'Howdy ###USERNAME###,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
You recently requested to have the administration email address on
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
your site changed.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   260
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
If this is correct, please click on the following link to change it:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
###ADMIN_URL###
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
You can safely ignore and delete this email if you do not want to
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
take this action.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
This email has been sent to ###EMAIL###
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
Regards,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
All at ###SITENAME###
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
###SITEURL###' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
	 * Filter the email text sent when the site admin email is changed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
	 * The following strings have a special meaning and will get replaced dynamically:
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   277
	 * ###USERNAME###  The current user's username.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   278
	 * ###ADMIN_URL### The link to click on to confirm the email change.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
	 * ###EMAIL###     The new email.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
	 * ###SITENAME###  The name of the site.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
	 * ###SITEURL###   The URL to the site.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
	 * @since MU
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
	 * @param string $email_text      Text in the email.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
	 * @param string $new_admin_email New admin email that the current administration email was changed to.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
	$content = apply_filters( 'new_admin_email_content', $email_text, $new_admin_email );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   290
	$content = str_replace( '###USERNAME###', $current_user->user_login, $content );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
	$content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'options.php?adminhash='.$hash ) ), $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
	$content = str_replace( '###EMAIL###', $value, $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
	$content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
	$content = str_replace( '###SITEURL###', network_home_url(), $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   296
	wp_mail( $value, sprintf( __( '[%s] New Admin Email Address' ), wp_specialchars_decode( get_option( 'blogname' ) ) ), $content );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
add_action( 'update_option_new_admin_email', 'update_option_new_admin_email', 10, 2 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
add_action( 'add_option_new_admin_email', 'update_option_new_admin_email', 10, 2 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   301
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   302
 * Sends an email when an email address change is requested.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   303
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   304
 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   305
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   306
 * @global object $errors WP_Error object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   307
 * @global object $wpdb   WordPress database object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   308
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
function send_confirmation_on_profile_email() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
	global $errors, $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
	$current_user = wp_get_current_user();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
	if ( ! is_object($errors) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
		$errors = new WP_Error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
	if ( $current_user->ID != $_POST['user_id'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
	if ( $current_user->user_email != $_POST['email'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
		if ( !is_email( $_POST['email'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
			$errors->add( 'user_email', __( "<strong>ERROR</strong>: The email address isn&#8217;t correct." ), array( 'form-field' => 'email' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
		if ( $wpdb->get_var( $wpdb->prepare( "SELECT user_email FROM {$wpdb->users} WHERE user_email=%s", $_POST['email'] ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
			$errors->add( 'user_email', __( "<strong>ERROR</strong>: The email address is already used." ), array( 'form-field' => 'email' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
			delete_option( $current_user->ID . '_new_email' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
		$hash = md5( $_POST['email'] . time() . mt_rand() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
		$new_user_email = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
				'hash' => $hash,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
				'newemail' => $_POST['email']
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
				);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
		update_option( $current_user->ID . '_new_email', $new_user_email );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   337
		$email_text = __( 'Howdy ###USERNAME###,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
You recently requested to have the email address on your account changed.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   340
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
If this is correct, please click on the following link to change it:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
###ADMIN_URL###
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
You can safely ignore and delete this email if you do not want to
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
take this action.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
This email has been sent to ###EMAIL###
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
Regards,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
All at ###SITENAME###
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
###SITEURL###' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
		 * Filter the email text sent when a user changes emails.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
		 * The following strings have a special meaning and will get replaced dynamically:
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   357
		 * ###USERNAME###  The current user's username.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   358
		 * ###ADMIN_URL### The link to click on to confirm the email change.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   359
		 * ###EMAIL###     The new email.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   360
		 * ###SITENAME###  The name of the site.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   361
		 * ###SITEURL###   The URL to the site.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
		 * @since MU
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
		 * @param string $email_text     Text in the email.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
		 * @param string $new_user_email New user email that the current user has changed to.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
		$content = apply_filters( 'new_user_email_content', $email_text, $new_user_email );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   370
		$content = str_replace( '###USERNAME###', $current_user->user_login, $content );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
		$content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'profile.php?newuseremail='.$hash ) ), $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
		$content = str_replace( '###EMAIL###', $_POST['email'], $content);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
		$content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
		$content = str_replace( '###SITEURL###', network_home_url(), $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   376
		wp_mail( $_POST['email'], sprintf( __( '[%s] New Email Address' ), wp_specialchars_decode( get_option( 'blogname' ) ) ), $content );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
		$_POST['email'] = $current_user->user_email;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
add_action( 'personal_options_update', 'send_confirmation_on_profile_email' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   382
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   383
 * Adds an admin notice alerting the user to check for confirmation email
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   384
 * after email address change.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   385
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   386
 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   387
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
function new_user_email_admin_notice() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
	if ( strpos( $_SERVER['PHP_SELF'], 'profile.php' ) && isset( $_GET['updated'] ) && $email = get_option( get_current_user_id() . '_new_email' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
		echo "<div class='update-nag'>" . sprintf( __( "Your email address has not been updated yet. Please check your inbox at %s for a confirmation email." ), $email['newemail'] ) . "</div>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
add_action( 'admin_notices', 'new_user_email_admin_notice' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
 * Check whether a blog has used its allotted upload space.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
 * @since MU
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
 * @param bool $echo Optional. If $echo is set and the quota is exceeded, a warning message is echoed. Default is true.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   400
 * @return bool True if user is over upload space quota, otherwise false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
function upload_is_user_over_quota( $echo = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
	if ( get_site_option( 'upload_space_check_disabled' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
	$space_allowed = get_space_allowed();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
	if ( empty( $space_allowed ) || !is_numeric( $space_allowed ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
		$space_allowed = 10; // Default space allowed is 10 MB
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
	$space_used = get_space_used();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
	if ( ( $space_allowed - $space_used ) < 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
		if ( $echo )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
			_e( 'Sorry, you have used your space allocation. Please delete some files to upload more files.' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
 * Displays the amount of disk space used by the current blog. Not used in core.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
 * @since MU
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
function display_space_usage() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
	$space_allowed = get_space_allowed();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
	$space_used = get_space_used();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
	$percent_used = ( $space_used / $space_allowed ) * 100;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
	if ( $space_allowed > 1000 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
		$space = number_format( $space_allowed / 1024 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
		/* translators: Gigabytes */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
		$space .= __( 'GB' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
		$space = number_format( $space_allowed );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
		/* translators: Megabytes */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
		$space .= __( 'MB' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
	<strong><?php printf( __( 'Used: %1$s%% of %2$s' ), number_format( $percent_used ), $space ); ?></strong>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
 * Get the remaining upload space for this blog.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
 * @since MU
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
 * @param int $size Current max size in bytes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
 * @return int Max size in bytes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
function fix_import_form_size( $size ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
	if ( upload_is_user_over_quota( false ) == true )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
		return 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
	$available = get_upload_space_available();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
	return min( $size, $available );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   462
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   463
 * Displays the edit blog upload space setting form on the Edit Blog screen.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   464
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   465
 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   466
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   467
 * @param int $id The ID of the blog to display the setting for.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   468
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
function upload_space_setting( $id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
	switch_to_blog( $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
	$quota = get_option( 'blog_upload_space' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
	restore_current_blog();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
	if ( !$quota )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
		$quota = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
	<tr>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   479
		<th><label for="blog-upload-space-number"><?php _e( 'Site Upload Space Quota' ); ?></label></th>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   480
		<td>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   481
			<input type="number" step="1" min="0" style="width: 100px" name="option[blog_upload_space]" id="blog-upload-space-number" aria-describedby="blog-upload-space-desc" value="<?php echo $quota; ?>" />
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   482
			<span id="blog-upload-space-desc"><span class="screen-reader-text"><?php _e( 'Size in megabytes' ); ?></span> <?php _e( 'MB (Leave blank for network default)' ); ?></span>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   483
		</td>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
	</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
add_action( 'wpmueditblogaction', 'upload_space_setting' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   489
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   490
 * Update the status of a user in the database.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   491
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   492
 * Used in core to mark a user as spam or "ham" (not spam) in Multisite.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   493
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   494
 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   495
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   496
 * @param int    $id         The user ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   497
 * @param string $pref       The column in the wp_users table to update the user's status
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   498
 *                           in (presumably user_status, spam, or deleted).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   499
 * @param int    $value      The new status for the user.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   500
 * @param null   $deprecated Deprecated as of 3.0.2 and should not be used.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   501
 * @return int   The initially passed $value.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   502
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
function update_user_status( $id, $pref, $value, $deprecated = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
	if ( null !== $deprecated )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
		_deprecated_argument( __FUNCTION__, '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
	$wpdb->update( $wpdb->users, array( sanitize_key( $pref ) => $value ), array( 'ID' => $id ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
	$user = new WP_User( $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
	clean_user_cache( $user );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
	if ( $pref == 'spam' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
		if ( $value == 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
			/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
			 * Fires after the user is marked as a SPAM user.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
			 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
			 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
			 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
			 * @param int $id ID of the user marked as SPAM.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
			 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
			do_action( 'make_spam_user', $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
			/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
			 * Fires after the user is marked as a HAM user. Opposite of SPAM.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
			 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
			 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
			 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
			 * @param int $id ID of the user marked as HAM.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
			 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
			do_action( 'make_ham_user', $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
	return $value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   539
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   540
 * Cleans the user cache for a specific user.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   541
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   542
 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   543
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   544
 * @param int $id The user ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   545
 * @return bool|int The ID of the refreshed user or false if the user does not exist.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   546
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
function refresh_user_details( $id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
	$id = (int) $id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
	if ( !$user = get_userdata( $id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
	clean_user_cache( $user );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
	return $id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   558
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   559
 * Returns the language for a language code.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   560
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   561
 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   562
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   563
 * @param string $code Optional. The two-letter language code. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   564
 * @return string The language corresponding to $code if it exists. If it does not exist,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   565
 *                then the first two letters of $code is returned.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   566
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
function format_code_lang( $code = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
	$code = strtolower( substr( $code, 0, 2 ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
	$lang_codes = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
		'aa' => 'Afar', 'ab' => 'Abkhazian', 'af' => 'Afrikaans', 'ak' => 'Akan', 'sq' => 'Albanian', 'am' => 'Amharic', 'ar' => 'Arabic', 'an' => 'Aragonese', 'hy' => 'Armenian', 'as' => 'Assamese', 'av' => 'Avaric', 'ae' => 'Avestan', 'ay' => 'Aymara', 'az' => 'Azerbaijani', 'ba' => 'Bashkir', 'bm' => 'Bambara', 'eu' => 'Basque', 'be' => 'Belarusian', 'bn' => 'Bengali',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
		'bh' => 'Bihari', 'bi' => 'Bislama', 'bs' => 'Bosnian', 'br' => 'Breton', 'bg' => 'Bulgarian', 'my' => 'Burmese', 'ca' => 'Catalan; Valencian', 'ch' => 'Chamorro', 'ce' => 'Chechen', 'zh' => 'Chinese', 'cu' => 'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic', 'cv' => 'Chuvash', 'kw' => 'Cornish', 'co' => 'Corsican', 'cr' => 'Cree',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
		'cs' => 'Czech', 'da' => 'Danish', 'dv' => 'Divehi; Dhivehi; Maldivian', 'nl' => 'Dutch; Flemish', 'dz' => 'Dzongkha', 'en' => 'English', 'eo' => 'Esperanto', 'et' => 'Estonian', 'ee' => 'Ewe', 'fo' => 'Faroese', 'fj' => 'Fijjian', 'fi' => 'Finnish', 'fr' => 'French', 'fy' => 'Western Frisian', 'ff' => 'Fulah', 'ka' => 'Georgian', 'de' => 'German', 'gd' => 'Gaelic; Scottish Gaelic',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
		'ga' => 'Irish', 'gl' => 'Galician', 'gv' => 'Manx', 'el' => 'Greek, Modern', 'gn' => 'Guarani', 'gu' => 'Gujarati', 'ht' => 'Haitian; Haitian Creole', 'ha' => 'Hausa', 'he' => 'Hebrew', 'hz' => 'Herero', 'hi' => 'Hindi', 'ho' => 'Hiri Motu', 'hu' => 'Hungarian', 'ig' => 'Igbo', 'is' => 'Icelandic', 'io' => 'Ido', 'ii' => 'Sichuan Yi', 'iu' => 'Inuktitut', 'ie' => 'Interlingue',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
		'ia' => 'Interlingua (International Auxiliary Language Association)', 'id' => 'Indonesian', 'ik' => 'Inupiaq', 'it' => 'Italian', 'jv' => 'Javanese', 'ja' => 'Japanese', 'kl' => 'Kalaallisut; Greenlandic', 'kn' => 'Kannada', 'ks' => 'Kashmiri', 'kr' => 'Kanuri', 'kk' => 'Kazakh', 'km' => 'Central Khmer', 'ki' => 'Kikuyu; Gikuyu', 'rw' => 'Kinyarwanda', 'ky' => 'Kirghiz; Kyrgyz',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
		'kv' => 'Komi', 'kg' => 'Kongo', 'ko' => 'Korean', 'kj' => 'Kuanyama; Kwanyama', 'ku' => 'Kurdish', 'lo' => 'Lao', 'la' => 'Latin', 'lv' => 'Latvian', 'li' => 'Limburgan; Limburger; Limburgish', 'ln' => 'Lingala', 'lt' => 'Lithuanian', 'lb' => 'Luxembourgish; Letzeburgesch', 'lu' => 'Luba-Katanga', 'lg' => 'Ganda', 'mk' => 'Macedonian', 'mh' => 'Marshallese', 'ml' => 'Malayalam',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
		'mi' => 'Maori', 'mr' => 'Marathi', 'ms' => 'Malay', 'mg' => 'Malagasy', 'mt' => 'Maltese', 'mo' => 'Moldavian', 'mn' => 'Mongolian', 'na' => 'Nauru', 'nv' => 'Navajo; Navaho', 'nr' => 'Ndebele, South; South Ndebele', 'nd' => 'Ndebele, North; North Ndebele', 'ng' => 'Ndonga', 'ne' => 'Nepali', 'nn' => 'Norwegian Nynorsk; Nynorsk, Norwegian', 'nb' => 'Bokmål, Norwegian, Norwegian Bokmål',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
		'no' => 'Norwegian', 'ny' => 'Chichewa; Chewa; Nyanja', 'oc' => 'Occitan, Provençal', 'oj' => 'Ojibwa', 'or' => 'Oriya', 'om' => 'Oromo', 'os' => 'Ossetian; Ossetic', 'pa' => 'Panjabi; Punjabi', 'fa' => 'Persian', 'pi' => 'Pali', 'pl' => 'Polish', 'pt' => 'Portuguese', 'ps' => 'Pushto', 'qu' => 'Quechua', 'rm' => 'Romansh', 'ro' => 'Romanian', 'rn' => 'Rundi', 'ru' => 'Russian',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
		'sg' => 'Sango', 'sa' => 'Sanskrit', 'sr' => 'Serbian', 'hr' => 'Croatian', 'si' => 'Sinhala; Sinhalese', 'sk' => 'Slovak', 'sl' => 'Slovenian', 'se' => 'Northern Sami', 'sm' => 'Samoan', 'sn' => 'Shona', 'sd' => 'Sindhi', 'so' => 'Somali', 'st' => 'Sotho, Southern', 'es' => 'Spanish; Castilian', 'sc' => 'Sardinian', 'ss' => 'Swati', 'su' => 'Sundanese', 'sw' => 'Swahili',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
		'sv' => 'Swedish', 'ty' => 'Tahitian', 'ta' => 'Tamil', 'tt' => 'Tatar', 'te' => 'Telugu', 'tg' => 'Tajik', 'tl' => 'Tagalog', 'th' => 'Thai', 'bo' => 'Tibetan', 'ti' => 'Tigrinya', 'to' => 'Tonga (Tonga Islands)', 'tn' => 'Tswana', 'ts' => 'Tsonga', 'tk' => 'Turkmen', 'tr' => 'Turkish', 'tw' => 'Twi', 'ug' => 'Uighur; Uyghur', 'uk' => 'Ukrainian', 'ur' => 'Urdu', 'uz' => 'Uzbek',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
		've' => 'Venda', 'vi' => 'Vietnamese', 'vo' => 'Volapük', 'cy' => 'Welsh','wa' => 'Walloon','wo' => 'Wolof', 'xh' => 'Xhosa', 'yi' => 'Yiddish', 'yo' => 'Yoruba', 'za' => 'Zhuang; Chuang', 'zu' => 'Zulu' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
	 * Filter the language codes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
	 * @since MU
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
	 * @param array  $lang_codes Key/value pair of language codes where key is the short version.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
	 * @param string $code       A two-letter designation of the language.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
	$lang_codes = apply_filters( 'lang_codes', $lang_codes, $code );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
	return strtr( $code, $lang_codes );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   594
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   595
 * Synchronize category and post tag slugs when global terms are enabled.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   596
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   597
 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   598
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   599
 * @param object $term     The term.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   600
 * @param string $taxonomy The taxonomy for $term. Should be 'category' or 'post_tag', as these are
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   601
 *                         the only taxonomies which are processed by this function; anything else
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   602
 *                         will be returned untouched.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   603
 * @return object|array Returns `$term`, after filtering the 'slug' field with {@see sanitize_title()}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   604
 *                      if $taxonomy is 'category' or 'post_tag'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   605
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
function sync_category_tag_slugs( $term, $taxonomy ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
	if ( global_terms_enabled() && ( $taxonomy == 'category' || $taxonomy == 'post_tag' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
		if ( is_object( $term ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
			$term->slug = sanitize_title( $term->name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
			$term['slug'] = sanitize_title( $term['name'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
	return $term;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
add_filter( 'get_term', 'sync_category_tag_slugs', 10, 2 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   618
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   619
 * Displays an access denied message when a user tries to view a site's dashboard they
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   620
 * do not have access to.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   621
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   622
 * @since 3.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   623
 * @access private
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   624
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
function _access_denied_splash() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
	if ( ! is_user_logged_in() || is_network_admin() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
	$blogs = get_blogs_of_user( get_current_user_id() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
	if ( wp_list_filter( $blogs, array( 'userblog_id' => get_current_blog_id() ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
	$blog_name = get_bloginfo( 'name' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
	if ( empty( $blogs ) )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   637
		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 ), 403 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
	$output = '<p>' . 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 ) . '</p>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
	$output .= '<p>' . __( '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.' ) . '</p>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
	$output .= '<h3>' . __('Your Sites') . '</h3>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
	$output .= '<table>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
	foreach ( $blogs as $blog ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   646
		$output .= '<tr>';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   647
		$output .= "<td>{$blog->blogname}</td>";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   648
		$output .= '<td><a href="' . esc_url( get_admin_url( $blog->userblog_id ) ) . '">' . __( 'Visit Dashboard' ) . '</a> | ' .
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   649
			'<a href="' . esc_url( get_home_url( $blog->userblog_id ) ). '">' . __( 'View Site' ) . '</a></td>';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   650
		$output .= '</tr>';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   652
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
	$output .= '</table>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   655
	wp_die( $output, 403 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
add_action( 'admin_page_access_denied', '_access_denied_splash', 99 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   659
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   660
 * Checks if the current user has permissions to import new users.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   661
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   662
 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   663
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   664
 * @param string $permission A permission to be checked. Currently not used.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   665
 * @return bool True if the user has proper permissions, false if they do not.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   666
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
function check_import_new_users( $permission ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
	if ( !is_super_admin() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
add_filter( 'import_allow_create_users', 'check_import_new_users' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
// See "import_allow_fetch_attachments" and "import_attachment_size_limit" filters too.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   675
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   676
 * Generates and displays a drop-down of available languages.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   677
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   678
 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   679
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   680
 * @param array  $lang_files Optional. An array of the language files. Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   681
 * @param string $current    Optional. The current language code. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   682
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
function mu_dropdown_languages( $lang_files = array(), $current = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
	$flag = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
	$output = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
	foreach ( (array) $lang_files as $val ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
		$code_lang = basename( $val, '.mo' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
		if ( $code_lang == 'en_US' ) { // American English
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
			$flag = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
			$ae = __( 'American English' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
			$output[$ae] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $ae . '</option>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
		} elseif ( $code_lang == 'en_GB' ) { // British English
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
			$flag = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
			$be = __( 'British English' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
			$output[$be] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $be . '</option>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
			$translated = format_code_lang( $code_lang );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
			$output[$translated] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . esc_html ( $translated ) . '</option>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
	if ( $flag === false ) // WordPress english
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
		$output[] = '<option value=""' . selected( $current, '', false ) . '>' . __( 'English' ) . "</option>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
	// Order by name
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
	uksort( $output, 'strnatcasecmp' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   710
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
	 * Filter the languages available in the dropdown.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
	 * @since MU
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
	 * @param array $output     HTML output of the dropdown.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
	 * @param array $lang_files Available language files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
	 * @param string $current   The current language code.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
	$output = apply_filters( 'mu_dropdown_languages', $output, $lang_files, $current );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   721
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
	echo implode( "\n\t", $output );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   725
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   726
 * Displays an admin notice to upgrade all sites after a core upgrade.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   727
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   728
 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   729
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   730
 * @global int $wp_db_version The version number of the database.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   731
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
function site_admin_notice() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
	global $wp_db_version;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
	if ( !is_super_admin() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
	if ( get_site_option( 'wpmu_upgrade_site' ) != $wp_db_version )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
		echo "<div class='update-nag'>" . sprintf( __( 'Thank you for Updating! Please visit the <a href="%s">Upgrade Network</a> page to update all your sites.' ), esc_url( network_admin_url( 'upgrade.php' ) ) ) . "</div>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
add_action( 'admin_notices', 'site_admin_notice' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
add_action( 'network_admin_notices', 'site_admin_notice' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   742
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   743
 * Avoids a collision between a site slug and a permalink slug.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   744
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   745
 * In a subdirectory install this will make sure that a site and a post do not use the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   746
 * same subdirectory by checking for a site with the same name as a new post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   747
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   748
 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   749
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   750
 * @param array $data    An array of post data.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   751
 * @param array $postarr An array of posts. Not currently used.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   752
 * @return array The new array of post data after checking for collisions.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   753
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
function avoid_blog_page_permalink_collision( $data, $postarr ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
	if ( is_subdomain_install() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
		return $data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
	if ( $data['post_type'] != 'page' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
		return $data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
	if ( !isset( $data['post_name'] ) || $data['post_name'] == '' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
		return $data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
	if ( !is_main_site() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
		return $data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
	$post_name = $data['post_name'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
	$c = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
	while( $c < 10 && get_id_from_blogname( $post_name ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
		$post_name .= mt_rand( 1, 10 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
		$c ++;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
	if ( $post_name != $data['post_name'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
		$data['post_name'] = $post_name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   772
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
	return $data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   775
add_filter( 'wp_insert_post_data', 'avoid_blog_page_permalink_collision', 10, 2 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   777
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   778
 * Handles the display of choosing a user's primary site.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   779
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   780
 * This displays the user's primary site and allows the user to choose
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   781
 * which site is primary.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   782
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   783
 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   784
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
function choose_primary_blog() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   786
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   787
	<table class="form-table">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   788
	<tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   789
	<?php /* translators: My sites label */ ?>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   790
		<th scope="row"><label for="primary_blog"><?php _e( 'Primary Site' ); ?></label></th>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   791
		<td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   792
		<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   793
		$all_blogs = get_blogs_of_user( get_current_user_id() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   794
		$primary_blog = get_user_meta( get_current_user_id(), 'primary_blog', true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
		if ( count( $all_blogs ) > 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
			$found = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
			?>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   798
			<select name="primary_blog" id="primary_blog">
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
				<?php foreach( (array) $all_blogs as $blog ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
					if ( $primary_blog == $blog->userblog_id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
						$found = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
					?><option value="<?php echo $blog->userblog_id ?>"<?php selected( $primary_blog, $blog->userblog_id ); ?>><?php echo esc_url( get_home_url( $blog->userblog_id ) ) ?></option><?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
				} ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
			</select>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
			<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
			if ( !$found ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   807
				$blog = reset( $all_blogs );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
				update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
		} elseif ( count( $all_blogs ) == 1 ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   811
			$blog = reset( $all_blogs );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
			echo $blog->domain;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   813
			if ( $primary_blog != $blog->userblog_id ) // Set the primary blog again if it's out of sync with blog list.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
				update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
			echo "N/A";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   817
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
		?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
		</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   820
	</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   821
	<?php if ( in_array( get_site_option( 'registration' ), array( 'all', 'blog' ) ) ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   822
		<tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
			<th scope="row" colspan="2" class="th-full">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   824
				<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   825
				/** This filter is documented in wp-login.php */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   826
				$sign_up_url = apply_filters( 'wp_signup_location', network_site_url( 'wp-signup.php' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
				?>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   828
				<a href="<?php echo esc_url( $sign_up_url ); ?>"><?php _e( 'Create a New Site' ); ?></a>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   829
			</th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   830
		</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   831
	<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   832
	</table>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   833
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   834
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   835
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   836
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   837
 * Grants Super Admin privileges.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   838
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   839
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   840
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   841
 * @param int $user_id ID of the user to be granted Super Admin privileges.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   842
 * @return bool True on success, false on failure. This can fail when the user is
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   843
 *              already a super admin or when the `$super_admins` global is defined.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   844
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   845
function grant_super_admin( $user_id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   846
	// If global super_admins override is defined, there is nothing to do here.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   847
	if ( isset( $GLOBALS['super_admins'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   848
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   849
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   850
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   851
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   852
	 * Fires before the user is granted Super Admin privileges.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   853
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   854
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   855
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   856
	 * @param int $user_id ID of the user that is about to be granted Super Admin privileges.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
	do_action( 'grant_super_admin', $user_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   859
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   860
	// Directly fetch site_admins instead of using get_super_admins()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   861
	$super_admins = get_site_option( 'site_admins', array( 'admin' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   862
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   863
	$user = get_userdata( $user_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   864
	if ( $user && ! in_array( $user->user_login, $super_admins ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   865
		$super_admins[] = $user->user_login;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   866
		update_site_option( 'site_admins' , $super_admins );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   867
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   868
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   869
		 * Fires after the user is granted Super Admin privileges.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   870
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   871
		 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   872
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   873
		 * @param int $user_id ID of the user that was granted Super Admin privileges.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   874
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   875
		do_action( 'granted_super_admin', $user_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   876
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   877
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   878
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   879
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   880
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   881
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   882
 * Revokes Super Admin privileges.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   883
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   884
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   885
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   886
 * @param int $user_id ID of the user Super Admin privileges to be revoked from.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   887
 * @return bool True on success, false on failure. This can fail when the user's email
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   888
 *              is the network admin email or when the `$super_admins` global is defined.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   890
function revoke_super_admin( $user_id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   891
	// If global super_admins override is defined, there is nothing to do here.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   892
	if ( isset( $GLOBALS['super_admins'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   893
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   894
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   897
	 * Fires before the user's Super Admin privileges are revoked.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   899
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   900
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   901
	 * @param int $user_id ID of the user Super Admin privileges are being revoked from.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   902
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   903
	do_action( 'revoke_super_admin', $user_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   904
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   905
	// Directly fetch site_admins instead of using get_super_admins()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
	$super_admins = get_site_option( 'site_admins', array( 'admin' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   908
	$user = get_userdata( $user_id );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   909
	if ( $user && 0 !== strcasecmp( $user->user_email, get_site_option( 'admin_email' ) ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   910
		if ( false !== ( $key = array_search( $user->user_login, $super_admins ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   911
			unset( $super_admins[$key] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   912
			update_site_option( 'site_admins', $super_admins );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   913
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   914
			/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   915
			 * Fires after the user's Super Admin privileges are revoked.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   916
			 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   917
			 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   918
			 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   919
			 * @param int $user_id ID of the user Super Admin privileges were revoked from.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   920
			 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   921
			do_action( 'revoked_super_admin', $user_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   922
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   923
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   924
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   925
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   927
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   928
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   929
 * Whether or not we can edit this network from this page.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   930
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   931
 * By default editing of network is restricted to the Network Admin for that `$site_id`
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   932
 * this allows for this to be overridden.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   933
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   934
 * @since 3.1.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   935
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   936
 * @param int $site_id The network/site ID to check.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   937
 * @return bool True if network can be edited, otherwise false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   938
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   939
function can_edit_network( $site_id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   940
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   941
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   942
	if ( $site_id == $wpdb->siteid )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   943
		$result = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   944
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   945
		$result = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   946
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   947
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   948
	 * Filter whether this network can be edited from this page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   950
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   952
	 * @param bool $result  Whether the network can be edited from this page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   953
	 * @param int  $site_id The network/site ID to check.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   954
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
	return apply_filters( 'can_edit_network', $result, $site_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   956
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   957
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   958
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   959
 * Thickbox image paths for Network Admin.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   960
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   961
 * @since 3.1.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   962
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   963
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   964
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   965
function _thickbox_path_admin_subfolder() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
<script type="text/javascript">
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   968
var tb_pathToImage = "<?php echo includes_url( 'js/thickbox/loadingAnimation.gif', 'relative' ); ?>";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   969
</script>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   970
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   971
}