WordPress.org

Plugin Directory

Changeset 1533114


Ignore:
Timestamp:
11/13/16 01:26:57 (12 months ago)
Author:
Dev49.net
Message:

Version 2.2.7:

  • Added option to pass additional arguments to get_avatar() - thanks dpsjorge! (for developers only)
Location:
wp-first-letter-avatar
Files:
535 added
2 edited

Legend:

Unmodified
Added
Removed
  • wp-first-letter-avatar/trunk/readme.txt

    r1402562 r1533114  
    11=== WP First Letter Avatar === 
    22Plugin Name: WP First Letter Avatar 
    3 Version: 2.2.6.1 
     3Version: 2.2.7 
    44Plugin URI: http://dev49.net 
    55Contributors: Dev49.net, DanielAGW 
    66Tags: avatars, comments, custom avatar, discussion, change avatar, avatar, custom wordpress avatar, first letter avatar, comment change avatar, wordpress new avatar, avatar, initial avatar 
    7 Requires at least: 4.4 
    8 Tested up to: 4.5 
     7Requires at least: 4.6 
     8Tested up to: 4.6.1 
    99Stable tag: trunk 
    1010Author: Dev49.net 
     
    8282== Changelog == 
    8383 
     84= 2.2.7 = 
     85* Added option to pass additional arguments to get_avatar() - thanks dpsjorge! (for developers only) 
     86 
    8487= 2.2.6.1 = 
    8588* Fixed get_currentuserinfo() function deprecated notice 
     
    9497 
    9598= 2.2.4 = 
    96 * Added fallback for Polish letters (thanks Micha³!) 
     99* Added fallback for Polish letters (thanks Micha!) 
    97100* Plugin prepared for translations (contributors are welcome!) 
    98101 
     
    179182== Upgrade Notice == 
    180183 
     184= 2.2.7 = 
     185Added new feature for developers, update not necessary. 
     186 
    181187= 2.2.6.1 = 
    182188* Removed deprecated function - update recommended if you are using WP 4.5.x 
  • wp-first-letter-avatar/trunk/wp-first-letter-avatar.php

    r1402562 r1533114  
    88 * Contributors: Dev49.net, DanielAGW 
    99 * Description: Set custom avatars for users with no Gravatar. The avatar will be the first (or any other) letter of the user's name on a colorful background. 
    10  * Version: 2.2.6.1 
     10 * Version: 2.2.7 
    1111 * Author: Dev49.net 
    1212 * Author URI: http://dev49.net 
    1313 * Tags: avatars, comments, custom avatar, discussion, change avatar, avatar, custom wordpress avatar, first letter avatar, comment change avatar, wordpress new avatar, avatar, initial avatar 
    14  * Requires at least: 4.4 
    15  * Tested up to: 4.5 
     14 * Requires at least: 4.6 
     15 * Tested up to: 4.6.1 
    1616 * Stable tag: trunk 
    1717 * License: GPLv2 or later 
     
    3232    // Setup: 
    3333    const MINIMUM_PHP = '5.4'; 
    34     const MINIMUM_WP = '4.0'; 
     34    const MINIMUM_WP = '4.6'; 
    3535    const IMAGES_PATH = 'images'; // avatars root directory 
    3636    const GRAVATAR_URL = 'https://secure.gravatar.com/avatar/'; // default url for gravatar 
     
    5858 
    5959    public function __construct(){ 
    60  
     60         
    6161        /* --------------- CONFIGURATION --------------- */ 
    6262 
     
    102102 
    103103        // add filter to get_avatar: 
    104         add_filter('get_avatar', array($this, 'set_comment_avatar'), $this->filter_priority, 5); 
     104        add_filter('get_avatar', array($this, 'set_comment_avatar'), $this->filter_priority, 6); 
    105105 
    106106        // add filter for wpDiscuz: 
     
    149149    public function admin_bar_menu_action(){ // change avatar in the userbar at the top 
    150150 
    151         add_filter('get_avatar', array($this, 'set_userbar_avatar'), $this->filter_priority, 5); 
     151        add_filter('get_avatar', array($this, 'set_userbar_avatar'), $this->filter_priority, 6); 
    152152 
    153153    } 
     
    214214     * This is the main method used for generating avatars. It returns full HTML <img /> tag. 
    215215     */ 
    216     private function set_avatar($name, $email, $size, $alt = ''){ 
     216    private function set_avatar($name, $email, $size, $alt = '', $args = array()){ 
    217217 
    218218        if (empty($name)){ // if, for some reason, there is no name, use email instead 
     
    233233        } 
    234234 
    235         $avatar_img_output = $this->generate_avatar_img_tag($avatar_uri, $size, $alt); // get final <img /> tag for the avatar/gravatar 
     235        $avatar_img_output = $this->generate_avatar_img_tag($avatar_uri, $size, $alt, $args); // get final <img /> tag for the avatar/gravatar 
    236236 
    237237        return $avatar_img_output; 
     
    244244     * This filters every WordPress avatar call and return full HTML <img /> tag 
    245245     */ 
    246     public function set_comment_avatar($avatar, $id_or_email, $size = '96', $default = '', $alt = ''){ 
     246    public function set_comment_avatar($avatar, $id_or_email, $size = '96', $default = '', $alt = '', $args = array()){ 
    247247 
    248248        // create two main variables: 
     
    302302            } 
    303303 
    304         } else { // if it's a standard comment, use basic comment properties and/or functions to retrive info 
     304        } else { // if it's a standard comment, use basic comment properties and/or functions to retrieve info 
    305305 
    306306            $comment = $id_or_email; 
     
    328328        } 
    329329 
    330         $avatar_output = $this->set_avatar($name, $email, $size, $alt); 
     330        $avatar_output = $this->set_avatar($name, $email, $size, $alt, $args); 
    331331 
    332332        return $avatar_output; 
     
    339339     * This method is used to filter the avatar displayed in upper bar (displayed only for logged in users) 
    340340     */ 
    341     public function set_userbar_avatar($avatar, $id_or_email, $size = '96', $default = '', $alt = ''){ // only size and alt arguments are used 
     341    public function set_userbar_avatar($avatar, $id_or_email, $size = '96', $default = '', $alt = '', $args = array()){ 
    342342 
    343343        // get user information: 
     
    347347 
    348348        // use obtained data to return full HTML <img> tag 
    349         $avatar_output = $this->set_avatar($name, $email, $size, $alt); 
     349        $avatar_output = $this->set_avatar($name, $email, $size, $alt, $args); 
    350350 
    351351        return $avatar_output; 
     
    358358     * Generate full HTML <img /> tag with avatar URL, size, CSS classes etc. 
    359359     */ 
    360     private function generate_avatar_img_tag($avatar_uri, $size, $alt = ''){ 
    361  
     360    private function generate_avatar_img_tag($avatar_uri, $size, $alt = '', $args = array()){ 
     361 
     362        // Default classes 
     363        $css_classes = 'avatar avatar-' . $size . ' photo'; 
     364         
     365        // Append plugin class 
     366        $css_classes .= ' wpfla'; 
     367         
    362368        // prepare extra classes for <img> tag depending on plugin settings: 
    363         $extra_img_class = ''; 
    364369        if ($this->round_avatars == true){ 
    365             $extra_img_class .= 'round-avatars'; 
    366         } 
    367  
    368         $output_data = "<img alt='{$alt}' src='{$avatar_uri}' class='avatar avatar-{$size} photo wpfla {$extra_img_class}' width='{$size}' height='{$size}' />"; 
     370            $css_classes .= ' round-avatars'; 
     371        } 
     372         
     373        // Append extra classes 
     374        if (array_key_exists('class', $args)) { 
     375            if (is_array($args['class'])) { 
     376                $css_classes .= ' ' . implode(' ', $args['class']); 
     377            } else { 
     378                $css_classes .= ' ' . $args['class']; 
     379            } 
     380        } 
     381 
     382        $output_data = "<img alt='{$alt}' src='{$avatar_uri}' class='{$css_classes}' width='{$size}' height='{$size}' />"; 
    369383 
    370384        // return the complete <img> tag: 
Note: See TracChangeset for help on using the changeset viewer.