wp/wp-admin/includes/ms.php
author ymh <ymh.work@gmail.com>
Wed, 06 Nov 2013 03:21:17 +0000
changeset 0 d970ebf37754
child 5 5e2f62d02dcd
permissions -rw-r--r--
first import
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
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
	if ( $file['error'] != '0' && !isset($_POST['html-upload']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
		wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
	return $file;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
add_filter( 'wp_handle_upload_prefilter', 'check_upload_size' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
 * Delete a blog
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
 * @param int $blog_id Blog ID
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
 * @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
    52
 * @return void
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 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
	global $wpdb, $current_site;
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
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
	// Don't destroy the initial, main, or root blog.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
	if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->domain ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
		$drop = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
	if ( $drop ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
		$tables = $wpdb->tables( 'blog' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
		 * Filter the tables to drop when the blog is deleted.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
		 * @since MU
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
		 * @param array $tables  The blog tables to be dropped.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
		 * @param int   $blog_id The ID of the blog to drop tables for.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
		$drop_tables = apply_filters( 'wpmu_drop_tables', $tables, $blog_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
		foreach ( (array) $drop_tables as $table ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
			$wpdb->query( "DROP TABLE IF EXISTS `$table`" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
		$wpdb->delete( $wpdb->blogs, array( 'blog_id' => $blog_id ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
		$uploads = wp_upload_dir();
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 upload base directory to delete 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 string $uploads['basedir'] Uploads path without subdirectory. @see wp_upload_dir()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
		 * @param int    $blog_id            The blog ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
		$dir = apply_filters( 'wpmu_delete_blog_upload_dir', $uploads['basedir'], $blog_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
		$dir = rtrim( $dir, DIRECTORY_SEPARATOR );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
		$top_dir = $dir;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
		$stack = array($dir);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
		$index = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
		while ( $index < count( $stack ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
			# Get indexed directory from stack
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
			$dir = $stack[$index];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
			$dh = @opendir( $dir );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
			if ( $dh ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
				while ( ( $file = @readdir( $dh ) ) !== false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
					if ( $file == '.' || $file == '..' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
						continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
					if ( @is_dir( $dir . DIRECTORY_SEPARATOR . $file ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
						$stack[] = $dir . DIRECTORY_SEPARATOR . $file;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
					else if ( @is_file( $dir . DIRECTORY_SEPARATOR . $file ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
						@unlink( $dir . DIRECTORY_SEPARATOR . $file );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
				@closedir( $dh );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
			$index++;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
		$stack = array_reverse( $stack ); // Last added dirs are deepest
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
		foreach( (array) $stack as $dir ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
			if ( $dir != $top_dir)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
			@rmdir( $dir );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
		clean_blog_cache( $blog );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
	if ( $switch )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
		restore_current_blog();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
// @todo Merge with wp_delete_user() ?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
function wpmu_delete_user( $id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
	$id = (int) $id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
	$user = new WP_User( $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
	if ( !$user->exists() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
	 * Fires before a user is deleted from the network.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
	 * @since MU
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
	 * @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
   170
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
	do_action( 'wpmu_delete_user', $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
	$blogs = get_blogs_of_user( $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
	if ( ! empty( $blogs ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
		foreach ( $blogs as $blog ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
			switch_to_blog( $blog->userblog_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
			remove_user_from_blog( $id, $blog->userblog_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
			$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
   181
			foreach ( (array) $post_ids as $post_id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
				wp_delete_post( $post_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
			// Clean links
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
			$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
   187
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
			if ( $link_ids ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
				foreach ( $link_ids as $link_id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
					wp_delete_link( $link_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
			restore_current_blog();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
	$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
   198
	foreach ( $meta as $mid )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
		delete_metadata_by_mid( 'user', $mid );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
	$wpdb->delete( $wpdb->users, array( 'ID' => $id ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
	clean_user_cache( $user );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
	 * Fires after the user is deleted from the network.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
	 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
	 * @param int $id ID of the user that was deleted from the network.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
	do_action( 'deleted_user', $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
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
function update_option_new_admin_email( $old_value, $value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
	$email = get_option( 'admin_email' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
	if ( $value == get_option( 'admin_email' ) || !is_email( $value ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
	$hash = md5( $value. time() .mt_rand() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
	$new_admin_email = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
		'hash' => $hash,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
		'newemail' => $value
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
	update_option( 'adminhash', $new_admin_email );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
	$email_text = __( 'Dear user,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
You recently requested to have the administration email address on
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
your site changed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
If this is correct, please click on the following link to change it:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
###ADMIN_URL###
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
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
   237
take this action.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
This email has been sent to ###EMAIL###
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
Regards,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
All at ###SITENAME###
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
###SITEURL###' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
	 * Filter the email text sent when the site admin email is changed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
	 * The following strings have a special meaning and will get replaced dynamically:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
	 * ###ADMIN_URL### The link to click on to confirm the email change. Required otherwise this functunalty is will break.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
	 * ###EMAIL###     The new email.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
	 * ###SITENAME###  The name of the site.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
	 * ###SITEURL###   The URL to the site.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
	 * @since MU
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
	 * @param string $email_text      Text in the email.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
	 * @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
   258
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
	$content = apply_filters( 'new_admin_email_content', $email_text, $new_admin_email );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
	$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
   262
	$content = str_replace( '###EMAIL###', $value, $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
	$content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
	$content = str_replace( '###SITEURL###', network_home_url(), $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
	wp_mail( $value, sprintf( __( '[%s] New Admin Email Address' ), get_option( 'blogname' ) ), $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
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
   269
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
   270
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
function send_confirmation_on_profile_email() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
	global $errors, $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
	$current_user = wp_get_current_user();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
	if ( ! is_object($errors) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
		$errors = new WP_Error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
	if ( $current_user->ID != $_POST['user_id'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
	if ( $current_user->user_email != $_POST['email'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
		if ( !is_email( $_POST['email'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
			$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
   283
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
		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
   287
			$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
   288
			delete_option( $current_user->ID . '_new_email' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
		$hash = md5( $_POST['email'] . time() . mt_rand() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
		$new_user_email = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
				'hash' => $hash,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
				'newemail' => $_POST['email']
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
				);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
		update_option( $current_user->ID . '_new_email', $new_user_email );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
		$email_text = __( 'Dear user,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
You recently requested to have the email address on your account changed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
If this is correct, please click on the following link to change it:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
###ADMIN_URL###
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
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
   306
take this action.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
This email has been sent to ###EMAIL###
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
Regards,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
All at ###SITENAME###
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
###SITEURL###' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
		 * Filter the email text sent when a user changes emails.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
		 * The following strings have a special meaning and will get replaced dynamically:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
		 * ###ADMIN_URL### The link to click on to confirm the email change. Required otherwise this functunalty is will break.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
		 * ###EMAIL### The new email.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
		 * ###SITENAME### The name of the site.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
		 * ###SITEURL### The URL to the site.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
		 * @since MU
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
		 * @param string $email_text     Text in the email.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
		 * @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
   327
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
		$content = apply_filters( 'new_user_email_content', $email_text, $new_user_email );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
		$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
   331
		$content = str_replace( '###EMAIL###', $_POST['email'], $content);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
		$content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
		$content = str_replace( '###SITEURL###', network_home_url(), $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
		wp_mail( $_POST['email'], sprintf( __( '[%s] New Email Address' ), get_option( 'blogname' ) ), $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
		$_POST['email'] = $current_user->user_email;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
add_action( 'personal_options_update', 'send_confirmation_on_profile_email' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
function new_user_email_admin_notice() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
	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
   343
		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
   344
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
add_action( 'admin_notices', 'new_user_email_admin_notice' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
 * Check whether a blog has used its allotted upload space.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
 * @since MU
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
 * @param bool $echo Optional. If $echo is set and the quota is exceeded, a warning message is echoed. Default is true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
 * @return int
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
function upload_is_user_over_quota( $echo = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
	if ( get_site_option( 'upload_space_check_disabled' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
	$space_allowed = get_space_allowed();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
	if ( empty( $space_allowed ) || !is_numeric( $space_allowed ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
		$space_allowed = 10; // Default space allowed is 10 MB
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
	$space_used = get_space_used();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
	if ( ( $space_allowed - $space_used ) < 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
		if ( $echo )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
			_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
   368
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
 * 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
   376
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
 * @since MU
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
function display_space_usage() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
	$space_allowed = get_space_allowed();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
	$space_used = get_space_used();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
	$percent_used = ( $space_used / $space_allowed ) * 100;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
	if ( $space_allowed > 1000 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
		$space = number_format( $space_allowed / 1024 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
		/* translators: Gigabytes */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
		$space .= __( 'GB' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
		$space = number_format( $space_allowed );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
		/* translators: Megabytes */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
		$space .= __( 'MB' );
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
	<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
   396
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
 * Get the remaining upload space for this blog.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
 * @since MU
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
 * @uses upload_is_user_over_quota()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
 * @uses get_space_allowed()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
 * @uses get_upload_space_available()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
 * @param int $size Current max size in bytes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
 * @return int Max size in bytes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
function fix_import_form_size( $size ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
	if ( upload_is_user_over_quota( false ) == true )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
		return 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
	$available = get_upload_space_available();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
	return min( $size, $available );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
// Edit blog upload space setting on Edit Blog page
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
function upload_space_setting( $id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
	switch_to_blog( $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
	$quota = get_option( 'blog_upload_space' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
	restore_current_blog();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
	if ( !$quota )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
		$quota = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
	<tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
		<th><?php _e( 'Site Upload Space Quota '); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
		<td><input type="number" step="1" min="0" style="width: 100px" name="option[blog_upload_space]" value="<?php echo $quota; ?>" /> <?php _e( 'MB (Leave blank for network default)' ); ?></td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
	</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
add_action( 'wpmueditblogaction', 'upload_space_setting' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
function update_user_status( $id, $pref, $value, $deprecated = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
	if ( null !== $deprecated )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
		_deprecated_argument( __FUNCTION__, '3.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
	$wpdb->update( $wpdb->users, array( sanitize_key( $pref ) => $value ), array( 'ID' => $id ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
	$user = new WP_User( $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
	clean_user_cache( $user );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
	if ( $pref == 'spam' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
		if ( $value == 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
			/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
			 * Fires after the user is marked as a SPAM user.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
			 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
			 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
			 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
			 * @param int $id ID of the user marked as SPAM.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
			 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
			do_action( 'make_spam_user', $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
			/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
			 * Fires after the user is marked as a HAM user. Opposite of SPAM.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
			 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
			 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
			 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
			 * @param int $id ID of the user marked as HAM.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
			 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
			do_action( 'make_ham_user', $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
	return $value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
function refresh_user_details( $id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
	$id = (int) $id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
	if ( !$user = get_userdata( $id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
	clean_user_cache( $user );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
	return $id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
function format_code_lang( $code = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
	$code = strtolower( substr( $code, 0, 2 ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
	$lang_codes = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
		'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
   487
		'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
   488
		'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
   489
		'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
   490
		'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
   491
		'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
   492
		'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
   493
		'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
   494
		'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
   495
		'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
   496
		'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
   497
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
	 * Filter the language codes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
	 * @since MU
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
	 * @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
   504
	 * @param string $code       A two-letter designation of the language.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
	$lang_codes = apply_filters( 'lang_codes', $lang_codes, $code );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
	return strtr( $code, $lang_codes );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
function sync_category_tag_slugs( $term, $taxonomy ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
	if ( global_terms_enabled() && ( $taxonomy == 'category' || $taxonomy == 'post_tag' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
		if ( is_object( $term ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
			$term->slug = sanitize_title( $term->name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
			$term['slug'] = sanitize_title( $term['name'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
	return $term;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
add_filter( 'get_term', 'sync_category_tag_slugs', 10, 2 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
function _access_denied_splash() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
	if ( ! is_user_logged_in() || is_network_admin() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
	$blogs = get_blogs_of_user( get_current_user_id() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
	if ( wp_list_filter( $blogs, array( 'userblog_id' => get_current_blog_id() ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
	$blog_name = get_bloginfo( 'name' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
	if ( empty( $blogs ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
		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 ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
	$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
   537
	$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
   538
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
	$output .= '<h3>' . __('Your Sites') . '</h3>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
	$output .= '<table>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
	foreach ( $blogs as $blog ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
		$output .= "<tr>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
		$output .= "<td valign='top'>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
		$output .= "{$blog->blogname}";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
		$output .= "</td>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
		$output .= "<td valign='top'>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
		$output .= "<a href='" . esc_url( get_admin_url( $blog->userblog_id ) ) . "'>" . __( 'Visit Dashboard' ) . "</a> | <a href='" . esc_url( get_home_url( $blog->userblog_id ) ). "'>" . __( 'View Site' ) . "</a>" ;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
		$output .= "</td>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
		$output .= "</tr>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
	$output .= '</table>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
	wp_die( $output );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
add_action( 'admin_page_access_denied', '_access_denied_splash', 99 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
function check_import_new_users( $permission ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
	if ( !is_super_admin() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
add_filter( 'import_allow_create_users', 'check_import_new_users' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
// See "import_allow_fetch_attachments" and "import_attachment_size_limit" filters too.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
function mu_dropdown_languages( $lang_files = array(), $current = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
	$flag = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
	$output = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
	foreach ( (array) $lang_files as $val ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
		$code_lang = basename( $val, '.mo' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
		if ( $code_lang == 'en_US' ) { // American English
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
			$flag = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
			$ae = __( 'American English' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
			$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
   577
		} elseif ( $code_lang == 'en_GB' ) { // British English
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
			$flag = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
			$be = __( 'British English' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
			$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
   581
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
			$translated = format_code_lang( $code_lang );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
			$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
   584
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
	if ( $flag === false ) // WordPress english
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
		$output[] = '<option value=""' . selected( $current, '', false ) . '>' . __( 'English' ) . "</option>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
	// Order by name
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
	uksort( $output, 'strnatcasecmp' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
	 * Filter the languages available in the dropdown.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
	 * @since MU
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
	 * @param array $output     HTML output of the dropdown.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
	 * @param array $lang_files Available language files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
	 * @param string $current   The current language code.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
	$output = apply_filters( 'mu_dropdown_languages', $output, $lang_files, $current );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
	echo implode( "\n\t", $output );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
function site_admin_notice() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
	global $wp_db_version;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
	if ( !is_super_admin() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
	if ( get_site_option( 'wpmu_upgrade_site' ) != $wp_db_version )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
		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
   612
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
add_action( 'admin_notices', 'site_admin_notice' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
add_action( 'network_admin_notices', 'site_admin_notice' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
function avoid_blog_page_permalink_collision( $data, $postarr ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
	if ( is_subdomain_install() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
		return $data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
	if ( $data['post_type'] != 'page' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
		return $data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
	if ( !isset( $data['post_name'] ) || $data['post_name'] == '' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
		return $data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
	if ( !is_main_site() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
		return $data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
	$post_name = $data['post_name'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
	$c = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
	while( $c < 10 && get_id_from_blogname( $post_name ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
		$post_name .= mt_rand( 1, 10 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
		$c ++;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
	if ( $post_name != $data['post_name'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
		$data['post_name'] = $post_name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
	return $data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
add_filter( 'wp_insert_post_data', 'avoid_blog_page_permalink_collision', 10, 2 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
function choose_primary_blog() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
	<table class="form-table">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
	<tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
	<?php /* translators: My sites label */ ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
		<th scope="row"><?php _e( 'Primary Site' ); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
		<td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
		<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
		$all_blogs = get_blogs_of_user( get_current_user_id() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
		$primary_blog = get_user_meta( get_current_user_id(), 'primary_blog', true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
		if ( count( $all_blogs ) > 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
			$found = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
			?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
			<select name="primary_blog">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
				<?php foreach( (array) $all_blogs as $blog ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
					if ( $primary_blog == $blog->userblog_id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
						$found = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
					?><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
   657
				} ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
			</select>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
			<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
			if ( !$found ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
				$blog = array_shift( $all_blogs );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
				update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
		} elseif ( count( $all_blogs ) == 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
			$blog = array_shift( $all_blogs );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
			echo $blog->domain;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
			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
   668
				update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
			echo "N/A";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
		?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
		</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
	</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
	<?php if ( in_array( get_site_option( 'registration' ), array( 'all', 'blog' ) ) ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
		<tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
			<th scope="row" colspan="2" class="th-full">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
				<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
				$signup_url = network_site_url( 'wp-signup.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
				/** This filter is documented in wp-login.php */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
				?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
				<a href="<?php echo apply_filters( 'wp_signup_location', $signup_url ); ?>"><?php _e( 'Create a New Site' ); ?></a>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
			</th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
		</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
	<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
	</table>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
 * Grants Super Admin privileges.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
 * @param int $user_id ID of the user to be granted Super Admin privileges.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
function grant_super_admin( $user_id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
	global $super_admins;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
	// If global super_admins override is defined, there is nothing to do here.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
	if ( isset( $super_admins ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
		return false;
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
	 * Fires before the user is granted Super Admin privileges.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
	 * @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
   709
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
	do_action( 'grant_super_admin', $user_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
	// Directly fetch site_admins instead of using get_super_admins()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
	$super_admins = get_site_option( 'site_admins', array( 'admin' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
	$user = get_userdata( $user_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
	if ( $user && ! in_array( $user->user_login, $super_admins ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
		$super_admins[] = $user->user_login;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
		update_site_option( 'site_admins' , $super_admins );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
		 * Fires after the user is granted Super Admin privileges.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
		 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
		 * @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
   726
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
		do_action( 'granted_super_admin', $user_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
 * Revokes Super Admin privileges.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
 * @param int $user_id ID of the user Super Admin privileges to be revoked from.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
function revoke_super_admin( $user_id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
	global $super_admins;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
	// If global super_admins override is defined, there is nothing to do here.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
	if ( isset( $super_admins ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   745
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   747
	 * Fires before the user's Super Admin privileges are revoked.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
	 * @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
   752
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
	do_action( 'revoke_super_admin', $user_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
	// Directly fetch site_admins instead of using get_super_admins()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
	$super_admins = get_site_option( 'site_admins', array( 'admin' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
	$user = get_userdata( $user_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
	if ( $user && $user->user_email != get_site_option( 'admin_email' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
		if ( false !== ( $key = array_search( $user->user_login, $super_admins ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
			unset( $super_admins[$key] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
			update_site_option( 'site_admins', $super_admins );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
			/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
			 * Fires after the user's Super Admin privileges are revoked.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
			 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
			 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
			 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
			 * @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
   770
			 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
			do_action( 'revoked_super_admin', $user_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   772
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   775
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   778
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   779
 * Whether or not we can edit this network from this page
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   780
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   781
 * By default editing of network is restricted to the Network Admin for that site_id this allows for this to be overridden
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   784
 * @param integer $site_id The network/site ID to check.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   786
function can_edit_network( $site_id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   787
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   788
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   789
	if ( $site_id == $wpdb->siteid )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   790
		$result = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   791
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   792
		$result = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   793
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   794
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
	 * Filter whether this network can be edited from this page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
	 * @param bool $result  Whether the network can be edited from this page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
	 * @param int  $site_id The network/site ID to check.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
	return apply_filters( 'can_edit_network', $result, $site_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
 * Thickbox image paths for Network Admin.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   807
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   811
function _thickbox_path_admin_subfolder() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   813
<script type="text/javascript">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
//<![CDATA[
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
var tb_pathToImage = "../../wp-includes/js/thickbox/loadingAnimation.gif";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
//]]>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   817
</script>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
}