Changeset 1932035
- Timestamp:
- 08/28/2018 09:01:42 PM (8 years ago)
- Location:
- wp-initials-avatar
- Files:
-
- 3 edited
- 4 copied
-
tags/0.8 (copied) (copied from wp-initials-avatar/trunk)
-
tags/0.8/options.php (copied) (copied from wp-initials-avatar/trunk/options.php) (4 diffs)
-
tags/0.8/readme.txt (copied) (copied from wp-initials-avatar/trunk/readme.txt) (4 diffs)
-
tags/0.8/wordpress-initials-avatar.php (copied) (copied from wp-initials-avatar/trunk/wordpress-initials-avatar.php) (5 diffs)
-
trunk/options.php (modified) (4 diffs)
-
trunk/readme.txt (modified) (4 diffs)
-
trunk/wordpress-initials-avatar.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-initials-avatar/tags/0.8/options.php
r1769240 r1932035 1 1 <div class="wrap"> 2 <h1><?php _e( 'User Initials Avatar Setitngs', 'w iauia' ); ?></h1>2 <h1><?php _e( 'User Initials Avatar Setitngs', 'wp-initials-avatar' ); ?></h1> 3 3 4 4 <form method="post" action="options.php"> … … 9 9 <table class="form-table"> 10 10 <tr valign="top"> 11 <th scope="row"><?php _e( 'Font color', 'w iauia' ); ?></th>11 <th scope="row"><?php _e( 'Font color', 'wp-initials-avatar' ); ?></th> 12 12 <td><input type="text" name="color" data-default="#222222" value="<?php echo esc_attr( get_option( 'color', '#222222' ) ); ?>" class="my-color-field"/></td> 13 13 </tr> 14 14 15 15 <tr valign="top"> 16 <th scope="row"><?php _e( 'Background color', 'w iauia' ); ?></th>16 <th scope="row"><?php _e( 'Background color', 'wp-initials-avatar' ); ?></th> 17 17 <td><input type="text" name="background" data-default="#dddddd" value="<?php echo esc_attr( get_option( 'background', '#dddddd' ) ); ?>" class="my-color-field"/></td> 18 18 </tr> 19 19 20 20 <tr valign="top"> 21 <th scope="row"><?php _e( 'Length', 'w iauia' ); ?></th>21 <th scope="row"><?php _e( 'Length', 'wp-initials-avatar' ); ?></th> 22 22 <td> 23 23 <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> 45 28 </select> 46 29 </td> … … 51 34 <td> 52 35 <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> 55 38 </select> 56 39 </td> … … 58 41 59 42 <tr valign="top"> 60 <th scope="row"><?php _e( 'Uppercase letters?', 'w iauia' ); ?></th>43 <th scope="row"><?php _e( 'Uppercase letters?', 'wp-initials-avatar' ); ?></th> 61 44 <td> 62 45 <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> 65 48 </select> 66 49 </td> -
wp-initials-avatar/tags/0.8/readme.txt
r1769240 r1932035 1 == Word press Initial Avatars ==2 Tested up to: 4. 91 == WordPress Initial Avatars == 2 Tested up to: 4.8.2 3 3 Requires at least: 3.5 4 4 Requires PHP: 5.6 5 Stable tag: 0. 75 Stable tag: 0.8 6 6 License: MIT 7 7 License URI: https://opensource.org/licenses/MIT 8 Contributors: LasseRafn 8 Contributors: LasseRafn, mayukojpn, abecoffman 9 9 10 10 Plugin to replace default avatars with user initials generated from their name. … … 16 16 == Installation == 17 17 18 1. Upload the plugin files to the `/wp-content/plugins/wp-initials-avatar` directory, or install the plugin through the Word press plugins screen directly.19 2. Activate the plugin through the 'Plugins' screen in Word press.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. 20 20 3. Navigate to Settings -> Avatar settings and configure the plugin 21 21 … … 25 25 26 26 == 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) 27 33 28 34 = 0.7 = … … 35 41 * Updated readme 36 42 37 == Terms of Usage == 43 == Terms of usage == 44 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. 38 45 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. 46 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. -
wp-initials-avatar/tags/0.8/wordpress-initials-avatar.php
r1769240 r1932035 2 2 3 3 /* 4 Plugin Name: Word press Initials Avatar4 Plugin Name: WordPress Initials Avatar 5 5 Plugin URI: https://github.com/LasseRafn/wordpress-initials-avatar 6 6 Description: Replaces the default avatars with initials 7 Version: 0. 77 Version: 0.8 8 8 Author: lasserafn 9 9 Author URI: https://github.com/LasseRafn … … 12 12 13 13 if ( is_admin() ) { // admin actions 14 add_action( 'admin_init', 'register_w iauia_settings' );15 add_action( 'admin_menu', 'w iauia_settings_menu' );14 add_action( 'admin_init', 'register_wp_ui_avatars_settings' ); 15 add_action( 'admin_menu', 'wp_ui_avatars_settings_menu' ); 16 16 17 function w iauia_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_w iauia_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' ); 20 20 } 21 21 22 function register_w iauia_settings() {22 function register_wp_ui_avatars_settings() { 23 23 register_setting( 'wiauia-settings', 'color' ); 24 24 register_setting( 'wiauia-settings', 'background' ); 25 25 register_setting( 'wiauia-settings', 'length' ); 26 register_setting( 'wiauia-settings', 'size' );27 26 register_setting( 'wiauia-settings', 'uppercase' ); 28 27 register_setting( 'wiauia-settings', 'rounded' ); 29 28 } 30 29 31 function w iauia_enqueue_color_picker() {30 function wp_ui_avatars_enqueue_color_picker() { 32 31 wp_enqueue_style( 'wp-color-picker' ); 33 32 wp_enqueue_script( 'my-script-handle', plugins_url( 'settings.js', __FILE__ ), [ 'wp-color-picker' ], false, true ); 34 33 } 35 34 36 add_action( 'admin_enqueue_scripts', 'w iauia_enqueue_color_picker' );35 add_action( 'admin_enqueue_scripts', 'wp_ui_avatars_enqueue_color_picker' ); 37 36 38 function w iauia_settings_page() {37 function wp_ui_avatars_settings_page() { 39 38 40 39 require_once __DIR__ . '/options.php'; … … 42 41 } 43 42 44 add_filter( 'get_avatar ', 'wordpress_initials_avatar', 1, 6);43 add_filter( 'get_avatar_url', 'wordpress_initials_avatar', 10, 3 ); 45 44 46 function wordpress_initials_avatar( $ avatar, $id_or_email, $size, $default, $alt, $args ) {47 if ( $ default !== 'initials' && $args['force_default'] ?? false) {48 return $ avatar;45 function wordpress_initials_avatar( $url, $id_or_email, $args ) { 46 if ( $args['default'] !== 'initials' && ( $args['force_default'] || false ) ) { 47 return $url; 49 48 } 50 49 … … 71 70 } 72 71 73 $size = esc_attr( get_option( 'size', $size ) ); 74 $size2x = $size * 2; 72 $size = $args['size']; 75 73 $background = esc_attr( get_option( 'background', 'ddd' ) ); 76 74 $color = esc_attr( get_option( 'color', '222' ) ); … … 83 81 $background = str_replace( '#', '', $background ); 84 82 85 $url = $args['url']; 86 $url = explode( 'd=', $url ); 83 $param = explode( 'd=', $url ); 87 84 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 ); 93 88 } 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}" ); 96 90 } 97 91 98 if ( ! is_array( $args['class'] ) ) { 99 $args['class'] = [ $args['class'] ]; 100 } 92 return $url; 101 93 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;114 94 } -
wp-initials-avatar/trunk/options.php
r1769240 r1932035 1 1 <div class="wrap"> 2 <h1><?php _e( 'User Initials Avatar Setitngs', 'w iauia' ); ?></h1>2 <h1><?php _e( 'User Initials Avatar Setitngs', 'wp-initials-avatar' ); ?></h1> 3 3 4 4 <form method="post" action="options.php"> … … 9 9 <table class="form-table"> 10 10 <tr valign="top"> 11 <th scope="row"><?php _e( 'Font color', 'w iauia' ); ?></th>11 <th scope="row"><?php _e( 'Font color', 'wp-initials-avatar' ); ?></th> 12 12 <td><input type="text" name="color" data-default="#222222" value="<?php echo esc_attr( get_option( 'color', '#222222' ) ); ?>" class="my-color-field"/></td> 13 13 </tr> 14 14 15 15 <tr valign="top"> 16 <th scope="row"><?php _e( 'Background color', 'w iauia' ); ?></th>16 <th scope="row"><?php _e( 'Background color', 'wp-initials-avatar' ); ?></th> 17 17 <td><input type="text" name="background" data-default="#dddddd" value="<?php echo esc_attr( get_option( 'background', '#dddddd' ) ); ?>" class="my-color-field"/></td> 18 18 </tr> 19 19 20 20 <tr valign="top"> 21 <th scope="row"><?php _e( 'Length', 'w iauia' ); ?></th>21 <th scope="row"><?php _e( 'Length', 'wp-initials-avatar' ); ?></th> 22 22 <td> 23 23 <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> 45 28 </select> 46 29 </td> … … 51 34 <td> 52 35 <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> 55 38 </select> 56 39 </td> … … 58 41 59 42 <tr valign="top"> 60 <th scope="row"><?php _e( 'Uppercase letters?', 'w iauia' ); ?></th>43 <th scope="row"><?php _e( 'Uppercase letters?', 'wp-initials-avatar' ); ?></th> 61 44 <td> 62 45 <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> 65 48 </select> 66 49 </td> -
wp-initials-avatar/trunk/readme.txt
r1769240 r1932035 1 == Word press Initial Avatars ==2 Tested up to: 4. 91 == WordPress Initial Avatars == 2 Tested up to: 4.8.2 3 3 Requires at least: 3.5 4 4 Requires PHP: 5.6 5 Stable tag: 0. 75 Stable tag: 0.8 6 6 License: MIT 7 7 License URI: https://opensource.org/licenses/MIT 8 Contributors: LasseRafn 8 Contributors: LasseRafn, mayukojpn, abecoffman 9 9 10 10 Plugin to replace default avatars with user initials generated from their name. … … 16 16 == Installation == 17 17 18 1. Upload the plugin files to the `/wp-content/plugins/wp-initials-avatar` directory, or install the plugin through the Word press plugins screen directly.19 2. Activate the plugin through the 'Plugins' screen in Word press.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. 20 20 3. Navigate to Settings -> Avatar settings and configure the plugin 21 21 … … 25 25 26 26 == 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) 27 33 28 34 = 0.7 = … … 35 41 * Updated readme 36 42 37 == Terms of Usage == 43 == Terms of usage == 44 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. 38 45 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. 46 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. -
wp-initials-avatar/trunk/wordpress-initials-avatar.php
r1769240 r1932035 2 2 3 3 /* 4 Plugin Name: Word press Initials Avatar4 Plugin Name: WordPress Initials Avatar 5 5 Plugin URI: https://github.com/LasseRafn/wordpress-initials-avatar 6 6 Description: Replaces the default avatars with initials 7 Version: 0. 77 Version: 0.8 8 8 Author: lasserafn 9 9 Author URI: https://github.com/LasseRafn … … 12 12 13 13 if ( is_admin() ) { // admin actions 14 add_action( 'admin_init', 'register_w iauia_settings' );15 add_action( 'admin_menu', 'w iauia_settings_menu' );14 add_action( 'admin_init', 'register_wp_ui_avatars_settings' ); 15 add_action( 'admin_menu', 'wp_ui_avatars_settings_menu' ); 16 16 17 function w iauia_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_w iauia_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' ); 20 20 } 21 21 22 function register_w iauia_settings() {22 function register_wp_ui_avatars_settings() { 23 23 register_setting( 'wiauia-settings', 'color' ); 24 24 register_setting( 'wiauia-settings', 'background' ); 25 25 register_setting( 'wiauia-settings', 'length' ); 26 register_setting( 'wiauia-settings', 'size' );27 26 register_setting( 'wiauia-settings', 'uppercase' ); 28 27 register_setting( 'wiauia-settings', 'rounded' ); 29 28 } 30 29 31 function w iauia_enqueue_color_picker() {30 function wp_ui_avatars_enqueue_color_picker() { 32 31 wp_enqueue_style( 'wp-color-picker' ); 33 32 wp_enqueue_script( 'my-script-handle', plugins_url( 'settings.js', __FILE__ ), [ 'wp-color-picker' ], false, true ); 34 33 } 35 34 36 add_action( 'admin_enqueue_scripts', 'w iauia_enqueue_color_picker' );35 add_action( 'admin_enqueue_scripts', 'wp_ui_avatars_enqueue_color_picker' ); 37 36 38 function w iauia_settings_page() {37 function wp_ui_avatars_settings_page() { 39 38 40 39 require_once __DIR__ . '/options.php'; … … 42 41 } 43 42 44 add_filter( 'get_avatar ', 'wordpress_initials_avatar', 1, 6);43 add_filter( 'get_avatar_url', 'wordpress_initials_avatar', 10, 3 ); 45 44 46 function wordpress_initials_avatar( $ avatar, $id_or_email, $size, $default, $alt, $args ) {47 if ( $ default !== 'initials' && $args['force_default'] ?? false) {48 return $ avatar;45 function wordpress_initials_avatar( $url, $id_or_email, $args ) { 46 if ( $args['default'] !== 'initials' && ( $args['force_default'] || false ) ) { 47 return $url; 49 48 } 50 49 … … 71 70 } 72 71 73 $size = esc_attr( get_option( 'size', $size ) ); 74 $size2x = $size * 2; 72 $size = $args['size']; 75 73 $background = esc_attr( get_option( 'background', 'ddd' ) ); 76 74 $color = esc_attr( get_option( 'color', '222' ) ); … … 83 81 $background = str_replace( '#', '', $background ); 84 82 85 $url = $args['url']; 86 $url = explode( 'd=', $url ); 83 $param = explode( 'd=', $url ); 87 84 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 ); 93 88 } 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}" ); 96 90 } 97 91 98 if ( ! is_array( $args['class'] ) ) { 99 $args['class'] = [ $args['class'] ]; 100 } 92 return $url; 101 93 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;114 94 }
Note: See TracChangeset
for help on using the changeset viewer.