update( $wpdb->users, array( $pref => $value ), array( 'ID' => $id ) );
+ if ( null !== $deprecated )
+ _deprecated_argument( __FUNCTION__, '3.1' );
+
+ $wpdb->update( $wpdb->users, array( sanitize_key( $pref ) => $value ), array( 'ID' => $id ) );
- if ( $refresh == 1 )
- refresh_user_details( $id );
+ $user = new WP_User( $id );
+ clean_user_cache( $user );
if ( $pref == 'spam' ) {
- if ( $value == 1 )
+ if ( $value == 1 ) {
+ /**
+ * Fires after the user is marked as a SPAM user.
+ *
+ * @since 3.0.0
+ *
+ * @param int $id ID of the user marked as SPAM.
+ */
do_action( 'make_spam_user', $id );
- else
+ } else {
+ /**
+ * Fires after the user is marked as a HAM user. Opposite of SPAM.
+ *
+ * @since 3.0.0
+ *
+ * @param int $id ID of the user marked as HAM.
+ */
do_action( 'make_ham_user', $id );
+ }
}
return $value;
}
+/**
+ * Cleans the user cache for a specific user.
+ *
+ * @since 3.0.0
+ *
+ * @param int $id The user ID.
+ * @return bool|int The ID of the refreshed user or false if the user does not exist.
+ */
function refresh_user_details( $id ) {
$id = (int) $id;
if ( !$user = get_userdata( $id ) )
return false;
- clean_user_cache( $id );
+ clean_user_cache( $user );
return $id;
}
+/**
+ * Returns the language for a language code.
+ *
+ * @since 3.0.0
+ *
+ * @param string $code Optional. The two-letter language code. Default empty.
+ * @return string The language corresponding to $code if it exists. If it does not exist,
+ * then the first two letters of $code is returned.
+ */
function format_code_lang( $code = '' ) {
$code = strtolower( substr( $code, 0, 2 ) );
$lang_codes = array(
@@ -581,10 +597,31 @@ function format_code_lang( $code = '' ) {
'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',
'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',
've' => 'Venda', 'vi' => 'Vietnamese', 'vo' => 'Volapük', 'cy' => 'Welsh','wa' => 'Walloon','wo' => 'Wolof', 'xh' => 'Xhosa', 'yi' => 'Yiddish', 'yo' => 'Yoruba', 'za' => 'Zhuang; Chuang', 'zu' => 'Zulu' );
+
+ /**
+ * Filter the language codes.
+ *
+ * @since MU
+ *
+ * @param array $lang_codes Key/value pair of language codes where key is the short version.
+ * @param string $code A two-letter designation of the language.
+ */
$lang_codes = apply_filters( 'lang_codes', $lang_codes, $code );
return strtr( $code, $lang_codes );
}
+/**
+ * Synchronize category and post tag slugs when global terms are enabled.
+ *
+ * @since 3.0.0
+ *
+ * @param object $term The term.
+ * @param string $taxonomy The taxonomy for $term. Should be 'category' or 'post_tag', as these are
+ * the only taxonomies which are processed by this function; anything else
+ * will be returned untouched.
+ * @return object|array Returns `$term`, after filtering the 'slug' field with {@see sanitize_title()}
+ * if $taxonomy is 'category' or 'post_tag'.
+ */
function sync_category_tag_slugs( $term, $taxonomy ) {
if ( global_terms_enabled() && ( $taxonomy == 'category' || $taxonomy == 'post_tag' ) ) {
if ( is_object( $term ) ) {
@@ -595,54 +632,70 @@ function sync_category_tag_slugs( $term, $taxonomy ) {
}
return $term;
}
-add_filter( 'get_term', 'sync_category_tag_slugs', 10, 2 );
-function redirect_user_to_blog() {
- $c = 0;
- if ( isset( $_GET['c'] ) )
- $c = (int) $_GET['c'];
+/**
+ * Displays an access denied message when a user tries to view a site's dashboard they
+ * do not have access to.
+ *
+ * @since 3.2.0
+ * @access private
+ */
+function _access_denied_splash() {
+ if ( ! is_user_logged_in() || is_network_admin() )
+ return;
- if ( $c >= 5 ) {
- wp_die( __( "You don’t have permission to view this site. Please contact the system administrator." ) );
- }
- $c ++;
+ $blogs = get_blogs_of_user( get_current_user_id() );
- $blog = get_active_blog_for_user( get_current_user_id() );
- $dashboard_blog = get_dashboard_blog();
- if ( is_object( $blog ) ) {
- wp_redirect( get_admin_url( $blog->blog_id, '?c=' . $c ) ); // redirect and count to 5, "just in case"
- exit;
- }
+ if ( wp_list_filter( $blogs, array( 'userblog_id' => get_current_blog_id() ) ) )
+ return;
- /*
- If the user is a member of only 1 blog and the user's primary_blog isn't set to that blog,
- then update the primary_blog record to match the user's blog
- */
- $blogs = get_blogs_of_user( get_current_user_id() );
+ $blog_name = get_bloginfo( 'name' );
- if ( !empty( $blogs ) ) {
- foreach( $blogs as $blogid => $blog ) {
- if ( $blogid != $dashboard_blog->blog_id && get_user_meta( get_current_user_id() , 'primary_blog', true ) == $dashboard_blog->blog_id ) {
- update_user_meta( get_current_user_id(), 'primary_blog', $blogid );
- continue;
- }
- }
- $blog = get_blog_details( get_user_meta( get_current_user_id(), 'primary_blog', true ) );
- wp_redirect( get_admin_url( $blog->blog_id, '?c=' . $c ) );
- exit;
+ if ( empty( $blogs ) )
+ wp_die( sprintf( __( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ), $blog_name ), 403 );
+
+ $output = '
' . sprintf( __( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ), $blog_name ) . '
';
+ $output .= '
' . __( 'If you reached this screen by accident and meant to visit one of your own sites, here are some shortcuts to help you find your way.' ) . '
', esc_html( $url ) );
- }
+ echo implode( "\n\t", $output );
}
-add_action( 'admin_notices', 'admin_notice_feed' );
+/**
+ * Displays an admin notice to upgrade all sites after a core upgrade.
+ *
+ * @since 3.0.0
+ *
+ * @global int $wp_db_version The version number of the database.
+ *
+ * @return false False if the current user is not a super admin.
+ */
function site_admin_notice() {
global $wp_db_version;
if ( !is_super_admin() )
return false;
if ( get_site_option( 'wpmu_upgrade_site' ) != $wp_db_version )
- echo "
" . sprintf( __( 'Thank you for Updating! Please visit the Update Network page to update all your sites.' ), esc_url( admin_url( 'ms-upgrade-network.php' ) ) ) . "
";
+ echo "
" . sprintf( __( 'Thank you for Updating! Please visit the Upgrade Network page to update all your sites.' ), esc_url( network_admin_url( 'upgrade.php' ) ) ) . "
";
}
-add_action( 'admin_notices', 'site_admin_notice' );
+/**
+ * Avoids a collision between a site slug and a permalink slug.
+ *
+ * In a subdirectory install this will make sure that a site and a post do not use the
+ * same subdirectory by checking for a site with the same name as a new post.
+ *
+ * @since 3.0.0
+ *
+ * @param array $data An array of post data.
+ * @param array $postarr An array of posts. Not currently used.
+ * @return array The new array of post data after checking for collisions.
+ */
function avoid_blog_page_permalink_collision( $data, $postarr ) {
if ( is_subdomain_install() )
return $data;
@@ -756,14 +788,21 @@ function avoid_blog_page_permalink_collision( $data, $postarr ) {
}
return $data;
}
-add_filter( 'wp_insert_post_data', 'avoid_blog_page_permalink_collision', 10, 2 );
+/**
+ * Handles the display of choosing a user's primary site.
+ *
+ * This displays the user's primary site and allows the user to choose
+ * which site is primary.
+ *
+ * @since 3.0.0
+ */
function choose_primary_blog() {
?>
-
+
1 ) {
$found = false;
?>
-
userblog_id );
}
} elseif ( count( $all_blogs ) == 1 ) {
- $blog = array_shift( $all_blogs );
- echo $blog->domain;
+ $blog = reset( $all_blogs );
+ echo esc_url( get_home_url( $blog->userblog_id ) );
if ( $primary_blog != $blog->userblog_id ) // Set the primary blog again if it's out of sync with blog list.
update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
} else {
@@ -794,69 +833,51 @@ function choose_primary_blog() {
?>
-
-
-
-
-
-
-
" . sprintf( __( "Warning! The current theme supports Featured Images. You must enable image uploads on the options page for it to work." ), esc_url( admin_url( 'ms-options.php' ) ) ) . "";
- }
-}
-add_action( 'admin_notices', 'show_post_thumbnail_warning' );
-
-function ms_deprecated_blogs_file() {
- if ( ! is_super_admin() )
- return;
- if ( ! file_exists( WP_CONTENT_DIR . '/blogs.php' ) )
- return;
- echo '
' . sprintf( __( 'The %1$s file is deprecated. Please remove it and update your server rewrite rules to use %2$s instead.' ), 'wp-content/blogs.php', 'wp-includes/ms-files.php' ) . '
';
-}
-add_action( 'admin_notices', 'ms_deprecated_blogs_file' );
-
/**
- * Outputs the notice message for multisite regarding activation of plugin page.
+ * Grants Super Admin privileges.
*
* @since 3.0.0
- * @return none
- */
-function _admin_notice_multisite_activate_plugins_page() {
- $message = sprintf( __( 'The plugins page is not visible to normal users. It must be activated first. %s' ), '' . __( 'Activate' ) . '' );
- echo "
$message
";
-}
-
-/**
- * Grants super admin privileges.
*
- * @since 3.0.0
- * @param $user_id
+ * @global array $super_admins
+ *
+ * @param int $user_id ID of the user to be granted Super Admin privileges.
+ * @return bool True on success, false on failure. This can fail when the user is
+ * already a super admin or when the `$super_admins` global is defined.
*/
function grant_super_admin( $user_id ) {
- global $super_admins;
-
// If global super_admins override is defined, there is nothing to do here.
- if ( isset($super_admins) )
+ if ( isset( $GLOBALS['super_admins'] ) ) {
return false;
+ }
+ /**
+ * Fires before the user is granted Super Admin privileges.
+ *
+ * @since 3.0.0
+ *
+ * @param int $user_id ID of the user that is about to be granted Super Admin privileges.
+ */
do_action( 'grant_super_admin', $user_id );
// Directly fetch site_admins instead of using get_super_admins()
$super_admins = get_site_option( 'site_admins', array( 'admin' ) );
- $user = new WP_User( $user_id );
- if ( ! in_array( $user->user_login, $super_admins ) ) {
+ $user = get_userdata( $user_id );
+ if ( $user && ! in_array( $user->user_login, $super_admins ) ) {
$super_admins[] = $user->user_login;
update_site_option( 'site_admins' , $super_admins );
+
+ /**
+ * Fires after the user is granted Super Admin privileges.
+ *
+ * @since 3.0.0
+ *
+ * @param int $user_id ID of the user that was granted Super Admin privileges.
+ */
do_action( 'granted_super_admin', $user_id );
return true;
}
@@ -864,32 +885,228 @@ function grant_super_admin( $user_id ) {
}
/**
- * Revokes super admin privileges.
+ * Revokes Super Admin privileges.
*
* @since 3.0.0
- * @param $user_id
+ *
+ * @global array $super_admins
+ *
+ * @param int $user_id ID of the user Super Admin privileges to be revoked from.
+ * @return bool True on success, false on failure. This can fail when the user's email
+ * is the network admin email or when the `$super_admins` global is defined.
*/
function revoke_super_admin( $user_id ) {
- global $super_admins;
-
// If global super_admins override is defined, there is nothing to do here.
- if ( isset($super_admins) )
+ if ( isset( $GLOBALS['super_admins'] ) ) {
return false;
+ }
+ /**
+ * Fires before the user's Super Admin privileges are revoked.
+ *
+ * @since 3.0.0
+ *
+ * @param int $user_id ID of the user Super Admin privileges are being revoked from.
+ */
do_action( 'revoke_super_admin', $user_id );
// Directly fetch site_admins instead of using get_super_admins()
$super_admins = get_site_option( 'site_admins', array( 'admin' ) );
- $user = new WP_User( $user_id );
- if ( $user->user_email != get_site_option( 'admin_email' ) ) {
+ $user = get_userdata( $user_id );
+ if ( $user && 0 !== strcasecmp( $user->user_email, get_site_option( 'admin_email' ) ) ) {
if ( false !== ( $key = array_search( $user->user_login, $super_admins ) ) ) {
unset( $super_admins[$key] );
update_site_option( 'site_admins', $super_admins );
+
+ /**
+ * Fires after the user's Super Admin privileges are revoked.
+ *
+ * @since 3.0.0
+ *
+ * @param int $user_id ID of the user Super Admin privileges were revoked from.
+ */
do_action( 'revoked_super_admin', $user_id );
return true;
}
}
return false;
}
+
+/**
+ * Whether or not we can edit this network from this page.
+ *
+ * By default editing of network is restricted to the Network Admin for that `$site_id`
+ * this allows for this to be overridden.
+ *
+ * @since 3.1.0
+ *
+ * @global wpdb $wpdb WordPress database abstraction object.
+ *
+ * @param int $site_id The network/site ID to check.
+ * @return bool True if network can be edited, otherwise false.
+ */
+function can_edit_network( $site_id ) {
+ global $wpdb;
+
+ if ( $site_id == $wpdb->siteid )
+ $result = true;
+ else
+ $result = false;
+
+ /**
+ * Filter whether this network can be edited from this page.
+ *
+ * @since 3.1.0
+ *
+ * @param bool $result Whether the network can be edited from this page.
+ * @param int $site_id The network/site ID to check.
+ */
+ return apply_filters( 'can_edit_network', $result, $site_id );
+}
+
+/**
+ * Thickbox image paths for Network Admin.
+ *
+ * @since 3.1.0
+ *
+ * @access private
+ */
+function _thickbox_path_admin_subfolder() {
?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+