Tag Info

Hot answers tagged

19

The answer above seems comprehensive, but I just wrote a wrapper function and moved on. Here it is if you need it (put this in functions.php): function get_avatar_url($get_avatar){ preg_match("/src='(.*?)'/i", $get_avatar, $matches); return $matches[1]; } and then use it wherver you need it in the template files like this: <img src="<? echo ...


9

The get_avatar() function applies a get_avatar filter hook, that you can use to change the avatar markup: return apply_filters('get_avatar', $avatar, $id_or_email, $size, $default, $alt); I think this would be the correct way to hook into this filter: function mytheme_get_avatar( $avatar ) { $avatar = '<img src="<' . ...


8

If you want a super-lightweight solution and don't mind dabbling in a little code, drop this in your functions.php; function __default_local_avatar() { // this assumes default_avatar.png is in wp-content/themes/active-theme/images return get_bloginfo('template_directory') . '/images/default_avatar.png'; } add_filter( 'pre_option_avatar_default', ...


6

Avatars are meant to be controlled by the user, not by you. So yes, in a way, you're being forced to use the Gravatar service. But remember, it gives the user the ability to use the same avatar anywhere, and you can always restrict the display of a gravatar based on content ratings (G, PG, PG-13, R). Gravatar is a hosted service, which is why there's no ...


6

There are two ways to customize the default avatar: Add a new default avatar to Settings/Discussion. Change the output of get_avatar(). Let’s start with the first option; this processes slightly faster. Add a new default avatar to Settings/Discussion There is a filter 'avatar_defaults'. You can add more avatars here. You get an array of default images ...


5

You can use the filter get_avatar for get all data to the avatar, also the url inside the markup. I think, WP don`t have an function for return only the url if the avatar image. $avatar = "<img alt='{$safe_alt}' src='{$default}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />"; apply_filters('get_avatar', ...


5

I am not sure why your query is returning more IDs than necessary. The $args for get_users look correct. By default get_users does not support orderby=rand, but you can overwrite that option. See below: function random_user_query( &$query ) { $query->query_orderby = "ORDER BY RAND()"; } // Usage: [random_users how_many = 3] add_shortcode( ...


5

Must Use Plugins will anable functionality global. And actualy functionality is pretty simple... only prefiltring default_avatar value. Use this code as plugin which you can install to anable default avatar. <?php /* Plugin Name: Network Default Avatar Description: This Plugin Used to be the General Framework Author: Version: ...


5

The avatar_default is the better option. add_filter('pre_option_avatar_default', 'se72578_avatar_default'); function se72578_avatar_default( $option ){ return 'http://example.com/your/default/here.jpg'; } Simple. Stick that in a mu-plugin and you're good to go. Edit: If you want to still allow site owners to change the default avatar, use the ...


4

I think that i figured it out. Gravatar default images need to be on a public url and not one blocked by htaccess. So i had this on my dev server and when i removed my htaccess file that was blocking access the images started to work. This seems to still be a new feature. Hope that this helps out someone in the future.


4

Notice: get_the_author_ID is deprecated since version 2.8! Use get_the_author_meta('ID') instead. in C:\Users\Administrator\Desktop\www.wpsites.dev\wp-includes\functions.php on line 2908 You aren't using get_the_author_meta('ID'); as instructed by the Notice. You are just using get_the_author_meta(). The latter returns an empty string when I try ...


4

Just generate the URL yourself. It's just a hash of the user's email address. function get_gravatar_url( $email ) { $hash = md5( strtolower( trim ( $email ) ) ); return 'http://gravatar.com/avatar/' . $hash; } This function requires that you pass the user's email address in ... but you could do anything you need to programatically grab the user's ...


4

If you are asking how to replace the default gravatar with one of your own, you can put this code in the functions.php (or better yet the custom-functions.php if your theme supports it). add_filter( 'avatar_defaults', 'customgravatar' ); function customgravatar ($avatar_defaults) { $myavatar = get_home_url('Template_directory') . ...


4

WordPress never makes any HTTP requests for gravatars, it just generates URLs to them. You don't really need to override function completely. You can filter get_avatar hook and return different URL if email matches user with custom avatar set.


3

The only place that gravatars are administered in WordPress core (without plugins, that is) is on the discussion settings page: If you want to access YOUR gravatar, go to http://gravatar.com and set up your profile. WordPress is set to automatically interface with gravatar using your user's email address to identify you with gravatar.com.


3

All you need to do is pass the current users email address into the get_avatar() function. <?php $current_user = wp_get_current_user(); if ( ($current_user instanceof WP_User) ) { echo get_avatar( $current_user->user_email, 32 ); } ?> Here are some links for specifics: get_avatar(); wp_get_current_user(); A response to your new problem ...


3

As usual with hooks this is issue of timing. your init function is hooked to admin load process, which works fine for most things; however in this specific case function is added to filter in constructor of WP_Comments_List_Table class, and object is created in edit-comments.php after admin loader had been processed. In my plugin for similar stuff I am ...


2

You should place your code inside the loop and add to the args array 'post_id' => get_the_ID() so it should look like this: while(have_posts()){ the_post(); //your post loop output $args = array( 'status' => 'approved', 'number' => '5', 'post_id' => get_the_ID() ); $comments = get_comments($args); ...


2

Look at how it is implemented here: http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/pluggable.php#L1578 Additionally check out the very simple Gravatar API: http://en.gravatar.com/site/implement/images/ You can try to hook into the get_avatar filter and preg_match against the 'src' like so: add_filter( 'get_avatar', function( $avatar ) { ...


2

You could use the auto generated Gravatar options in the back end which will randomly assign an "avatar" to those who do not have one. You will find this when you go to your WordPress back-end Settings > Discussion and scroll down to the bottom. Or you can have a custom avatar replacement for those who do not have one however this will not be random but ...


2

Sergey, use this in place where you are going to put form to edit avatar: <?php $myAv = new simple_local_avatars(); $myAv->edit_user_profile($profileuser); ?>


2

This a short compilation of the multiple comments above, so that future visitors don't have to read each and every one of them. First of all, the_author_posts_link() is a deprecated function since version 2.1, so get_author_posts_url() or the_author_posts_url() should be used instead http://codex.wordpress.org/Function_Reference/get_author_posts_url The ...


2

I found the function that makes up bp_post_author_avatar() and then changed the type to full. Place this funtion in functions.php and use the new function to call the post author avatar in the template. function fod_post_author_avatar() { global $post; if ( function_exists('bp_core_fetch_avatar') ) { echo apply_filters( 'bp_post_author_avatar', ...


2

You can simplly check if ($comment->user_id > 0){ //comment by registered user }else{ //comment by none registered user }


2

Try the Simple Local Avatars Plugin. It works exactly as advertised!


2

It depends on what you call "nice" of course - it's hard to create something meaningful with an algorithm. Someone once created a unicorn-generator, which was used on April 1, 2010 all over Stack Overflow. Your unicorn looks like this:


2

The Original Poster was missing the pair priority, parameters when declaring the filter hook: add_filter( 'get_avatar', array( $this, 'get_avatar' ), 10, 5 ); Being 5 all the parameters the callback function can use: public function get_avatar( $avatar, $id_or_email, $size, $default, $alt ) { return $avatar; }


2

The function get_avatar's 3rd argument is the default image, which you can also pass a function's return value to, so wherever you run get_avatar in your theme you can set a function that changes the default avatar as a 3rd argument. get_avatar( get_the_author_meta( 'user_email' ), 64, 'http://example.com/path/to/image.jpg' ); Or, with a function's return ...


2

add do_action('show_user_profile'); do_action('edit_user_profile'); to your custom frontend template and when saving add : do_action('personal_options_update'); do_action('edit_user_profile_update');


2

Three simple steps to generate a Facebook Avatar: Create an extra field in your comment form for the user's facebook profile (see e.g. WP Engineer for a code example and how to) If the user filled out this field, get the facebook avatar (see this question) Replace the WP avatar with your facebook avatar if a fb profile url is set All together in this ...



Only top voted, non community-wiki answers of a minimum length are eligible