ID); $author->first_name = $author_data->first_name; $author->last_name = $author_data->last_name; } 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($orderby, &$authors) { if ('first_name' != $orderby && 'last_name' != $orderby) { return; } array_walk($authors, widget_authors_add_last_name); switch ($orderby) { case 'first_name': usort($authors, widget_authors_sort_by_first_name); break; case 'last_name': usort($authors, widget_authors_sort_by_last_name); break; } } if ( function_exists('seo_tag_cloud_generate') ) : function widget_authors_cloud($args = '') { global $wpdb; $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' ); $r = wp_parse_args( $args, $defaults ); extract($r, EXTR_SKIP); $return = ''; $authors = $wpdb->get_results('SELECT ID, user_nicename, display_name FROM '.$wpdb->users.' ' . ($exclude_admin ? 'WHERE ID <> 1 ' : '') . 'ORDER BY display_name'); $author_count = array(); foreach ((array) $wpdb->get_results('SELECT DISTINCT post_author, COUNT(ID) AS count FROM '.$wpdb->posts.' WHERE post_type = "post" AND ' . get_private_posts_cap_sql( 'post' ) . ' GROUP BY post_author') as $row) { $author_count[$row->post_author] = $row->count; } 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 ); $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_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; } 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 = '') { global $wpdb; $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' ); $r = wp_parse_args( $args, $defaults ); extract($r, EXTR_SKIP); $return = ''; /** @todo Move select to get_authors(). */ $authors = $wpdb->get_results('SELECT ID, user_nicename FROM ' . $wpdb->users . ' ORDER BY display_name'); $author_count = array(); foreach ((array) $wpdb->get_results('SELECT DISTINCT post_author, COUNT(ID) AS count FROM ' . $wpdb->posts . ' WHERE post_type = "post" AND ' . get_private_posts_cap_sql('post') . ' GROUP BY post_author') as $row) { $author_count[$row->post_author] = $row->count; } 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'; $hide_credit = $options['hide_credit'] ? '1' : '0'; ?> '.__('Powered by %s','authors').'', ''.__('Authors Widget','authors').'');?> #', $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_style() { ?> $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']); $exclude_admin = isset($widget_authors['exclude_admin']); $hide_credit = isset($widget_authors['hide_credit']); $options[$widget_number] = compact( 'title', 'format', 'order', 'limit', 'show_fullname', 'show_avatar', 'avatar_size', 'feedlink', 'count', 'exclude_admin', 'hide_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; $exclude_admin = 0; $hide_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']; $exclude_admin = (bool) $options[$number]['exclude_admin']; $hide_credit = (bool) $options[$number]['hide_credit']; } ?>

    :

    :

    <?_e('Donate')?>

    $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; } 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');