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 +588,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 +623,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 +779,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() {
?>