WP hooks navigation: Home/browse • Actions index • Filters index
To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).
The best way to understand what a hook does is to look at where it occurs in the source code.
do_action( "hook_name" )apply_filters( "hook_name", "what_to_filter" ).Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.
This hook occurs 2 times in this file.
| Line | Code |
|---|---|
| 38 | return false; |
| 39 | } |
| 40 | |
| 41 | function get_blogs_of_user( $id, $all = false ) { |
| 42 | global $wpdb; |
| 43 | |
| 44 | $cache_suffix = $all ? '_all' : '_short'; |
| 45 | $return = wp_cache_get( 'blogs_of_user_' . $id . $cache_suffix, 'users' ); |
| 46 | if ( $return ) |
| 47 | return apply_filters( 'get_blogs_of_user', $return, $id, $all ); |
| 48 | |
| 49 | $user = get_userdata( (int) $id ); |
| 50 | if ( !$user ) |
| 51 | return false; |
| 52 | |
| 53 | $blogs = $match = array(); |
| 54 | $prefix_length = strlen($wpdb->base_prefix); |
| 55 | foreach ( (array) $user as $key => $value ) { |
| 56 | if ( $prefix_length && substr($key, 0, $prefix_length) != $wpdb->base_prefix ) |
| Line | Code |
| 69 | $blogs[ $blog_id ]->domain = $blog->domain; |
| 70 | $blogs[ $blog_id ]->path = $blog->path; |
| 71 | $blogs[ $blog_id ]->site_id = $blog->site_id; |
| 72 | $blogs[ $blog_id ]->siteurl = $blog->siteurl; |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | wp_cache_add( 'blogs_of_user_' . $id . $cache_suffix, $blogs, 'users', 5 ); |
| 78 | return apply_filters( 'get_blogs_of_user', $blogs, $id, $all ); |
| 79 | } |
| 80 | |
| 81 | function get_active_blog_for_user( $user_id ) { // get an active blog for user - either primary blog or from blogs list |
| 82 | global $wpdb; |
| 83 | $blogs = get_blogs_of_user( $user_id ); |
| 84 | if ( empty( $blogs ) ) { |
| 85 | $details = get_dashboard_blog(); |
| 86 | add_user_to_blog( $details->blog_id, $user_id, 'subscriber' ); |
| 87 | update_user_meta( $user_id, 'primary_blog', $details->blog_id ); |