Ejemplo n.º 1
0
function get_author_avatar()
{
    global $default;
    $avatar = '';
    if (class_exists('author_image')) {
        $avatar = author_image::get();
    }
    if ($avatar == '') {
        if (in_the_loop()) {
            $author_id = get_the_author_ID();
        } elseif (is_singular()) {
            global $wp_the_query;
            $author_id = $wp_the_query->posts[0]->post_author;
        } elseif (is_author()) {
            global $wp_the_query;
            $author_id = $wp_the_query->get_queried_object_id();
        }
        $author = get_userdata($author_id);
        if (!empty($author)) {
            $avatar = get_avatar($author->user_email, 64, $default, $author->display_name);
        } else {
            $avatar = '<img src="' . esc_url($default) . '" alt="' . $author->display_name . '" />';
        }
    }
    return $avatar;
}
 /**
  * get_single_id()
  *
  * @return int $author_id
  **/
 static function get_single_id()
 {
     $author_id = get_transient('author_image_cache');
     if ($author_id && !sem_author_image_debug) {
         return $author_id;
     } elseif ($author_id === '' && !sem_author_image_debug) {
         return 0;
     } elseif (!is_dir(WP_CONTENT_DIR . '/authors')) {
         set_transient('author_image_cache', '');
         return 0;
     }
     # try the site admin first
     $user = get_user_by('email', get_option('admin_email'));
     if ($user && $user->ID && author_image::get($user->ID)) {
         set_transient('author_image_cache', $user->ID);
         return $user->ID;
     }
     global $wpdb;
     $author_id = 0;
     $i = 0;
     do {
         $offset = $i * 10;
         $limit = ($i + 1) * 10;
         $authors = $wpdb->get_results("\n\t\t\t\tSELECT\t{$wpdb->users}.ID,\n\t\t\t\t\t\t{$wpdb->users}.user_login\n\t\t\t\tFROM\t{$wpdb->users}\n\t\t\t\tJOIN\t{$wpdb->usermeta}\n\t\t\t\tON\t\t{$wpdb->usermeta}.user_id = {$wpdb->users}.ID\n\t\t\t\tAND\t\t{$wpdb->usermeta}.meta_key = '" . $wpdb->prefix . "capabilities'\n\t\t\t\tJOIN\t{$wpdb->posts}\n\t\t\t\tON\t\t{$wpdb->posts}.post_author = {$wpdb->users}.ID\n\t\t\t\tGROUP BY {$wpdb->users}.ID\n\t\t\t\tORDER BY {$wpdb->users}.ID\n\t\t\t\tLIMIT {$offset}, {$limit}\n\t\t\t\t");
         if (!$authors) {
             set_transient('author_image_cache', '');
             return 0;
         }
         foreach ($authors as $author) {
             if (defined('GLOB_BRACE')) {
                 $author_image = glob(WP_CONTENT_DIR . '/authors/' . $author->user_login . '{,-*}.{jpg,jpeg,png}', GLOB_BRACE);
             } else {
                 $author_image = glob(WP_CONTENT_DIR . '/authors/' . $author->user_login . '-*.jpg');
             }
             if ($author_image) {
                 $user = new WP_User($author->ID);
                 if (!$user->has_cap('publish_posts') && !$user->has_cap('publish_pages')) {
                     continue;
                 }
                 $author_id = $author->ID;
                 set_transient('author_image_cache', $author_id);
                 return $author_id;
             }
         }
         $i++;
     } while (!$author_id);
     set_transient('author_image_cache', '');
     return 0;
 }