dimitris (January 30th, 2013)
/** * ADD ROLE TO ALL BLOGS - START */ // hook to user register add_filter( 'user_register', 'jr_user_register_role_all_blogs'); // Add selected role to all blogs function jr_user_register_role_all_blogs( $user_id ) { global $posted; foreach( jr_msum_get_blog_list( 0, 'all' ) as $key => $blog ) { if( is_user_member_of_blog( $user_id, $blog[ 'blog_id' ] ) ) continue; switch_to_blog( $blog[ 'blog_id' ] ); if ( !empty( $posted['role'] ) ) add_user_to_blog( $blog[ 'blog_id' ], $user_id, $posted['role'] ); else add_user_to_blog( $blog[ 'blog_id' ], $user_id, 'job_lister' ); restore_current_blog(); } update_user_meta( $user_id, 'msum_has_caps', 'true' ); } /** * Based on the deprecated WPMU get_blog_list function. * * Except this function gets all blogs, even if they are marked as mature and private. */ function jr_msum_get_blog_list( $start = 0, $num = 10 ) { global $wpdb; $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND archived = '0' AND spam = '0' AND deleted = '0' ORDER BY registered DESC", $wpdb->siteid ), ARRAY_A ); foreach ( (array) $blogs as $details ) { $blog_list[ $details[ 'blog_id' ] ] = $details; $blog_list[ $details[ 'blog_id' ] ]['postcount'] = $wpdb->get_var( "SELECT COUNT(ID) FROM " . $wpdb->get_blog_prefix( $details['blog_id'] ). "posts WHERE post_status='publish' AND post_type='post'" ); } unset( $blogs ); $blogs = $blog_list; if ( false == is_array( $blogs ) ) return array(); if ( $num == 'all' ) return array_slice( $blogs, $start, count( $blogs ) ); else return array_slice( $blogs, $start, $num ); } /** * ADD ROLE TO ALL BLOGS - END */
dimitris (January 30th, 2013)
There are currently 1 users browsing this thread. (0 members and 1 guests)