Plugin Directory

Changeset 1932035


Ignore:
Timestamp:
08/28/2018 09:01:42 PM (8 years ago)
Author:
LasseRafn
Message:

Tagging version 0.8

Location:
wp-initials-avatar
Files:
3 edited
4 copied

Legend:

Unmodified
Added
Removed
  • wp-initials-avatar/tags/0.8/options.php

    r1769240 r1932035  
    11<div class="wrap">
    2     <h1><?php _e( 'User Initials Avatar Setitngs', 'wiauia' ); ?></h1>
     2    <h1><?php _e( 'User Initials Avatar Setitngs', 'wp-initials-avatar' ); ?></h1>
    33
    44    <form method="post" action="options.php">
     
    99        <table class="form-table">
    1010            <tr valign="top">
    11                 <th scope="row"><?php _e( 'Font color', 'wiauia' ); ?></th>
     11                <th scope="row"><?php _e( 'Font color', 'wp-initials-avatar' ); ?></th>
    1212                <td><input type="text" name="color" data-default="#222222" value="<?php echo esc_attr( get_option( 'color', '#222222' ) ); ?>" class="my-color-field"/></td>
    1313            </tr>
    1414
    1515            <tr valign="top">
    16                 <th scope="row"><?php _e( 'Background color', 'wiauia' ); ?></th>
     16                <th scope="row"><?php _e( 'Background color', 'wp-initials-avatar' ); ?></th>
    1717                <td><input type="text" name="background" data-default="#dddddd" value="<?php echo esc_attr( get_option( 'background', '#dddddd' ) ); ?>" class="my-color-field"/></td>
    1818            </tr>
    1919
    2020            <tr valign="top">
    21                 <th scope="row"><?php _e( 'Length', 'wiauia' ); ?></th>
     21                <th scope="row"><?php _e( 'Length', 'wp-initials-avatar' ); ?></th>
    2222                <td>
    2323                    <select name="length">
    24                         <option <?php selected( esc_attr( get_option( 'length', 2 ) ) == 1 ); ?> value="1"><?php echo sprintf( translate( '%s letter', 'wiauia' ), 1 ); ?></option>
    25                         <option <?php selected( esc_attr( get_option( 'length', 2 ) ) == 2 ); ?> value="2"><?php echo sprintf( translate( '%s letters', 'wiauia' ), 2 ); ?></option>
    26                         <option <?php selected( esc_attr( get_option( 'length', 2 ) ) == 3 ); ?> value="3"><?php echo sprintf( translate( '%s letters', 'wiauia' ), 3 ); ?></option>
    27                         <option <?php selected( esc_attr( get_option( 'length', 2 ) ) == 4 ); ?> value="4"><?php echo sprintf( translate( '%s letters', 'wiauia' ), 4 ); ?></option>
    28                     </select>
    29                 </td>
    30             </tr>
    31 
    32             <tr valign="top">
    33                 <th scope="row"><?php _e( 'Image size', 'wiauia' ); ?></th>
    34                 <td>
    35                     <select name="size">
    36                         <option <?php selected( esc_attr( get_option( 'size', 64 ) ) == 16 ); ?> value="16"><?php echo sprintf( translate( '%sx%s pixels', 'wiauia' ), 16, 16 ); ?></option>
    37                         <option <?php selected( esc_attr( get_option( 'size', 64 ) ) == 24 ); ?> value="24"><?php echo sprintf( translate( '%sx%s pixels', 'wiauia' ), 24, 24 ); ?></option>
    38                         <option <?php selected( esc_attr( get_option( 'size', 64 ) ) == 32 ); ?> value="32"><?php echo sprintf( translate( '%sx%s pixels', 'wiauia' ), 32, 32 ); ?></option>
    39                         <option <?php selected( esc_attr( get_option( 'size', 64 ) ) == 48 ); ?> value="48"><?php echo sprintf( translate( '%sx%s pixels', 'wiauia' ), 48, 48 ); ?></option>
    40                         <option <?php selected( esc_attr( get_option( 'size', 64 ) ) == 64 ); ?> value="64"><?php echo sprintf( translate( '%sx%s pixels', 'wiauia' ), 64, 64 ); ?></option>
    41                         <option <?php selected( esc_attr( get_option( 'size', 64 ) ) == 96 ); ?> value="96"><?php echo sprintf( translate( '%sx%s pixels', 'wiauia' ), 96, 96 ); ?></option>
    42                         <option <?php selected( esc_attr( get_option( 'size', 64 ) ) == 128 ); ?> value="128"><?php echo sprintf( translate( '%sx%s pixels', 'wiauia' ), 128, 128 ); ?></option>
    43                         <option <?php selected( esc_attr( get_option( 'size', 64 ) ) == 192 ); ?> value="192"><?php echo sprintf( translate( '%sx%s pixels', 'wiauia' ), 192, 192 ); ?></option>
    44                         <option <?php selected( esc_attr( get_option( 'size', 64 ) ) == 256 ); ?> value="256"><?php echo sprintf( translate( '%sx%s pixels', 'wiauia' ), 256, 256 ); ?></option>
     24                        <option <?php selected( esc_attr( get_option( 'length', 2 ) ) == 1 ); ?> value="1"><?php echo sprintf( __( '%s letter', 'wp-initials-avatar' ), 1 ); ?></option>
     25                        <option <?php selected( esc_attr( get_option( 'length', 2 ) ) == 2 ); ?> value="2"><?php echo sprintf( __( '%s letters', 'wp-initials-avatar' ), 2 ); ?></option>
     26                        <option <?php selected( esc_attr( get_option( 'length', 2 ) ) == 3 ); ?> value="3"><?php echo sprintf( __( '%s letters', 'wp-initials-avatar' ), 3 ); ?></option>
     27                        <option <?php selected( esc_attr( get_option( 'length', 2 ) ) == 4 ); ?> value="4"><?php echo sprintf( __( '%s letters', 'wp-initials-avatar' ), 4 ); ?></option>
    4528                    </select>
    4629                </td>
     
    5134                <td>
    5235                    <select name="rounded">
    53                         <option <?php selected( esc_attr( get_option( 'rounded', 'false' ) ) == 'false' ); ?> value="false"><?php echo translate( 'No - Square avatar', 'wiauia' ); ?></option>
    54                         <option <?php selected( esc_attr( get_option( 'rounded', 'false' ) ) == 'true' ); ?> value="true"><?php echo translate( 'Yes - Rounded avatar', 'wiauia' ); ?></option>
     36                        <option <?php selected( esc_attr( get_option( 'rounded', 'false' ) ) == 'false' ); ?> value="false"><?php echo __( 'No - Square avatar', 'wp-initials-avatar' ); ?></option>
     37                        <option <?php selected( esc_attr( get_option( 'rounded', 'false' ) ) == 'true' ); ?> value="true"><?php echo __( 'Yes - Rounded avatar', 'wp-initials-avatar' ); ?></option>
    5538                    </select>
    5639                </td>
     
    5841
    5942            <tr valign="top">
    60                 <th scope="row"><?php _e( 'Uppercase letters?', 'wiauia' ); ?></th>
     43                <th scope="row"><?php _e( 'Uppercase letters?', 'wp-initials-avatar' ); ?></th>
    6144                <td>
    6245                    <select name="uppercase">
    63                         <option <?php selected( esc_attr( get_option( 'uppercase', 'true' ) ) == 'true' ); ?> value="true"><?php echo translate( 'Yes', 'wiauia' ); ?></option>
    64                         <option <?php selected( esc_attr( get_option( 'uppercase', 'true' ) ) == 'false' ); ?> value="false"><?php echo translate( 'No - Do not modify lettercase', 'wiauia' ); ?></option>
     46                        <option <?php selected( esc_attr( get_option( 'uppercase', 'true' ) ) == 'true' ); ?> value="true"><?php echo __( 'Yes', 'wp-initials-avatar' ); ?></option>
     47                        <option <?php selected( esc_attr( get_option( 'uppercase', 'true' ) ) == 'false' ); ?> value="false"><?php echo __( 'No - Do not modify lettercase', 'wp-initials-avatar' ); ?></option>
    6548                    </select>
    6649                </td>
  • wp-initials-avatar/tags/0.8/readme.txt

    r1769240 r1932035  
    1 == Wordpress Initial Avatars ==
    2 Tested up to: 4.9
     1== WordPress Initial Avatars ==
     2Tested up to: 4.8.2
    33Requires at least: 3.5
    44Requires PHP: 5.6
    5 Stable tag: 0.7
     5Stable tag: 0.8
    66License: MIT
    77License URI: https://opensource.org/licenses/MIT
    8 Contributors: LasseRafn
     8Contributors: LasseRafn, mayukojpn, abecoffman
    99
    1010Plugin to replace default avatars with user initials generated from their name.
     
    1616== Installation ==
    1717
    18 1. Upload the plugin files to the `/wp-content/plugins/wp-initials-avatar` directory, or install the plugin through the Wordpress plugins screen directly.
    19 2. Activate the plugin through the 'Plugins' screen in Wordpress.
     181. Upload the plugin files to the `/wp-content/plugins/wp-initials-avatar` directory, or install the plugin through the WordPress plugins screen directly.
     192. Activate the plugin through the 'Plugins' screen in WordPress.
    20203. Navigate to Settings -> Avatar settings and configure the plugin
    2121
     
    2525
    2626== Changelog ==
     27
     28= 0.8 =
     29* Spelling fixex (thanks mayukojpn)
     30* Translate-ability (thanks mayukojpn)
     31* Removed PHP coalesce operator (thanks abecoffman)
     32* Bugfixes and more (thanks mayukojpn)
    2733
    2834= 0.7 =
     
    3541* Updated readme
    3642
    37 == Terms of Usage ==
     43== Terms of usage ==
     44We do not track usage, and there is no limits. It's free to use and everything is done to assure fast responses with least delay.
    3845
    39 
    40 We do not track usage, and there is no limits. It’s free to use and everything is done to assure fast responses with least delay.
    41 Only terms are that we (the API) is not liable, and you agree to typical MIT licensing. Please use the service with respect, considering that some people depend on it, and it’s limitless and free. Be nice, that’s the only terms of usage.
     46Only terms are that we (the API) is not liable, and you agree to typical MIT licensing. Please use the service with respect, considering that some people depend on it, and it's limitless and free. Be nice, that's the only terms of usage.
  • wp-initials-avatar/tags/0.8/wordpress-initials-avatar.php

    r1769240 r1932035  
    22
    33/*
    4 Plugin Name: Wordpress Initials Avatar
     4Plugin Name: WordPress Initials Avatar
    55Plugin URI: https://github.com/LasseRafn/wordpress-initials-avatar
    66Description: Replaces the default avatars with initials
    7 Version: 0.7
     7Version: 0.8
    88Author: lasserafn
    99Author URI: https://github.com/LasseRafn
     
    1212
    1313if ( is_admin() ) { // admin actions
    14     add_action( 'admin_init', 'register_wiauia_settings' );
    15     add_action( 'admin_menu', 'wiauia_settings_menu' );
     14    add_action( 'admin_init', 'register_wp_ui_avatars_settings' );
     15    add_action( 'admin_menu', 'wp_ui_avatars_settings_menu' );
    1616
    17     function wiauia_settings_menu() {
    18         add_submenu_page( 'options-general.php', translate( 'User Initials Avatar Setitngs', 'wiauia' ), 'Avatar settings', 'administrator', __FILE__, 'wiauia_settings_page' );
    19         add_action( 'admin_init', 'register_wiauia_settings' );
     17    function wp_ui_avatars_settings_menu() {
     18        add_submenu_page( 'options-general.php', __( 'User Initials Avatar Setitngs', 'wp-initials-avatar' ), 'Avatar settings', 'administrator', __FILE__, 'wp_ui_avatars_settings_page' );
     19        add_action( 'admin_init', 'register_wp_ui_avatars_settings' );
    2020    }
    2121
    22     function register_wiauia_settings() {
     22    function register_wp_ui_avatars_settings() {
    2323        register_setting( 'wiauia-settings', 'color' );
    2424        register_setting( 'wiauia-settings', 'background' );
    2525        register_setting( 'wiauia-settings', 'length' );
    26         register_setting( 'wiauia-settings', 'size' );
    2726        register_setting( 'wiauia-settings', 'uppercase' );
    2827        register_setting( 'wiauia-settings', 'rounded' );
    2928    }
    3029
    31     function wiauia_enqueue_color_picker() {
     30    function wp_ui_avatars_enqueue_color_picker() {
    3231        wp_enqueue_style( 'wp-color-picker' );
    3332        wp_enqueue_script( 'my-script-handle', plugins_url( 'settings.js', __FILE__ ), [ 'wp-color-picker' ], false, true );
    3433    }
    3534
    36     add_action( 'admin_enqueue_scripts', 'wiauia_enqueue_color_picker' );
     35    add_action( 'admin_enqueue_scripts', 'wp_ui_avatars_enqueue_color_picker' );
    3736
    38     function wiauia_settings_page() {
     37    function wp_ui_avatars_settings_page() {
    3938
    4039        require_once __DIR__ . '/options.php';
     
    4241}
    4342
    44 add_filter( 'get_avatar', 'wordpress_initials_avatar', 1, 6 );
     43add_filter( 'get_avatar_url', 'wordpress_initials_avatar', 10, 3 );
    4544
    46 function wordpress_initials_avatar( $avatar, $id_or_email, $size, $default, $alt, $args ) {
    47     if ( $default !== 'initials' && $args['force_default'] ?? false ) {
    48         return $avatar;
     45function wordpress_initials_avatar( $url, $id_or_email, $args ) {
     46    if ( $args['default'] !== 'initials' && ( $args['force_default'] || false ) ) {
     47        return $url;
    4948    }
    5049
     
    7170    }
    7271
    73     $size       = esc_attr( get_option( 'size', $size ) );
    74     $size2x = $size * 2;
     72    $size       = $args['size'];
    7573    $background = esc_attr( get_option( 'background', 'ddd' ) );
    7674    $color      = esc_attr( get_option( 'color', '222' ) );
     
    8381    $background = str_replace( '#', '', $background );
    8482
    85     $url = $args['url'];
    86     $url = explode( 'd=', $url );
     83    $param      = explode( 'd=', $url );
    8784
    88     if ( count( $url ) >= 1 ) {
    89         $url = explode( '&', $url[ count( $url ) - 1 ] );
    90 
    91         $url2x  = str_replace( $url[0], urlencode( 'https://ui-avatars.com/api/' . urlencode( $name ) . "/{$size2x}/{$background}/{$color}/{$length}/{$fontSize}/{$rounded}/{$uppercase}" ), $args['url'] );
    92         $args['url'] = str_replace( $url[0], urlencode( 'https://ui-avatars.com/api/' . urlencode( $name ) . "/{$size}/{$background}/{$color}/{$length}/{$fontSize}/{$rounded}/{$uppercase}" ), $args['url'] );
     85    if ( count( $param ) >= 1 ) {
     86        $param = explode( '&', $param[1] );
     87        $url   = str_replace( $param[0], urlencode( 'https://ui-avatars.com/api/' . urlencode( $name ) . "/{$size}/{$background}/{$color}/{$length}/{$fontSize}/{$rounded}/{$uppercase}" ), $url );
    9388    } else {
    94         $args['url'] = urlencode( 'https://ui-avatars.com/api/' . urlencode( $name ) . "/{$size}/{$background}/{$color}/{$length}/{$fontSize}/{$rounded}/{$uppercase}" );
    95         $url2x  = 'https://ui-avatars.com/api/' . urlencode( $name ) . "/{$size2x}/{$background}/{$color}/{$length}/{$fontSize}/{$rounded}/{$uppercase}";
     89        $url   = urlencode( 'https://ui-avatars.com/api/' . urlencode( $name ) . "/{$size}/{$background}/{$color}/{$length}/{$fontSize}/{$rounded}/{$uppercase}" );
    9690    }
    9791
    98     if ( ! is_array( $args['class'] ) ) {
    99         $args['class'] = [ $args['class'] ];
    100     }
     92    return $url;
    10193
    102     $avatar = sprintf(
    103         "<img alt='%s' src='%s' srcset='%s' class='avatar %s' height='%d' width='%d' %s/>",
    104         esc_attr( $args['alt'] ),
    105         esc_url( $args['url'] ),
    106         esc_attr( "$url2x 2x" ),
    107         esc_attr( implode( ' ', $args['class'] ) ),
    108         (int) $args['height'],
    109         (int) $args['width'],
    110         $args['extra_attr']
    111     );
    112 
    113     return $avatar;
    11494}
  • wp-initials-avatar/trunk/options.php

    r1769240 r1932035  
    11<div class="wrap">
    2     <h1><?php _e( 'User Initials Avatar Setitngs', 'wiauia' ); ?></h1>
     2    <h1><?php _e( 'User Initials Avatar Setitngs', 'wp-initials-avatar' ); ?></h1>
    33
    44    <form method="post" action="options.php">
     
    99        <table class="form-table">
    1010            <tr valign="top">
    11                 <th scope="row"><?php _e( 'Font color', 'wiauia' ); ?></th>
     11                <th scope="row"><?php _e( 'Font color', 'wp-initials-avatar' ); ?></th>
    1212                <td><input type="text" name="color" data-default="#222222" value="<?php echo esc_attr( get_option( 'color', '#222222' ) ); ?>" class="my-color-field"/></td>
    1313            </tr>
    1414
    1515            <tr valign="top">
    16                 <th scope="row"><?php _e( 'Background color', 'wiauia' ); ?></th>
     16                <th scope="row"><?php _e( 'Background color', 'wp-initials-avatar' ); ?></th>
    1717                <td><input type="text" name="background" data-default="#dddddd" value="<?php echo esc_attr( get_option( 'background', '#dddddd' ) ); ?>" class="my-color-field"/></td>
    1818            </tr>
    1919
    2020            <tr valign="top">
    21                 <th scope="row"><?php _e( 'Length', 'wiauia' ); ?></th>
     21                <th scope="row"><?php _e( 'Length', 'wp-initials-avatar' ); ?></th>
    2222                <td>
    2323                    <select name="length">
    24                         <option <?php selected( esc_attr( get_option( 'length', 2 ) ) == 1 ); ?> value="1"><?php echo sprintf( translate( '%s letter', 'wiauia' ), 1 ); ?></option>
    25                         <option <?php selected( esc_attr( get_option( 'length', 2 ) ) == 2 ); ?> value="2"><?php echo sprintf( translate( '%s letters', 'wiauia' ), 2 ); ?></option>
    26                         <option <?php selected( esc_attr( get_option( 'length', 2 ) ) == 3 ); ?> value="3"><?php echo sprintf( translate( '%s letters', 'wiauia' ), 3 ); ?></option>
    27                         <option <?php selected( esc_attr( get_option( 'length', 2 ) ) == 4 ); ?> value="4"><?php echo sprintf( translate( '%s letters', 'wiauia' ), 4 ); ?></option>
    28                     </select>
    29                 </td>
    30             </tr>
    31 
    32             <tr valign="top">
    33                 <th scope="row"><?php _e( 'Image size', 'wiauia' ); ?></th>
    34                 <td>
    35                     <select name="size">
    36                         <option <?php selected( esc_attr( get_option( 'size', 64 ) ) == 16 ); ?> value="16"><?php echo sprintf( translate( '%sx%s pixels', 'wiauia' ), 16, 16 ); ?></option>
    37                         <option <?php selected( esc_attr( get_option( 'size', 64 ) ) == 24 ); ?> value="24"><?php echo sprintf( translate( '%sx%s pixels', 'wiauia' ), 24, 24 ); ?></option>
    38                         <option <?php selected( esc_attr( get_option( 'size', 64 ) ) == 32 ); ?> value="32"><?php echo sprintf( translate( '%sx%s pixels', 'wiauia' ), 32, 32 ); ?></option>
    39                         <option <?php selected( esc_attr( get_option( 'size', 64 ) ) == 48 ); ?> value="48"><?php echo sprintf( translate( '%sx%s pixels', 'wiauia' ), 48, 48 ); ?></option>
    40                         <option <?php selected( esc_attr( get_option( 'size', 64 ) ) == 64 ); ?> value="64"><?php echo sprintf( translate( '%sx%s pixels', 'wiauia' ), 64, 64 ); ?></option>
    41                         <option <?php selected( esc_attr( get_option( 'size', 64 ) ) == 96 ); ?> value="96"><?php echo sprintf( translate( '%sx%s pixels', 'wiauia' ), 96, 96 ); ?></option>
    42                         <option <?php selected( esc_attr( get_option( 'size', 64 ) ) == 128 ); ?> value="128"><?php echo sprintf( translate( '%sx%s pixels', 'wiauia' ), 128, 128 ); ?></option>
    43                         <option <?php selected( esc_attr( get_option( 'size', 64 ) ) == 192 ); ?> value="192"><?php echo sprintf( translate( '%sx%s pixels', 'wiauia' ), 192, 192 ); ?></option>
    44                         <option <?php selected( esc_attr( get_option( 'size', 64 ) ) == 256 ); ?> value="256"><?php echo sprintf( translate( '%sx%s pixels', 'wiauia' ), 256, 256 ); ?></option>
     24                        <option <?php selected( esc_attr( get_option( 'length', 2 ) ) == 1 ); ?> value="1"><?php echo sprintf( __( '%s letter', 'wp-initials-avatar' ), 1 ); ?></option>
     25                        <option <?php selected( esc_attr( get_option( 'length', 2 ) ) == 2 ); ?> value="2"><?php echo sprintf( __( '%s letters', 'wp-initials-avatar' ), 2 ); ?></option>
     26                        <option <?php selected( esc_attr( get_option( 'length', 2 ) ) == 3 ); ?> value="3"><?php echo sprintf( __( '%s letters', 'wp-initials-avatar' ), 3 ); ?></option>
     27                        <option <?php selected( esc_attr( get_option( 'length', 2 ) ) == 4 ); ?> value="4"><?php echo sprintf( __( '%s letters', 'wp-initials-avatar' ), 4 ); ?></option>
    4528                    </select>
    4629                </td>
     
    5134                <td>
    5235                    <select name="rounded">
    53                         <option <?php selected( esc_attr( get_option( 'rounded', 'false' ) ) == 'false' ); ?> value="false"><?php echo translate( 'No - Square avatar', 'wiauia' ); ?></option>
    54                         <option <?php selected( esc_attr( get_option( 'rounded', 'false' ) ) == 'true' ); ?> value="true"><?php echo translate( 'Yes - Rounded avatar', 'wiauia' ); ?></option>
     36                        <option <?php selected( esc_attr( get_option( 'rounded', 'false' ) ) == 'false' ); ?> value="false"><?php echo __( 'No - Square avatar', 'wp-initials-avatar' ); ?></option>
     37                        <option <?php selected( esc_attr( get_option( 'rounded', 'false' ) ) == 'true' ); ?> value="true"><?php echo __( 'Yes - Rounded avatar', 'wp-initials-avatar' ); ?></option>
    5538                    </select>
    5639                </td>
     
    5841
    5942            <tr valign="top">
    60                 <th scope="row"><?php _e( 'Uppercase letters?', 'wiauia' ); ?></th>
     43                <th scope="row"><?php _e( 'Uppercase letters?', 'wp-initials-avatar' ); ?></th>
    6144                <td>
    6245                    <select name="uppercase">
    63                         <option <?php selected( esc_attr( get_option( 'uppercase', 'true' ) ) == 'true' ); ?> value="true"><?php echo translate( 'Yes', 'wiauia' ); ?></option>
    64                         <option <?php selected( esc_attr( get_option( 'uppercase', 'true' ) ) == 'false' ); ?> value="false"><?php echo translate( 'No - Do not modify lettercase', 'wiauia' ); ?></option>
     46                        <option <?php selected( esc_attr( get_option( 'uppercase', 'true' ) ) == 'true' ); ?> value="true"><?php echo __( 'Yes', 'wp-initials-avatar' ); ?></option>
     47                        <option <?php selected( esc_attr( get_option( 'uppercase', 'true' ) ) == 'false' ); ?> value="false"><?php echo __( 'No - Do not modify lettercase', 'wp-initials-avatar' ); ?></option>
    6548                    </select>
    6649                </td>
  • wp-initials-avatar/trunk/readme.txt

    r1769240 r1932035  
    1 == Wordpress Initial Avatars ==
    2 Tested up to: 4.9
     1== WordPress Initial Avatars ==
     2Tested up to: 4.8.2
    33Requires at least: 3.5
    44Requires PHP: 5.6
    5 Stable tag: 0.7
     5Stable tag: 0.8
    66License: MIT
    77License URI: https://opensource.org/licenses/MIT
    8 Contributors: LasseRafn
     8Contributors: LasseRafn, mayukojpn, abecoffman
    99
    1010Plugin to replace default avatars with user initials generated from their name.
     
    1616== Installation ==
    1717
    18 1. Upload the plugin files to the `/wp-content/plugins/wp-initials-avatar` directory, or install the plugin through the Wordpress plugins screen directly.
    19 2. Activate the plugin through the 'Plugins' screen in Wordpress.
     181. Upload the plugin files to the `/wp-content/plugins/wp-initials-avatar` directory, or install the plugin through the WordPress plugins screen directly.
     192. Activate the plugin through the 'Plugins' screen in WordPress.
    20203. Navigate to Settings -> Avatar settings and configure the plugin
    2121
     
    2525
    2626== Changelog ==
     27
     28= 0.8 =
     29* Spelling fixex (thanks mayukojpn)
     30* Translate-ability (thanks mayukojpn)
     31* Removed PHP coalesce operator (thanks abecoffman)
     32* Bugfixes and more (thanks mayukojpn)
    2733
    2834= 0.7 =
     
    3541* Updated readme
    3642
    37 == Terms of Usage ==
     43== Terms of usage ==
     44We do not track usage, and there is no limits. It's free to use and everything is done to assure fast responses with least delay.
    3845
    39 
    40 We do not track usage, and there is no limits. It’s free to use and everything is done to assure fast responses with least delay.
    41 Only terms are that we (the API) is not liable, and you agree to typical MIT licensing. Please use the service with respect, considering that some people depend on it, and it’s limitless and free. Be nice, that’s the only terms of usage.
     46Only terms are that we (the API) is not liable, and you agree to typical MIT licensing. Please use the service with respect, considering that some people depend on it, and it's limitless and free. Be nice, that's the only terms of usage.
  • wp-initials-avatar/trunk/wordpress-initials-avatar.php

    r1769240 r1932035  
    22
    33/*
    4 Plugin Name: Wordpress Initials Avatar
     4Plugin Name: WordPress Initials Avatar
    55Plugin URI: https://github.com/LasseRafn/wordpress-initials-avatar
    66Description: Replaces the default avatars with initials
    7 Version: 0.7
     7Version: 0.8
    88Author: lasserafn
    99Author URI: https://github.com/LasseRafn
     
    1212
    1313if ( is_admin() ) { // admin actions
    14     add_action( 'admin_init', 'register_wiauia_settings' );
    15     add_action( 'admin_menu', 'wiauia_settings_menu' );
     14    add_action( 'admin_init', 'register_wp_ui_avatars_settings' );
     15    add_action( 'admin_menu', 'wp_ui_avatars_settings_menu' );
    1616
    17     function wiauia_settings_menu() {
    18         add_submenu_page( 'options-general.php', translate( 'User Initials Avatar Setitngs', 'wiauia' ), 'Avatar settings', 'administrator', __FILE__, 'wiauia_settings_page' );
    19         add_action( 'admin_init', 'register_wiauia_settings' );
     17    function wp_ui_avatars_settings_menu() {
     18        add_submenu_page( 'options-general.php', __( 'User Initials Avatar Setitngs', 'wp-initials-avatar' ), 'Avatar settings', 'administrator', __FILE__, 'wp_ui_avatars_settings_page' );
     19        add_action( 'admin_init', 'register_wp_ui_avatars_settings' );
    2020    }
    2121
    22     function register_wiauia_settings() {
     22    function register_wp_ui_avatars_settings() {
    2323        register_setting( 'wiauia-settings', 'color' );
    2424        register_setting( 'wiauia-settings', 'background' );
    2525        register_setting( 'wiauia-settings', 'length' );
    26         register_setting( 'wiauia-settings', 'size' );
    2726        register_setting( 'wiauia-settings', 'uppercase' );
    2827        register_setting( 'wiauia-settings', 'rounded' );
    2928    }
    3029
    31     function wiauia_enqueue_color_picker() {
     30    function wp_ui_avatars_enqueue_color_picker() {
    3231        wp_enqueue_style( 'wp-color-picker' );
    3332        wp_enqueue_script( 'my-script-handle', plugins_url( 'settings.js', __FILE__ ), [ 'wp-color-picker' ], false, true );
    3433    }
    3534
    36     add_action( 'admin_enqueue_scripts', 'wiauia_enqueue_color_picker' );
     35    add_action( 'admin_enqueue_scripts', 'wp_ui_avatars_enqueue_color_picker' );
    3736
    38     function wiauia_settings_page() {
     37    function wp_ui_avatars_settings_page() {
    3938
    4039        require_once __DIR__ . '/options.php';
     
    4241}
    4342
    44 add_filter( 'get_avatar', 'wordpress_initials_avatar', 1, 6 );
     43add_filter( 'get_avatar_url', 'wordpress_initials_avatar', 10, 3 );
    4544
    46 function wordpress_initials_avatar( $avatar, $id_or_email, $size, $default, $alt, $args ) {
    47     if ( $default !== 'initials' && $args['force_default'] ?? false ) {
    48         return $avatar;
     45function wordpress_initials_avatar( $url, $id_or_email, $args ) {
     46    if ( $args['default'] !== 'initials' && ( $args['force_default'] || false ) ) {
     47        return $url;
    4948    }
    5049
     
    7170    }
    7271
    73     $size       = esc_attr( get_option( 'size', $size ) );
    74     $size2x = $size * 2;
     72    $size       = $args['size'];
    7573    $background = esc_attr( get_option( 'background', 'ddd' ) );
    7674    $color      = esc_attr( get_option( 'color', '222' ) );
     
    8381    $background = str_replace( '#', '', $background );
    8482
    85     $url = $args['url'];
    86     $url = explode( 'd=', $url );
     83    $param      = explode( 'd=', $url );
    8784
    88     if ( count( $url ) >= 1 ) {
    89         $url = explode( '&', $url[ count( $url ) - 1 ] );
    90 
    91         $url2x  = str_replace( $url[0], urlencode( 'https://ui-avatars.com/api/' . urlencode( $name ) . "/{$size2x}/{$background}/{$color}/{$length}/{$fontSize}/{$rounded}/{$uppercase}" ), $args['url'] );
    92         $args['url'] = str_replace( $url[0], urlencode( 'https://ui-avatars.com/api/' . urlencode( $name ) . "/{$size}/{$background}/{$color}/{$length}/{$fontSize}/{$rounded}/{$uppercase}" ), $args['url'] );
     85    if ( count( $param ) >= 1 ) {
     86        $param = explode( '&', $param[1] );
     87        $url   = str_replace( $param[0], urlencode( 'https://ui-avatars.com/api/' . urlencode( $name ) . "/{$size}/{$background}/{$color}/{$length}/{$fontSize}/{$rounded}/{$uppercase}" ), $url );
    9388    } else {
    94         $args['url'] = urlencode( 'https://ui-avatars.com/api/' . urlencode( $name ) . "/{$size}/{$background}/{$color}/{$length}/{$fontSize}/{$rounded}/{$uppercase}" );
    95         $url2x  = 'https://ui-avatars.com/api/' . urlencode( $name ) . "/{$size2x}/{$background}/{$color}/{$length}/{$fontSize}/{$rounded}/{$uppercase}";
     89        $url   = urlencode( 'https://ui-avatars.com/api/' . urlencode( $name ) . "/{$size}/{$background}/{$color}/{$length}/{$fontSize}/{$rounded}/{$uppercase}" );
    9690    }
    9791
    98     if ( ! is_array( $args['class'] ) ) {
    99         $args['class'] = [ $args['class'] ];
    100     }
     92    return $url;
    10193
    102     $avatar = sprintf(
    103         "<img alt='%s' src='%s' srcset='%s' class='avatar %s' height='%d' width='%d' %s/>",
    104         esc_attr( $args['alt'] ),
    105         esc_url( $args['url'] ),
    106         esc_attr( "$url2x 2x" ),
    107         esc_attr( implode( ' ', $args['class'] ) ),
    108         (int) $args['height'],
    109         (int) $args['width'],
    110         $args['extra_attr']
    111     );
    112 
    113     return $avatar;
    11494}
Note: See TracChangeset for help on using the changeset viewer.