Tag Info

Hot answers tagged

10

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="<' . ...


7

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

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

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

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

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') . ...


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

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

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 ...


2

The filters you cite are only for the default/fallback avatars. If you want to replace BP avatars altogether, the key filters are bp_core_fetch_avatar and bp_core_fetch_avatar_url. The latter filters the entire HTML avatar element, while the latter does just the URL. How you do the filtering depends on how fancy you want to get. The bp_core_fetch_avatar ...


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

As far as I know the get_avatar() function only allows for square values. That doesn't mean you couldn't use styling to display a rectangular avatar. Essentially you would use styling to "shave off" 150px from the width. So, let's assume that your theme file produces a 300 x 300 pixel avatar for the post author using the following code: <?php echo ...


2

In my mu-plugins folder I now have the following code, which adds a custom avatar as the default network wide, but allows each individual site to change it thereafter. <?php /* Plugin Name: Network Default Avatar Description: This Plugin sets the default avatar network-wide */ class Network_Default_Avatars { // configure these ...


2

We need second parameters passed to the actions: action edit_user_profile needs a Wordpress user object (we take it from WP_User class) action edit_user_profile_update needs the user id The first action is rendering the upload field and the current avatar and the second one is doing the upload itself. That's why we need to trigger it after clicking the ...



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