• Resolved dpsjfveloso1

    (@dpsjfveloso1)


    I think that this is a fix for passing extra arguments that should be used by the plugin. For example, users can use the get_avatar method and include extra CSS classes $args parameter in the filter since the 4.2.0 version.

    I wrote a fix for this, by changing the number of passed arguments based on the WordPress version, in the wp-first-letter-avatar.php file, I made the following edits:

    Lines 104-105, __construct, now should be:

    // add filter to get_avatar:
    global $wp_version;
    
    if (version_compare($wp_version, '4.2.0', '<')) {
    	// The $args started only started to be passed in WordPress 4.2.0
    	add_filter('get_avatar', array($this, 'set_comment_avatar'), $this->filter_priority, 5);
    }
    else {
    	add_filter('get_avatar', array($this, 'set_comment_avatar'), $this->filter_priority, 6);
    }

    The admin_bar_menu_action method now looks like:

    public function admin_bar_menu_action(){ // change avatar in the userbar at the top
    	global $wp_version;
    	
    	if (version_compare($wp_version, '4.2.0', '<')) {
    		// The $args started only started to be passed in WordPress 4.2.0
    		add_filter('get_avatar', array($this, 'set_userbar_avatar'), $this->filter_priority, 5);
    	}
    	else {
    		add_filter('get_avatar', array($this, 'set_userbar_avatar'), $this->filter_priority, 6);
    	}
    
    }

    Also, set_userbar_avatar:

    public function set_comment_avatar($avatar, $id_or_email, $size = '96', $default = '', $alt = '', $args = array()){
    	.
    	.
    	.
    
    	$avatar_output = $this->set_avatar($name, $email, $size, $alt, $args);
    
    	return $avatar_output;
    
    }

    The set_avatar method now should be updated as well:

    private function set_avatar($name, $email, $size, $alt = '', $args = array()){
    	.
    	.
    	.
    	
    	$avatar_img_output = $this->generate_avatar_img_tag($avatar_uri, $size, $alt, $args); // get final <img /> tag for the avatar/gravatar
    
    	return $avatar_img_output;
    
    }

    And the generate_avatar_img_tag now should use the extra CSS class, if available

    private function generate_avatar_img_tag($avatar_uri, $size, $alt = '', $args = array()){
    	// Default classes
    	$css_classes = 'avatar avatar-' . $size . ' photo';
    	
    	// Append plugin class
    	$css_classes .= ' wpfla';
    	
    	// prepare extra classes for <img> tag depending on plugin settings:
    	if ($this->round_avatars == true){
    		$css_classes .= ' round-avatars';
    	}
    	
    	// Append extra classes
    	if (array_key_exists('class', $args)) {
    		if (is_array($args['class'])) {
    			$css_classes .= ' ' . implode(' ', $args['class']);
    		}
    		else {
    			$css_classes .= ' ' . $args['class'];
    		}
    	}
    
    	$output_data = "<img alt='{$alt}' src='{$avatar_uri}' class='{$css_classes}' width='{$size}' height='{$size}' />";
    
    	// return the complete <img> tag:
    	return $output_data;
    
    }

    Is it possible to include this update on the next version of the plugin?

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Fix for passing the arguments in the get_avatar filter’ is closed to new replies.