'top_members', 'description' => __('A widget that sums the top members on your blog', 'top_members') ); /* Widget control settings. */ $control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'top_members' ); /* Create the widget. */ $this->WP_Widget( 'top_members' , __( 'Top Members' , 'top_members' ), $widget_ops, $control_ops ); } /** * This is the part where the heart of this widget is! * here we get al the members and count their posts. * * The frontend function */ function widget( $args, $instance ) { global $bp; extract( $args ); // default values $exclude_admin = false; $exclude_zero = false; /* Our variables from the widget settings. (nice tabbed huh!?)*/ if(isset($instance)) { if( isset( $instance[ 'title' ] ) ) { $title = apply_filters( 'widget_title', $instance[ 'title' ] ); } if( isset( $instance[ 'number' ]) ) { $number_of_authors = $instance[ 'number' ]; } if( isset( $instance[ 'template' ] ) ) { $template = htmlspecialchars_decode( $instance[ 'template' ] ); } if( isset( $instance[ 'before' ] ) ) { $before_the_list = htmlspecialchars_decode( $instance[ 'before' ] ); } if( isset( $instance[ 'after' ] ) ) { $after_the_list = htmlspecialchars_decode( $instance [ 'after' ] ); } if( isset( $instance[ 'gravatar_size' ] ) ) { $gravatar_size = $instance[ 'gravatar_size' ]; } if( isset( $instance[ 'exclude_admin' ] ) ) { $exclude_admin = $instance[ 'exclude_admin' ]; } if( isset( $instance[ 'exclude_zero' ] ) ) { $exclude_zero = $instance[ 'exclude_zero' ]; } if( isset( $instance[ 'linkbase'] ) ) { $author_slug = $instance[ 'linkbase' ]; } if( isset( $instance[ 'author_link' ] ) ) { $author_link = $instance[ 'author_link' ]; } } if( !isset( $author_slug ) ) { $author_slug = 'author' ; } if( !isset( $author_link ) ) { $author_link = 'username' ;} // define vars $counter=0; /* Before widget (defined by themes). */ if( isset( $before_widget ) ) { echo $before_widget; } /* Display the widget title if one was input (before and after defined by themes). */ if( isset( $title ) ) { if (strlen($title) > 0) echo $before_title . $title . $after_title; } $user_list = array(); $blogusers = get_users(); // doh // this part can be a heavyload process if you have a lot of members if ( $blogusers ) { foreach ( $blogusers as $bloguser ) { $user_list[] = $bloguser->ID; } // replaced deprecated wp-function (http://codex.wordpress.org/Function_Reference/get_usernumposts) $posts = count_many_users_posts( $user_list, 'ia_invites' ); arsort( $posts ); //use asort($user_list) if ascending by post count is desired // user defined html element before the list if( $user_list ) { echo $before_the_list; } if( count( $user_list ) < $number_of_authors ) { $number_of_authors=count($user_list); } foreach($posts as $userid => $post) { $counter++; if($counter>$number_of_authors) { break; } // create a WP user object $user = new WP_User( $userid ); // detect if user is administrator if( isset( $user->wp_capabilities[ 'administrator' ] ) || isset( $user->blog_capabilities[ 'administrator' ] ) ){ $user_is_admin = true; } else { $user_is_admin = false; } $author_posts_url = get_author_posts_url($userid); if(!$user->user_firstname && !$user->user_lastname) { $user->user_firstname = $user->user_login; } $invite_anyone_link = ''; if (bp_is_active(BP_INVITE_ANYONE_SLUG) ) : $_link = $bp->loggedin_user->domain . $bp->invite_anyone->slug . '/'; $invite_anyone_link = '' . __( 'Invite your friends' ) . ''; endif; //replace anchors in usertemplate //author_slug / display_name // linkbase - author_link $arr_replace['username'] = $user->user_login; $arr_replace['nickname'] = $user->nickname; $arr_replace['display_name'] = $user->display_name; $output = str_replace("%linktoposts%",get_bloginfo("url") .'/'.$author_slug.'/'.str_replace(" ","-",strtolower($arr_replace[$author_link])),$template); $output = str_replace("%firstname%",$user->user_firstname,$output); $output = str_replace("%lastname%",$user->user_lastname,$output); $output = str_replace("%nrofposts%",$post,$output); $output = str_replace("%nickname%",$user->user_login,$output); $output = str_replace("%displayname%",$user->display_name,$output); $output = str_replace("%invitefriends%",$invite_anyone_link,$output); $gravatar_detect = strpos($output,"%gravatar%"); if($gravatar_detect !== false){ $gravatar = get_avatar($user->ID, $gravatar_size); $gravatar = str_replace("bpthumb", "bpfull",$gravatar); $output = str_replace("%gravatar%",$gravatar,$output); } if(($user_is_admin && $exclude_admin == "on") || ($post<1 && $exclude_zero=="on")) { // aiii we skipped a user but we still want to get the total number of users right! $counter--; } else { // newline in html, al for the looks! echo $output ."\n"; } } // user defined html after the list if($user_list){echo $after_the_list;} } /* After widget (defined by themes). */ echo $after_widget; } /** * Update the widget settings. * * Backend widget settings */ function update( $new_instance, $old_instance ) { $instance = $old_instance; /* Strip tags for title and name to remove HTML (important for text inputs). */ $instance['title'] = strip_tags( $new_instance['title'] ); // htmlspecialchars to save html markup in database, at frontend we use htmlspecialchars_decode $instance['template'] = htmlspecialchars($new_instance['template']); $instance['linkbase'] = $new_instance['linkbase']; $instance['author_link'] = $new_instance['author_link']; $instance['before'] = htmlspecialchars($new_instance['before']); $instance['after'] = htmlspecialchars($new_instance['after']); $instance['exclude_admin'] = $new_instance['exclude_admin']; $instance['exclude_zero'] = $new_instance['exclude_zero']; // check if datainput isnummeric if(is_numeric($new_instance['gravatar_size'])) { $instance['gravatar_size'] = $new_instance['gravatar_size']; } // check if datainput isnummeric and postive and under 100 if(is_numeric($new_instance['number'])) { if($new_instance['number'] <100 && $new_instance['number'] >0) { $instance['number'] = $new_instance['number']; } else { if($new_instance['number'] < 1) { $instance['number'] = 1; } else { $instance['number'] = 99; } } } return $instance; } /** * Displays the widget settings controls on the widget panel. * * Backend widget options form */ function form( $instance ) { $defaults = array( 'title' => __( 'Top Members', 'top_members'), 'number' => __(1, 'top_members'), 'template' => __('
/>
/>
Linkbase and auhtor link used to find your author page. (don't touch in default WP config). You will need this when using a plugin like author_slug.
example how used www.example.com/slug/author_link