. */ class BpDev_BPProfile_Widget extends WP_Widget { function __construct() { parent::__construct( false, $name = __( 'BP Profile for Blogs', 'bpdev' ) ); } function widget($args, $instance) { extract( $args ); echo $before_widget; echo $before_title . $instance['title'] . $after_title; BpDev_BPProfile_Widget::bpdev_show_blog_profile($instance);/*** show the profile fields**/ echo $after_widget; } function update( $new_instance, $old_instance ) { $instance = $old_instance; foreach($new_instance as $key=>$val) $instance[$key]=$val;//update the instance return $instance; } function form( $instance ) { $instance = wp_parse_args( (array) $instance, array( 'title' => __('My Profile','bpdev'), 'show_avatar' => "yes",'user_role'=>'administrator') ); $title = strip_tags( $instance['title'] ); extract($instance,EXTR_SKIP); ?>

>Show >Hide
'administrator')){ global $wpdb,$current_blog; $blog_prefix = $wpdb->get_blog_prefix($current_blog->blog_id); $role_sql = "SELECT user_id, meta_value FROM $wpdb->usermeta WHERE meta_key = '{$blog_prefix}capabilities' ORDER BY {$wpdb->usermeta}.user_id" ; $role=$wpdb->get_results($wpdb->prepare($role_sql),ARRAY_A); //clean the role $all_user=array_map("bpdev_serialize_role",$role);//we are unserializing the role to make that as an array $users=array(); foreach($all_user as $key=>$user_info){ foreach ($user_roles as $user_role){ if($user_info['meta_value'][$user_role]==1)//if the role is admin $users[]=$user_info['user_id']; continue ; } } return $users; } function get_users($user_role=null){ global $wpdb,$current_blog; $blog_prefix = $wpdb->get_blog_prefix($current_blog->blog_id); $role_sql = "SELECT user_id, meta_value FROM $wpdb->usermeta WHERE meta_key = '{$blog_prefix}capabilities' ORDER BY {$wpdb->usermeta}.user_id" ; $role=$wpdb->get_results($wpdb->prepare($role_sql),ARRAY_A); //clean the role $all_user=array_map("bpdev_serialize_role",$role);//we are unserializing the role to make that as an array $users=array(); foreach($all_user as $key=>$user_info) if($user_info['meta_value'][$user_role]==1)//if the role is admin $users[]=$user_info['user_id']; return $users; } function get_admin_users_for_current_blog() { global $wpdb,$current_blog; // $memers=BpDev_BPProfile_Widget::get_users_with_roles(array("administrator")); // $roles= return BpDev_BPProfile_Widget::get_admins(); } function bpdev_show_blog_profile($instance){ //if buddypress is not active, return if(!function_exists("bp_get_root_domain")) return; $show_avatar=$instance["show_avatar"];//we need to preserve for multi admin $user_role=$instance['user_role']; unset($instance["show_avatar"]); unset($instance["title"]);//unset the title of the widget,because we will be iterating over the instance fields unset($instance['user_role']);//unset the title of the widget,because we will be iterating over the instance fields global $current_blog; $users=apply_filters("bp_profile_for_users",BpDev_BPProfile_Widget::get_users($user_role));//may be we can improve it too if(empty($users)) return; foreach($users as $user){ /*** we many not need this loop if the blog has single owner and /or we just want to show a single users profile */ $user_id=$user;//["user_id"]; $op=""; if($show_avatar=="yes") $op.=""; //bad approach, because buddypress does not allow to fetch the field name from field key if ( function_exists( 'bp_has_profile' ) ) : if ( bp_has_profile( "user_id=".$user_id ) ) : while ( bp_profile_groups() ) : bp_the_profile_group(); while ( bp_profile_fields() ) : bp_the_profile_field(); $fld_name=bp_get_the_profile_field_input_name(); if(array_key_exists($fld_name,$instance)&&$instance[$fld_name]=="yes") $op.=""; endwhile; endwhile; endif; endif; $op.="
".bp_core_get_userlink($user_id) ."".bp_core_fetch_avatar(array("item_id"=>$user_id,"type"=>"thumb"))."
".bp_get_the_profile_field_name()."".bp_get_profile_field_data(array('field'=>bp_get_the_profile_field_id(),'user_id'=>$user_id))."
"; echo $op; } } } /** Let us register the widget*/ function bpdev_register_bpprofile_for_blogs_widgets() { add_action('widgets_init', create_function('', 'return register_widget("BpDev_BPProfile_Widget");') ); } add_action( 'bp_loaded', 'bpdev_register_bpprofile_for_blogs_widgets' ); function bpdev_serialize_role($roles){ $roles['meta_value']=maybe_unserialize($roles['meta_value']); return $roles; } ?>