ID); $author->first_name = $author_data->first_name; $author->last_name = $author_data->last_name; } function widget_authors_sort_by_id($a, $b) { return 0 + $a->ID - $b->ID; } function widget_authors_sort_by_first_name($a, $b) { $cmp_first_name = strcmp($a->first_name, $b->first_name); return $cmp_first_name !== 0 ? $cmp_first_name : strcmp($a->last_name, $b->last_name); } function widget_authors_sort_by_last_name($a, $b) { $cmp_last_name = strcmp($a->last_name, $b->last_name); return $cmp_last_name !== 0 ? $cmp_last_name : strcmp($a->first_name, $b->first_name); } function widget_authors_sort_by_posts($a, $b) { $matches = array(); preg_match('#\(([0-9]*)\)#', $a, $matches); $aC = is_array($matches) && count($matches) >= 2 ? intval($matches[1]) : 0; preg_match('#\(([0-9]*)\)#', $b, $matches); $bC = is_array($matches) && count($matches) >= 2 ? intval($matches[1]) : 0; return $aC < $bC ? 1 : -1; } function widget_authors_sort_by_random($a, $b) { return rand(-1,1); } function widget_authors_sort_by($orderby, &$authors) { # if ('first_name' != $orderby && 'last_name' != $orderby) { # return; # } switch ($orderby) { case 'first_name': array_walk($authors, 'widget_authors_add_last_name'); usort($authors, 'widget_authors_sort_by_first_name'); break; case 'last_name': array_walk($authors, 'widget_authors_add_last_name'); usort($authors, 'widget_authors_sort_by_last_name'); break; case 'id': usort($authors, 'widget_authors_sort_by_id'); break; case 'random': usort($authors, 'widget_authors_sort_by_random'); break; # case 'posts': # usort($authors, 'widget_authors_sort_by_posts'); # break; } } function widget_authors_order_by($args) { $count = $args['optioncount']; $args['optioncount'] = 1; $arr = array_slice(explode('
  • ', widget_authors_list_authors($args)), 1); switch ($args['orderby']) { case 'posts': usort($arr, 'widget_authors_sort_by_posts');break; default: } if ('0' == $count) { array_walk($arr, 'widget_authors_format', 'no-count'); } if ($args['limit']) { $arr = array_slice($arr, 0, $args['limit']); } return $arr; } if ( function_exists('seo_tag_cloud_generate') ) : function widget_authors_cloud($args = '') { $defaults = array( 'optioncount' => false, 'exclude_admin' => true, 'show_fullname' => false, 'hide_empty' => true, 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true, 'limit' => 0, 'em_step' => 0.1, 'orderby' => 'name', 'exclude' => '"0"', 'include' => '', ); $r = wp_parse_args( $args, $defaults ); extract($r, EXTR_SKIP); $return = ''; $authors = widget_authors_get_authors( $include, $exclude ); $author_count = widget_authors_count_authors ( $authors ); widget_authors_sort_by($orderby, $authors); foreach ( (array) $authors as $key => $author ) { $posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0; if ( $posts != 0 || !$hide_empty ) { $author = get_userdata( $author->ID ); if ($exclude_admin && 10 == $author->user_level) continue; $name = $author->display_name; if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') ) $name = $author->first_name . ' ' . $author->last_name; if ( $posts == 0 ) { if ( !$hide_empty ) $link = ''; } else { $link = get_author_posts_url($author->ID, $author->user_nicename); } $authors[$key]->name = $name; $authors[$key]->count = $posts; $authors[$key]->link = $link; $authors[$key]->extra = $optioncount ? '('.$posts.')' : ''; } else unset($authors[$key]); } $args['number'] = $limit; $return = seo_tag_cloud_generate( $authors, $args ); // Here's where those top tags get sorted according to $args echo $return; } endif; function widget_authors_format(&$val, $i, $format) { switch ($format) { case 'no-count': $val = preg_replace('#\(\s*([0-9]*)\)
  • #', '', $val); break; } } function widget_authors_dropdown($args = '') { $args['echo'] = false; unset($args['feed']); $arr = widget_authors_order_by($args); $options = ''; foreach ($arr as $author) { preg_match('#]*>([^<]*)( \(([0-9]*)\))?#', $author, $matches); $options .= ''."\n"; } unset($arr); $dropdown = ''; echo $dropdown; } /** * List all the authors of the blog, with several options available. * * * * @link http://codex.wordpress.org/Template_Tags/wp_list_authors * @since 1.2.0 * @param array $args The argument array. * @return null|string The output, if echo is set to false. */ function widget_authors_list_authors($args = '') { $defaults = array( 'optioncount' => false, 'exclude_admin' => true, 'show_fullname' => false, 'hide_empty' => true, 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true, 'style' => 'list', 'html' => true, 'show_avatar' => false, 'avatar_size' => 32, 'orderby' => 'name', 'exclude' => '"0"', 'include' => '', ); $r = wp_parse_args( $args, $defaults ); extract($r, EXTR_SKIP); $return = ''; $authors = widget_authors_get_authors( $include, $exclude); $author_count = widget_authors_count_authors ( $authors ); widget_authors_sort_by($orderby, $authors); foreach ( (array) $authors as $author ) { $link = ''; $author = get_userdata( $author->ID ); if ($exclude_admin && 10 == $author->user_level) continue; $posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0; $name = $author->display_name; $email = $author->user_email; $avatar = get_avatar($email, $avatar_size); if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') ) { $name = $author->first_name . ' ' . $author->last_name; } if( !$html ) { if ( $posts == 0 ) { if ( ! $hide_empty ) $return .= $name . ', '; } else $return .= $name . ', '; // No need to go further to process HTML. continue; } if ( !($posts == 0 && $hide_empty) && 'list' == $style ) $return .= '
  • '; if ( $posts == 0 ) { if ( ! $hide_empty ) $link = $name; } else { $link = ''; if ( $show_avatar && !empty($avatar) ) $link .= $avatar; $link .= 'display_name) ) . '">' . $name . ''; if ( (! empty($feed_image)) || (! empty($feed)) ) { $link .= ' '; if (empty($feed_image)) $link .= '('; $link .= ''; else $link .= $name; $link .= ''; if ( empty($feed_image) ) $link .= ')'; } if ( $optioncount ) $link .= ' ('. $posts . ')'; } if ( !($posts == 0 && $hide_empty) && 'list' == $style ) $return .= $link . '
  • '."\n"; else if ( ! $hide_empty ) $return .= $link . ', '; } $return = trim($return, ', '); if ( ! $echo ) return $return; echo $return; } function widget_authors($args, $widget_args = 1) { extract($args, EXTR_SKIP); if ( is_numeric($widget_args) ) $widget_args = array( 'number' => $widget_args ); $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); extract($widget_args, EXTR_SKIP); $options = get_option('widget_authors'); if (isset($options[$number])) $options = $options[$number]; $options = wp_parse_args($args, $options); # if (!isset($options[$number])) # return; $title = empty($options['title']) ? __('Authors','authors') : apply_filters('widget_title', $options['title']); $format = $options['format']; $order = $options['order']; $limit = $options['limit']; $show_fullname = $options['show_fullname'] ? '1' : '0'; $show_avatar = $options['show_avatar'] ? '1' : '0'; $avatar_size = $options['avatar_size']; $feedlink = $options['feedlink'] ? '1' : '0'; $count = $options['count'] ? '1' : '0'; $exclude_admin = $options['exclude_admin'] ? '1' : '0'; $exclude = !empty($options['exclude']) ? $options['exclude'] : '"0"'; $include = !empty($options['include']) ? $options['include'] : ''; $show_credit = $options['show_credit'] ? '1' : '0'; ?> $order, 'limit'=>$limit, 'show_fullname'=>$show_fullname, 'show_avatar'=>$show_avatar, 'avatar_size'=>$avatar_size, 'optioncount'=>$count, 'exclude_admin'=>$exclude_admin, 'exclude'=>$exclude, 'include'=>$include, 'hide_empty'=>1); if ($feedlink) { $list_args['feed'] = 'RSS'; $list_args['feed_image'] = ''; } if ('cloud' == $format && function_exists('seo_tag_cloud_generate')) { widget_authors_cloud($list_args); } elseif ('ball' == $format && function_exists('seo_tag_cloud_generate')) { $list_args['format'] = 'ball'; widget_authors_cloud($list_args); } elseif ('dropdown' == $format) { widget_authors_dropdown($list_args); } else /*if ('list' == $format)*/ { $list_args['echo'] = false; $arr = widget_authors_order_by($list_args); echo ''; } ?> '.__('Powered by %s','authors').'', ''.__('Authors Widget','authors').'');?> $widget_args ); $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); extract($widget_args, EXTR_SKIP); $options = get_option('widget_authors'); if ( !is_array( $options ) ) $options = array(); if ( !$updated && !empty($_POST['sidebar']) ) { $sidebar = (string) $_POST['sidebar']; $sidebars_widgets = wp_get_sidebars_widgets(); if ( isset($sidebars_widgets[$sidebar]) ) $this_sidebar =& $sidebars_widgets[$sidebar]; else $this_sidebar = array(); foreach ( (array) $this_sidebar as $_widget_id ) { if ( 'widget_authors' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) { $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number']; if ( !in_array( "authors-$widget_number", $_POST['widget-id'] ) ) // the widget has been removed. unset($options[$widget_number]); } } foreach ( (array) $_POST['widget-authors'] as $widget_number => $widget_authors ) { if ( !isset($widget_authors['title']) && isset($options[$widget_number]) ) // user clicked cancel continue; $title = trim(strip_tags(stripslashes($widget_authors['title']))); $format = !empty($widget_authors['format']) ? $widget_authors['format'] : 'list'; $order = !empty($widget_authors['order']) ? $widget_authors['order'] : 'name'; $limit = !empty($widget_authors['limit']) ? $widget_authors['limit'] : ''; $show_fullname = isset($widget_authors['show_fullname']); $show_avatar = isset($widget_authors['show_avatar']); $avatar_size = !empty($widget_authors['avatar_size']) ? $widget_authors['avatar_size'] : 32; $feedlink = isset($widget_authors['feedlink']); $count = isset($widget_authors['count']); $hide_empty = isset($widget_authors['hide_empty']); $exclude_admin = isset($widget_authors['exclude_admin']); $exclude = trim(strip_tags(stripslashes($widget_authors['exclude']))); $include = trim(strip_tags(stripslashes($widget_authors['include']))); $show_credit = isset($widget_authors['show_credit']); $options[$widget_number] = compact( 'title', 'format', 'order', 'limit', 'show_fullname', 'show_avatar', 'avatar_size', 'feedlink', 'count', 'hide_empty', 'exclude_admin', 'exclude', 'include', 'show_credit' ); } update_option('widget_authors', $options); $updated = true; } if ( -1 == $number ) { $title = ''; $format = 'list'; $order = 'name'; $limit = ''; $show_fullname = false; $show_avatar = false; $avatar_size = 32; $feedlink = false; $count = false; $hide_empty = 0; $exclude_admin = 0; $exclude = ''; $include = ''; $show_credit = 0; $number = '%i%'; } else { $title = attribute_escape( $options[$number]['title'] ); $format = attribute_escape( $options[$number]['format'] ); $order = attribute_escape( $options[$number]['order'] ); $limit = attribute_escape( $options[$number]['limit'] ); $show_fullname = (bool) $options[$number]['show_fullname']; $show_avatar = (bool) $options[$number]['show_avatar']; $avatar_size = attribute_escape( $options[$number]['avatar_size'] ); $feedlink = (bool) $options[$number]['feedlink']; $count = (bool) $options[$number]['count']; $hide_empty = (bool) $options[$number]['hide_empty']; $exclude_admin = (bool) $options[$number]['exclude_admin']; $exclude = $options[$number]['exclude']; $include = $options[$number]['include']; $show_credit = (bool) $options[$number]['show_credit']; } ?>

    :

    :


    $options ); update_option( 'widget_authors', $newoptions ); $sidebars_widgets = get_option( 'sidebars_widgets' ); if ( is_array( $sidebars_widgets ) ) { foreach ( $sidebars_widgets as $sidebar => $widgets ) { if ( is_array( $widgets ) ) { foreach ( $widgets as $widget ) $new_widgets[$sidebar][] = ( $widget == 'authors' ) ? 'authors-1' : $widget; } else { $new_widgets[$sidebar] = $widgets; } } if ( $new_widgets != $sidebars_widgets ) update_option( 'sidebars_widgets', $new_widgets ); } return $newoptions; } function widget_authors_get_authors( $include = array(), $exclude = array()) { if ( !empty( $include ) ) { $include = explode( ',', $include); foreach ( $include as $key => $val ) { if ( !is_int( $val ) ) { $val = trim($val, '"\''); $user = get_user_by( 'login', $val ); if (!$user) { $user = get_user_by( 'slug', $val ); } if ($user) { $include[$key] = $user->ID; } } } } if ( !empty( $exclude ) ) { $exclude = explode( ',', $exclude); foreach ( $exclude as $key => $val ) { if ( !is_int( $val ) ) { $val = trim($val, '"\''); $user = get_user_by( 'login', $val ); if (!$user) { $user = get_user_by( 'slug', $val ); } if ($user) { $exclude[$key] = $user->ID; } } } } $user_args = array( 'fields' => array( 'ID', 'user_nicename', 'display_name' ), 'who' => 'all', 'orderby' => 'display_name', 'include' => $include, 'exclude' => $exclude ); $wp_user_search = new WP_User_Query( $user_args ); $authors = $wp_user_search->get_results(); return $authors; } function widget_authors_count_authors( $authors ) { $author_ids = array(); foreach( $authors as $author) { $author_ids[] = $author->ID; } $author_count = count_many_users_posts($author_ids); return $author_count; } if ( !$options = get_option( 'widget_authors' ) ) $options = array(); if ( isset($options['title']) ) $options = widget_authors_upgrade(); $widget_ops = array( 'classname' => 'widget_authors', 'description' => __( 'A list of the authors','authors' ) ); $name = __( 'Authors','authors' ); $id = false; foreach ( (array) array_keys($options) as $o ) { // Old widgets can have null values for some reason if ( !isset($options[$o]['title']) ) continue; $id = "authors-$o"; wp_register_sidebar_widget( $id, $name, 'widget_authors', $widget_ops, array( 'number' => $o ) ); wp_register_widget_control( $id, $name, 'widget_authors_control', array( 'id_base' => 'authors' ), array( 'number' => $o ) ); } // If there are none, we register the widget's existance with a generic template if ( !$id ) { wp_register_sidebar_widget( 'authors-1', $name, 'widget_authors', $widget_ops, array( 'number' => -1 ) ); wp_register_widget_control( 'authors-1', $name, 'widget_authors_control', array( 'id_base' => 'authors' ), array( 'number' => -1 ) ); } if ( is_active_widget('widget_authors') ) add_action('wp_head', 'widget_authors_style'); endif; } add_action('init', 'widget_authors_register');