本文整理汇总了PHP中get_avatar_url函数的典型用法代码示例。如果您正苦于以下问题:PHP get_avatar_url函数的具体用法?PHP get_avatar_url怎么用?PHP get_avatar_url使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_avatar_url函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_avatar
/**
* Retrieve the avatar `<img>` tag for a user, email address, MD5 hash, comment, or post.
*
* @since 2.5.0
* @since 4.2.0 Optional `$args` parameter added.
*
* @param mixed $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash,
* user email, WP_User object, WP_Post object, or comment object.
* @param int $size Optional. Height and width of the avatar image file in pixels. Default 96.
* @param string $default Optional. URL for the default image or a default type. Accepts '404'
* (return a 404 instead of a default image), 'retro' (8bit), 'monsterid'
* (monster), 'wavatar' (cartoon face), 'indenticon' (the "quilt"),
* 'mystery', 'mm', or 'mysterman' (The Oyster Man), 'blank' (transparent GIF),
* or 'gravatar_default' (the Gravatar logo). Default is the value of the
* 'avatar_default' option, with a fallback of 'mystery'.
* @param string $alt Optional. Alternative text to use in <img> tag. Default empty.
* @param array $args {
* Optional. Extra arguments to retrieve the avatar.
*
* @type int $height Display height of the avatar in pixels. Defaults to $size.
* @type int $width Display width of the avatar in pixels. Defaults to $size.
* @type bool $force_default Whether to always show the default image, never the Gravatar. Default false.
* @type string $rating What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are
* judged in that order. Default is the value of the 'avatar_rating' option.
* @type string $scheme URL scheme to use. See set_url_scheme() for accepted values.
* Default null.
* @type array|string $class Array or string of additional classes to add to the <img> element.
* Default null.
* @type bool $force_display Whether to always show the avatar - ignores the show_avatars option.
* Default false.
* @type string $extra_attr HTML attributes to insert in the IMG element. Is not sanitized. Default empty.
* }
* @return false|string `<img>` tag for the user's avatar. False on failure.
*/
function get_avatar($id_or_email, $size = 96, $default = '', $alt = '', $args = null)
{
$defaults = array('size' => 96, 'height' => null, 'width' => null, 'default' => get_option('avatar_default', 'mystery'), 'force_default' => false, 'rating' => get_option('avatar_rating'), 'scheme' => null, 'alt' => '', 'class' => null, 'force_display' => false, 'extra_attr' => '');
if (empty($args)) {
$args = array();
}
$args['size'] = (int) $size;
$args['default'] = $default;
$args['alt'] = $alt;
$args = wp_parse_args($args, $defaults);
if (empty($args['height'])) {
$args['height'] = $args['size'];
}
if (empty($args['width'])) {
$args['width'] = $args['size'];
}
/**
* Filter whether to retrieve the avatar URL early.
*
* Passing a non-null value will effectively short-circuit get_avatar(), passing
* the value through the {@see 'pre_get_avatar'} filter and returning early.
*
* @since 4.2.0
*
* @param string $avatar HTML for the user's avatar. Default null.
* @param int|object|string $id_or_email A user ID, email address, or comment object.
* @param array $args Arguments passed to get_avatar_url(), after processing.
*/
$avatar = apply_filters('pre_get_avatar', null, $id_or_email, $args);
if (!is_null($avatar)) {
/** This filter is documented in wp-includes/pluggable.php */
return apply_filters('get_avatar', $avatar, $id_or_email, $args['size'], $args['default'], $args['alt'], $args);
}
if (!$args['force_display'] && !get_option('show_avatars')) {
return false;
}
$url2x = get_avatar_url($id_or_email, array_merge($args, array('size' => $args['size'] * 2)));
$args = get_avatar_data($id_or_email, $args);
$url = $args['url'];
if (!$url || is_wp_error($url)) {
return false;
}
$class = array('avatar', 'avatar-' . (int) $args['size'], 'photo');
if (!$args['found_avatar'] || $args['force_default']) {
$class[] = 'avatar-default';
}
if ($args['class']) {
if (is_array($args['class'])) {
$class = array_merge($class, $args['class']);
} else {
$class[] = $args['class'];
}
}
$avatar = sprintf("<img alt='%s' src='%s' srcset='%s' class='%s' height='%d' width='%d' %s/>", esc_attr($args['alt']), esc_url($url), esc_attr("{$url2x} 2x"), esc_attr(join(' ', $class)), (int) $args['height'], (int) $args['width'], $args['extra_attr']);
/**
* Filter the avatar to retrieve.
*
* @since 2.5.0
* @since 4.2.0 The `$args` parameter was added.
*
* @param string $avatar <img> tag for the user's avatar.
* @param int|object|string $id_or_email A user ID, email address, or comment object.
* @param int $size Square avatar width and height in pixels to retrieve.
* @param string $alt Alternative text to use in the avatar image tag.
* Default empty.
* @param array $args Arguments passed to get_avatar_data(), after processing.
//.........这里部分代码省略.........
示例2: fa_cache_avatar
function fa_cache_avatar($avatar, $id_or_email, $size, $default, $alt)
{
$avatar = str_replace(array("www.gravatar.com", "0.gravatar.com", "1.gravatar.com", "2.gravatar.com"), "cn.gravatar.com", $avatar);
$tmp = strpos($avatar, 'http');
$url = get_avatar_url($id_or_email, $size);
$url = str_replace(array("www.gravatar.com", "0.gravatar.com", "1.gravatar.com", "2.gravatar.com"), "cn.gravatar.com", $url);
$avatar2x = get_avatar_url($id_or_email, $size * 2);
$avatar2x = str_replace(array("www.gravatar.com", "0.gravatar.com", "1.gravatar.com", "2.gravatar.com"), "cn.gravatar.com", $avatar2x);
$g = substr($avatar, $tmp, strpos($avatar, "'", $tmp) - $tmp);
$tmp = strpos($g, 'avatar/') + 7;
$f = substr($g, $tmp, strpos($g, "?", $tmp) - $tmp);
$w = home_url();
$e = ABSPATH . 'avatar/' . $size . '*' . $f . '.jpg';
$e2x = ABSPATH . 'avatar/' . $size * 2 . '*' . $f . '.jpg';
$t = 1209600;
if ((!is_file($e) || time() - filemtime($e) > $t) && (!is_file($e2x) || time() - filemtime($e2x) > $t)) {
copy(htmlspecialchars_decode($g), $e);
copy(htmlspecialchars_decode($avatar2x), $e2x);
} else {
$avatar = $w . '/avatar/' . $size . '*' . $f . '.jpg';
$avatar2x = $w . '/avatar/' . $size * 2 . '*' . $f . '.jpg';
if (filesize($e) < 1000) {
copy($w . '/avatar/default.jpg', $e);
}
if (filesize($e2x) < 1000) {
copy($w . '/avatar/default.jpg', $e2x);
}
$avatar = "<img alt='{$alt}' src='{$avatar}' srcset='{$avatar2x}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
}
return $avatar;
}
示例3: hwseo_jsonld_person
function hwseo_jsonld_person()
{
$payload = array('@type' => 'Person');
if (is_author()) {
global $wp_query;
$author_data = $wp_query->get_queried_object();
} elseif (is_single()) {
global $post;
$author_data = get_userdata($post->post_author);
} else {
$author_data = get_userdata(1);
}
//refer to admin
// fetch twitter from author meta and concatenate with full twitter URL
$twitter_url = " https://twitter.com/";
$twitterHandle = get_the_author_meta('twitter', $author_data->ID);
$twitterHandleURL = $twitter_url . $twitterHandle;
$websiteHandle = get_the_author_meta('url', $author_data->ID);
$facebookHandle = get_the_author_meta('facebook', $author_data->ID);
$gplusHandle = get_the_author_meta('googleplus', $author_data->ID);
$linkedinHandle = get_the_author_meta('linkedin', $author_data->ID);
$slideshareHandle = get_the_author_meta('slideshare', $author_data->ID);
//user custom fields
$phone = get_the_author_meta('phone', $author_data->ID);
$jobtitle = get_the_author_meta('jobtitle', $author_data->ID);
$payload['name'] = $author_data->display_name;
$payload['email'] = $author_data->user_email;
$payload['telephone'] = $phone;
$payload['image'] = get_avatar_url(get_avatar($author_data->ID, 150));
$payload['jobTitle'] = $jobtitle;
$payload["sameAs"] = array($twitterHandleURL, $websiteHandle, $facebookHandle, $gplusHandle, $linkedinHandle, $slideshareHandle);
return $payload;
}
示例4: getUser
public function getUser($name, $meta = array())
{
global $wpdb;
$meta_fields = '';
if (sizeof($meta) > 0) {
foreach ($meta as $meta_item) {
$meta_fields .= ",{$meta_item}.meta_value as value{$meta_item}";
}
}
$query = "SELECT u.ID, u.display_name, ud.meta_value as bio, u.user_email, u.user_url {$meta_fields} FROM {$wpdb->users} AS u";
$query .= " LEFT JOIN {$wpdb->usermeta} AS ud ON (u.ID = ud.user_id AND ud.meta_key = 'description')";
if (sizeof($meta) > 0) {
foreach ($meta as $meta_item) {
$query .= " LEFT JOIN {$wpdb->usermeta} AS {$meta_item} ON (u.ID = {$meta_item}.user_id AND {$meta_item}.meta_key = '{$meta_item}')";
}
}
$query .= " WHERE u.display_name = {$name}";
$query .= " GROUP BY u.ID";
$authorQuery = $wpdb->get_results($query);
$author_data = $authorQuery[0];
$author = array();
$author['avatar'] = get_avatar_url($author_data->ID, '150');
$author['name'] = $author_data->display_name;
$author['id'] = $author_data->ID;
$author['bio'] = $author_data->bio;
$author['email'] = $author_data->user_email;
if (sizeof($meta) > 0) {
foreach ($meta as $meta_item) {
$meta_name = 'value' . $meta_item;
$author[$meta_item] = $author_data->{$meta_name};
}
}
wp_reset_query();
return $author;
}
示例5: __get
function __get($name)
{
if (is_numeric($name) && $name == (int) $name && $name == absint($name)) {
return get_avatar_url($this->_user_id, array('size' => $name));
}
return '';
}
示例6: questions_list_action
public function questions_list_action()
{
if ($_GET['feature_id']) {
$topic_ids = $this->model('feature')->get_topics_by_feature_id($_GET['feature_id']);
if ($topic_ids) {
$answers = $this->model('reader')->fetch_answers_list_by_topic_ids($topic_ids, $_GET['page'], 20);
}
} else {
$answers = $this->model('reader')->fetch_answers_list($_GET['page'], 20);
}
$output = array();
if ($answers) {
foreach ($answers as $key => $val) {
$question_ids[$val['question_id']] = $val['question_id'];
$uids[$val['uid']] = $val['uid'];
}
$questions_info = $this->model('question')->get_question_info_by_ids($question_ids);
$question_topics = $this->model('topic')->get_topics_by_item_ids($question_ids, 'question');
$users_info = $this->model('account')->get_user_info_by_uids($uids, TRUE);
foreach ($answers as $key => $val) {
$output['answers'][$val['answer_id']] = array('answer_id' => $val['answer_id'], 'question_id' => $val['question_id'], 'avatar' => get_avatar_url($val['uid'], 'mid'), 'user_name' => $users_info[$val['uid']]['user_name'], 'signature' => $users_info[$val['uid']]['signature'], 'agree_count' => $val['agree_count'], 'agree_users' => $this->model('answer')->get_vote_user_by_answer_id($val['answer_id']), 'answer_content' => FORMAT::parse_attachs(nl2br(FORMAT::parse_markdown($val['answer_content']))), 'add_time' => date_friendly($val['add_time']), 'uid' => $val['uid']);
}
foreach ($questions_info as $key => $val) {
$output['questions'][$val['question_id']] = array('question_id' => $val['question_id'], 'question_content' => $val['question_content'], 'question_detail' => FORMAT::parse_attachs(nl2br(FORMAT::parse_markdown($val['question_detail']))), 'answer_users' => $val['answer_users'], 'focus_count' => $val['focus_count'], 'view_count' => $val['view_count'], 'topics' => $question_topics[$val['question_id']]);
}
}
echo json_encode($output);
}
示例7: my_custom_comments
function my_custom_comments($comment, $args, $depth)
{
$GLOBALS['comment'] = $comment;
?>
<li <?php
comment_class();
?>
id="li-comment-<?php
comment_ID();
?>
">
<?php
if ($comment->comment_approved == '0') {
?>
<em><?php
_e('Your comment is awaiting moderation.');
?>
</em>
<?php
}
?>
<?php
echo '<div class="pull-left"><div class="commentor-avatar" style="height: 90px; width: 90px; background: url(' . get_avatar_url($comment) . ') no-repeat center center; background-size: cover;"><div class="commentor-name">' . get_comment_author() . '</div></div></div>';
comment_text();
echo '<div class="clearfix"></div>';
}
示例8: get_avatar_url
protected function get_avatar_url($email, $avatar_size = 96)
{
$avatar_url = get_avatar_url($email, array('size' => $avatar_size));
if (!$avatar_url || is_wp_error($avatar_url)) {
return '';
}
return $avatar_url;
}
示例9: url_author_avatar
/**
* @return false|string
*/
function url_author_avatar()
{
$image_url = get_the_author_meta('author-avatar');
if (empty($image_url)) {
$image_url = get_avatar_url(get_the_author_meta('ID'));
}
return $image_url;
}
示例10: index_action
public function index_action()
{
if (!$this->user_id) {
H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('请先登录或注册')));
}
$this->per_page = get_setting('contents_per_page');
if ($_GET['per_page']) {
$this->per_page = intval($_GET['per_page']);
}
//$data = $this->model('myhome')->home_activity($this->user_id, (intval($_GET['page']) * $this->per_page) . ", {$this->per_page}");
$data = $this->model('actions')->home_activity($this->user_id, intval($_GET['page']) * $this->per_page . ", {$this->per_page}");
if (!is_array($data)) {
$data = array();
} else {
$data_key = array('history_id', 'associate_action', 'user_info', 'answer_info', 'question_info', 'article_info', 'comment_info', 'add_time');
$user_info_key = array('uid', 'user_name', 'signature');
$article_info_key = array('id', 'title', 'message', 'comments', 'views', 'add_time');
$answer_info_key = array('answer_id', 'answer_content', 'add_time', 'against_count', 'agree_count');
$question_info_key = array('question_id', 'question_content', 'add_time', 'update_time', 'answer_count', 'agree_count');
foreach ($data as $key => $val) {
foreach ($val as $k => $v) {
if (!in_array($k, $data_key)) {
unset($data[$key][$k]);
}
}
if ($val['user_info']) {
foreach ($val['user_info'] as $k => $v) {
if (!in_array($k, $user_info_key)) {
unset($data[$key]['user_info'][$k]);
}
}
$data[$key]['user_info']['avatar_file'] = get_avatar_url($data[$key]['user_info']['uid'], 'mid');
}
if ($val['article_info']) {
foreach ($val['article_info'] as $k => $v) {
if (!in_array($k, $article_info_key)) {
unset($data[$key]['article_info'][$k]);
}
}
}
if ($val['answer_info']) {
foreach ($val['answer_info'] as $k => $v) {
if (!in_array($k, $answer_info_key)) {
unset($data[$key]['answer_info'][$k]);
}
}
}
if ($val['question_info']) {
foreach ($val['question_info'] as $k => $v) {
if (!in_array($k, $question_info_key)) {
unset($data[$key]['question_info'][$k]);
}
}
}
}
}
H::ajax_json_output(AWS_APP::RSM(array('total_rows' => count($data), 'rows' => array_values($data)), 1, null));
}
示例11: format_js_users_output
public function format_js_users_output($data)
{
if ($data) {
foreach ($data as $key => $val) {
$output .= '<div class="item"><dl class="inf"><dt><a href="' . get_js_url('/people/' . $val['url_token']) . '">' . $val['user_name'] . '</a></dt><dd>回复了 ' . $val['answer_count'] . ' 个问题</dd><dd>获得 ' . $val['agree_count'] . ' 个赞同</dd></dl><div class="avatar"><a href=""><img src="' . get_avatar_url($val['uid'], 'mid') . '" /></a></div></div><!-- .item -->';
}
}
return "document.write('" . addcslashes($output, "'") . "');";
}
示例12: get_focus_users_action
public function get_focus_users_action()
{
if ($focus_users = $this->model('topic')->get_focus_users_by_topic($_GET['topic_id'], 18)) {
foreach ($focus_users as $key => $val) {
$focus_users[$key]['avatar_file'] = get_avatar_url($val['uid'], 'mid');
$focus_users[$key]['url'] = get_js_url('/people/' . $val['url_token']);
}
}
H::ajax_json_output($focus_users);
}
示例13: get_comments_for_posts
function get_comments_for_posts($data, $post, $context)
{
$comments = get_comments(array('post_id' => $post['ID']));
foreach ($comments as $comment) {
$user_id = $comment->user_id;
$author = ['ID' => $user_id, 'username' => get_the_author_meta('user_login', $user_id), 'name' => get_the_author_meta('display_name', $user_id), 'first_name' => get_the_author_meta('first_name', $user_id), 'last_name' => get_the_author_meta('last_name', $user_id), 'avatar' => get_avatar_url($user_id), 'description' => get_the_author_meta('description', $user_id)];
$data['comments'][] = ['ID' => $comment->comment_ID, 'post' => $comment->comment_post_ID, 'content' => $comment->comment_content, 'author' => $author, 'date' => $comment->comment_date, 'date_gmt' => $comment->comment_date_gmt];
}
return $data;
}
示例14: wp_slack_bbpress
/**
* Plugin Name: WP Slack bbPress
* Plugin URI: https://github.com/rolfkleef/wp-slack-bbpress
* Description: Send notifications to Slack channels for events in bbPress.
* Version: 0.5
* Author: Rolf Kleef
* Author URI: https://drostan.org
* License: GPL2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: wp-slack-bbpress
*/
function wp_slack_bbpress($events)
{
$events['wp_slack_bbp_new_topic'] = array('action' => 'bbp_new_topic', 'description' => __('When a new topic is added in bbPress', 'wp-slack-bbpress'), 'message' => function ($topic_id, $forum_id, $anonymous_data, $topic_author) {
return array(array('fallback' => sprintf(__('<%1$s|New topic "%2$s"> in forum <%3$s|%4$s>', 'wp-slack-bbpress'), bbp_get_topic_permalink($topic_id), bbp_get_topic_title($topic_id), bbp_get_forum_permalink($forum_id), bbp_get_forum_title($forum_id)), 'pretext' => sprintf(__('New topic in forum <%1$s|%2$s>', 'wp-slack-bbpress'), bbp_get_forum_permalink($forum_id), bbp_get_forum_title($forum_id)), 'author_name' => bbp_get_topic_author_display_name($topic_id), 'author_link' => bbp_get_topic_author_link($topic_id), 'author_icon' => get_avatar_url($topic_author, array('size' => 16)), 'title' => sprintf('%1$s', bbp_get_topic_title($topic_id)), 'title_link' => bbp_get_topic_permalink($topic_id), 'text' => html_entity_decode(bbp_get_topic_excerpt($topic_id, 150))));
});
$events['wp_slack_bbp_new_reply'] = array('action' => 'bbp_new_reply', 'description' => __('When a new reply is added in bbPress', 'wp-slack-bbpress'), 'message' => function ($reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author, $bool, $reply_to) {
return array(array('fallback' => sprintf(__('<%1$s|New reply> in forum <%2$s|%3$s> on topic <%4$s|%5$s>', 'wp-slack-bbpress'), bbp_get_reply_url($reply_id), bbp_get_forum_permalink($forum_id), bbp_get_forum_title($forum_id), bbp_get_topic_permalink($topic_id), bbp_get_topic_title($topic_id)), 'pretext' => sprintf(__('New reply in forum <%1$s|%2$s> on topic <%3$s|%4$s>', 'wp-slack-bbpress'), bbp_get_forum_permalink($forum_id), bbp_get_forum_title($forum_id), bbp_get_topic_permalink($topic_id), bbp_get_topic_title($topic_id)), 'author_name' => bbp_get_reply_author_display_name($reply_id), 'author_link' => bbp_get_reply_author_link($reply_id), 'author_icon' => get_avatar_url($reply_author, array('size' => 16)), 'title' => sprintf(__('New reply to "%1$s"', 'wp-slack-bbpress'), bbp_get_topic_title($topic_id)), 'title_link' => bbp_get_reply_url($reply_id), 'text' => html_entity_decode(bbp_get_reply_excerpt($reply_id, 150))));
});
return $events;
}
示例15: get_author
/**
* get_author
*
* @return mixed
*/
protected function get_author()
{
if (empty($this->author)) {
if ($id = get_queried_object_id()) {
$this->author = new \TimberUser($id);
$this->author->thumbnail = new \TimberImage(get_avatar_url($this->author->id));
}
}
return $this->author;
}