Changeset 1127480
- Timestamp:
- 04/04/2015 02:58:31 AM (11 years ago)
- Location:
- wp-first-letter-avatar
- Files:
-
- 153 added
- 3 edited
-
tags/1.2.6 (added)
-
tags/1.2.6/css (added)
-
tags/1.2.6/css/style.css (added)
-
tags/1.2.6/images (added)
-
tags/1.2.6/images/default (added)
-
tags/1.2.6/images/default/128 (added)
-
tags/1.2.6/images/default/128/a.png (added)
-
tags/1.2.6/images/default/128/b.png (added)
-
tags/1.2.6/images/default/128/c.png (added)
-
tags/1.2.6/images/default/128/d.png (added)
-
tags/1.2.6/images/default/128/e.png (added)
-
tags/1.2.6/images/default/128/f.png (added)
-
tags/1.2.6/images/default/128/g.png (added)
-
tags/1.2.6/images/default/128/h.png (added)
-
tags/1.2.6/images/default/128/i.png (added)
-
tags/1.2.6/images/default/128/j.png (added)
-
tags/1.2.6/images/default/128/k.png (added)
-
tags/1.2.6/images/default/128/l.png (added)
-
tags/1.2.6/images/default/128/m.png (added)
-
tags/1.2.6/images/default/128/mystery.png (added)
-
tags/1.2.6/images/default/128/n.png (added)
-
tags/1.2.6/images/default/128/o.png (added)
-
tags/1.2.6/images/default/128/p.png (added)
-
tags/1.2.6/images/default/128/q.png (added)
-
tags/1.2.6/images/default/128/r.png (added)
-
tags/1.2.6/images/default/128/s.png (added)
-
tags/1.2.6/images/default/128/t.png (added)
-
tags/1.2.6/images/default/128/u.png (added)
-
tags/1.2.6/images/default/128/v.png (added)
-
tags/1.2.6/images/default/128/w.png (added)
-
tags/1.2.6/images/default/128/x.png (added)
-
tags/1.2.6/images/default/128/y.png (added)
-
tags/1.2.6/images/default/128/z.png (added)
-
tags/1.2.6/images/default/256 (added)
-
tags/1.2.6/images/default/256/a.png (added)
-
tags/1.2.6/images/default/256/b.png (added)
-
tags/1.2.6/images/default/256/c.png (added)
-
tags/1.2.6/images/default/256/d.png (added)
-
tags/1.2.6/images/default/256/e.png (added)
-
tags/1.2.6/images/default/256/f.png (added)
-
tags/1.2.6/images/default/256/g.png (added)
-
tags/1.2.6/images/default/256/h.png (added)
-
tags/1.2.6/images/default/256/i.png (added)
-
tags/1.2.6/images/default/256/j.png (added)
-
tags/1.2.6/images/default/256/k.png (added)
-
tags/1.2.6/images/default/256/l.png (added)
-
tags/1.2.6/images/default/256/m.png (added)
-
tags/1.2.6/images/default/256/mystery.png (added)
-
tags/1.2.6/images/default/256/n.png (added)
-
tags/1.2.6/images/default/256/o.png (added)
-
tags/1.2.6/images/default/256/p.png (added)
-
tags/1.2.6/images/default/256/q.png (added)
-
tags/1.2.6/images/default/256/r.png (added)
-
tags/1.2.6/images/default/256/s.png (added)
-
tags/1.2.6/images/default/256/t.png (added)
-
tags/1.2.6/images/default/256/u.png (added)
-
tags/1.2.6/images/default/256/v.png (added)
-
tags/1.2.6/images/default/256/w.png (added)
-
tags/1.2.6/images/default/256/x.png (added)
-
tags/1.2.6/images/default/256/y.png (added)
-
tags/1.2.6/images/default/256/z.png (added)
-
tags/1.2.6/images/default/48 (added)
-
tags/1.2.6/images/default/48/a.png (added)
-
tags/1.2.6/images/default/48/b.png (added)
-
tags/1.2.6/images/default/48/c.png (added)
-
tags/1.2.6/images/default/48/d.png (added)
-
tags/1.2.6/images/default/48/e.png (added)
-
tags/1.2.6/images/default/48/f.png (added)
-
tags/1.2.6/images/default/48/g.png (added)
-
tags/1.2.6/images/default/48/h.png (added)
-
tags/1.2.6/images/default/48/i.png (added)
-
tags/1.2.6/images/default/48/j.png (added)
-
tags/1.2.6/images/default/48/k.png (added)
-
tags/1.2.6/images/default/48/l.png (added)
-
tags/1.2.6/images/default/48/m.png (added)
-
tags/1.2.6/images/default/48/mystery.png (added)
-
tags/1.2.6/images/default/48/n.png (added)
-
tags/1.2.6/images/default/48/o.png (added)
-
tags/1.2.6/images/default/48/p.png (added)
-
tags/1.2.6/images/default/48/q.png (added)
-
tags/1.2.6/images/default/48/r.png (added)
-
tags/1.2.6/images/default/48/s.png (added)
-
tags/1.2.6/images/default/48/t.png (added)
-
tags/1.2.6/images/default/48/u.png (added)
-
tags/1.2.6/images/default/48/v.png (added)
-
tags/1.2.6/images/default/48/w.png (added)
-
tags/1.2.6/images/default/48/x.png (added)
-
tags/1.2.6/images/default/48/y.png (added)
-
tags/1.2.6/images/default/48/z.png (added)
-
tags/1.2.6/images/default/512 (added)
-
tags/1.2.6/images/default/512/a.png (added)
-
tags/1.2.6/images/default/512/b.png (added)
-
tags/1.2.6/images/default/512/c.png (added)
-
tags/1.2.6/images/default/512/d.png (added)
-
tags/1.2.6/images/default/512/e.png (added)
-
tags/1.2.6/images/default/512/f.png (added)
-
tags/1.2.6/images/default/512/g.png (added)
-
tags/1.2.6/images/default/512/h.png (added)
-
tags/1.2.6/images/default/512/i.png (added)
-
tags/1.2.6/images/default/512/j.png (added)
-
tags/1.2.6/images/default/512/k.png (added)
-
tags/1.2.6/images/default/512/l.png (added)
-
tags/1.2.6/images/default/512/m.png (added)
-
tags/1.2.6/images/default/512/mystery.png (added)
-
tags/1.2.6/images/default/512/n.png (added)
-
tags/1.2.6/images/default/512/o.png (added)
-
tags/1.2.6/images/default/512/p.png (added)
-
tags/1.2.6/images/default/512/q.png (added)
-
tags/1.2.6/images/default/512/r.png (added)
-
tags/1.2.6/images/default/512/s.png (added)
-
tags/1.2.6/images/default/512/t.png (added)
-
tags/1.2.6/images/default/512/u.png (added)
-
tags/1.2.6/images/default/512/v.png (added)
-
tags/1.2.6/images/default/512/w.png (added)
-
tags/1.2.6/images/default/512/x.png (added)
-
tags/1.2.6/images/default/512/y.png (added)
-
tags/1.2.6/images/default/512/z.png (added)
-
tags/1.2.6/images/default/96 (added)
-
tags/1.2.6/images/default/96/a.png (added)
-
tags/1.2.6/images/default/96/b.png (added)
-
tags/1.2.6/images/default/96/c.png (added)
-
tags/1.2.6/images/default/96/d.png (added)
-
tags/1.2.6/images/default/96/e.png (added)
-
tags/1.2.6/images/default/96/f.png (added)
-
tags/1.2.6/images/default/96/g.png (added)
-
tags/1.2.6/images/default/96/h.png (added)
-
tags/1.2.6/images/default/96/i.png (added)
-
tags/1.2.6/images/default/96/j.png (added)
-
tags/1.2.6/images/default/96/k.png (added)
-
tags/1.2.6/images/default/96/l.png (added)
-
tags/1.2.6/images/default/96/m.png (added)
-
tags/1.2.6/images/default/96/mystery.png (added)
-
tags/1.2.6/images/default/96/n.png (added)
-
tags/1.2.6/images/default/96/o.png (added)
-
tags/1.2.6/images/default/96/p.png (added)
-
tags/1.2.6/images/default/96/q.png (added)
-
tags/1.2.6/images/default/96/r.png (added)
-
tags/1.2.6/images/default/96/s.png (added)
-
tags/1.2.6/images/default/96/t.png (added)
-
tags/1.2.6/images/default/96/u.png (added)
-
tags/1.2.6/images/default/96/v.png (added)
-
tags/1.2.6/images/default/96/w.png (added)
-
tags/1.2.6/images/default/96/x.png (added)
-
tags/1.2.6/images/default/96/y.png (added)
-
tags/1.2.6/images/default/96/z.png (added)
-
tags/1.2.6/images/default/template_512.psd (added)
-
tags/1.2.6/js (added)
-
tags/1.2.6/js/script.js (added)
-
tags/1.2.6/readme.txt (added)
-
tags/1.2.6/wp-first-letter-avatar-config.php (added)
-
tags/1.2.6/wp-first-letter-avatar.php (added)
-
trunk/js (added)
-
trunk/js/script.js (added)
-
trunk/readme.txt (modified) (4 diffs)
-
trunk/wp-first-letter-avatar-config.php (modified) (5 diffs)
-
trunk/wp-first-letter-avatar.php (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-first-letter-avatar/trunk/readme.txt
r1108525 r1127480 1 1 === WP First Letter Avatar === 2 2 Plugin Name: WP First Letter Avatar 3 Version: 1.2. 53 Version: 1.2.6 4 4 Plugin URI: https://github.com/DanielAGW/wp-first-letter-avatar 5 5 Contributors: DanielAGW … … 32 32 33 33 = Compatibility with other plugins = 34 WP First Letter Avatar is fully compatible with [bbPress](https://bbpress.org/). For [BuddyPress](https://buddypress.org/) compatibility please use my other plugin - [BuddyPress First Letter Avatar](https://wordpress.org/plugins/buddypress-first-letter-avatar/). 34 WP First Letter Avatar is fully compatible with [bbPress](https://bbpress.org/) and [wpDiscuz](http://www.gvectors.com/wpdiscuz/). For [BuddyPress](https://buddypress.org/) compatibility please use my other plugin - [BuddyPress First Letter Avatar](https://wordpress.org/plugins/buddypress-first-letter-avatar/). 35 36 = Requirements = 37 WP First Letter Avatar requires at least PHP 5.4.0. It **does not work properly** on PHP 5.3.x and earlier. 35 38 36 39 == Installation == … … 55 58 56 59 = Can I set custom avatars based on last (or any other) character in user's name? = 57 58 60 Of course! This can be done in plugin settings. 59 61 60 62 = I don't want to use Gravatar at all. Can I disable it? = 61 63 Yes! By default, WP First Letter Avatar sets custom avatar only to users without Gravatar, but in plugin settings you can disable it and use custom avatar for everybody. 64 65 = Is WP First Letter Avatar compatible with other plugins? = 66 WP First Letter Avatar has fully tested compatibilty with bbPress and wpDiscuz. For BuddyPress compatibility, please use my other plugin - [BuddyPress First Letter Avatar](https://wordpress.org/plugins/buddypress-first-letter-avatar/). 62 67 63 68 = Can avatars be round, like in Google+? = … … 72 77 73 78 == Changelog == 79 80 = 1.2.6 = 81 * PHP 5.4.x or later REQUIRED: PHP 5.3.x is no longer supported by PHP team, if you are still using it - update immediately 82 * Added asynchronous Gravatar loading for faster page rendering (needs to be activated in plugin Settings) 83 * Added auto-check to see if one or more options in plugin Settings are not empty 84 * Fixed standard avatars replacement on Discussion page in Settings 85 * Couple of minor fixes 74 86 75 87 = 1.2.5 = -
wp-first-letter-avatar/trunk/wp-first-letter-avatar-config.php
r1106485 r1127480 15 15 public function __construct(){ 16 16 17 add_action( 'admin_menu', array($this, 'wpfla_add_admin_menu'));18 add_action( 'admin_init', array($this, 'wpfla_settings_init'));17 add_action('admin_menu', array($this, 'wpfla_add_admin_menu')); 18 add_action('admin_init', array($this, 'wpfla_settings_init')); 19 19 20 20 } … … 82 82 83 83 add_settings_field( 84 'wpfla_use_js', 85 'Use JavaScript for Gravatars<br/>Default: uncheck', 86 array($this, 'wpfla_use_js_render'), 87 'wpfla_pluginPage', 88 'wpfla_pluginPage_section' 89 ); 90 91 add_settings_field( 84 92 'wpfla_round_avatars', 85 93 'Round avatars<br/>Default: uncheck', … … 136 144 137 145 ?> 138 <input type='checkbox' name='wpfla_settings[wpfla_use_gravatar]' <?php checked( $this->wpfla_options['wpfla_use_gravatar'], 1 ); ?> value='1' /> 146 <input type='checkbox' name='wpfla_settings[wpfla_use_gravatar]' <?php checked($this->wpfla_options['wpfla_use_gravatar'], 1); ?> value='1' /> 147 <?php 148 149 } 150 151 152 153 public function wpfla_use_js_render(){ 154 155 ?> 156 <input type='checkbox' name='wpfla_settings[wpfla_use_js]' <?php checked($this->wpfla_options['wpfla_use_js'], 1); ?> value='1' /> 139 157 <?php 140 158 … … 146 164 147 165 ?> 148 <input type='checkbox' name='wpfla_settings[wpfla_round_avatars]' <?php checked( $this->wpfla_options['wpfla_round_avatars'], 1); ?> value='1' />166 <input type='checkbox' name='wpfla_settings[wpfla_round_avatars]' <?php checked($this->wpfla_options['wpfla_round_avatars'], 1); ?> value='1' /> 149 167 <?php 150 168 … … 198 216 </p> 199 217 <p> 218 <strong>Use JavaScript for Gravatars</strong><br /> 219 <span>Works only when option Use Gravatar is active</span><br /> 220 <span style="text-decoration: underline">Check</span>: use JavaScript to check for Gravatars (faster); <span style="text-decoration: underline">Uncheck</span>: use PHP to check for Gravatars (slower). 221 </p> 222 <p> 200 223 <strong>Round avatars</strong><br /> 201 224 <span style="text-decoration: underline">Check</span>: use rounded avatars; <span style="text-decoration: underline">Uncheck</span>: use standard avatars. 202 225 </p> 203 <p>In case of any problems, use thedefault values.</p>226 <p>In case of any problems, use default values.</p> 204 227 205 228 <hr /> -
wp-first-letter-avatar/trunk/wp-first-letter-avatar.php
r1108525 r1127480 5 5 * Contributors: DanielAGW 6 6 * Description: Set custom avatars for users with no Gravatar. The avatar will be a first (or any other) letter of the users's name. 7 * Version: 1.2. 57 * Version: 1.2.6 8 8 * Author: Daniel Wroblewski 9 9 * Author URI: https://github.com/DanielAGW … … 26 26 // Default configuration (this is the default configuration only for the first plugin usage): 27 27 const WPFLA_USE_GRAVATAR = TRUE; // TRUE: if user has Gravatar, use it; FALSE: use custom avatars even when gravatar is set 28 const WPFLA_USE_JS = FALSE; // TRUE: use JS to replace avatars to Gravatar; FALSE: generate avatars and gravatars here in PHP 28 29 const WPFLA_AVATAR_SET = 'default'; // directory where avatars are stored 29 30 const WPFLA_LETTER_INDEX = 0; // 0: first letter; 1: second letter; -1: last letter, etc. … … 34 35 // variables duplicating const values (will be changed in constructor after reading config from DB): 35 36 private $use_gravatar = self::WPFLA_USE_GRAVATAR; 37 private $use_js = self::WPFLA_USE_JS; 36 38 private $avatar_set = self::WPFLA_AVATAR_SET; 37 39 private $letter_index = self::WPFLA_LETTER_INDEX; … … 47 49 add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'wpfla_add_settings_link')); 48 50 49 // add stylesheets/scripts :51 // add stylesheets/scripts for front-end and admin: 50 52 add_action('wp_enqueue_scripts', array($this, 'wpfla_add_scripts')); 53 add_action('admin_enqueue_scripts', array($this, 'wpfla_add_scripts')); 54 55 // add Ajax action for asynchronous Gravatar verification: 56 add_action('wp_ajax_gravatar_verify', array($this, 'ajax_gravatar_exists')); 57 add_action('wp_ajax_nopriv_gravatar_verify', array($this, 'ajax_gravatar_exists')); 51 58 52 59 // add filter to get_avatar: … … 54 61 55 62 // add additional filter for userbar avatar, but only when not in admin: 56 if (!is_admin()) { 57 add_action('admin_bar_menu', array($this, 'add_set_userbar_avatar_filter'), 0); 58 } 59 63 if (!is_admin()){ 64 add_action('admin_bar_menu', function(){ 65 add_filter('get_avatar', array($this, 'set_userbar_avatar'), 10, 5); 66 }, 0); 67 } else { // when in admin, make sure first letter avatars are not displayed on discussion settings page 68 global $pagenow; 69 if ($pagenow == 'options-discussion.php'){ 70 remove_filter('get_avatar', array($this, 'set_comment_avatar')); 71 } 72 } 60 73 61 74 // get plugin configuration from database: 62 75 $options = get_option('wpfla_settings'); 63 76 if (empty($options)){ 64 65 77 // no records in DB, use default (const) values to save plugin config: 66 78 $settings = array( 67 79 'wpfla_use_gravatar' => self::WPFLA_USE_GRAVATAR, 80 'wpfla_use_js' => self::WPFLA_USE_JS, 68 81 'wpfla_avatar_set' => self::WPFLA_AVATAR_SET, 69 82 'wpfla_letter_index' => self::WPFLA_LETTER_INDEX, … … 73 86 ); 74 87 add_option('wpfla_settings', $settings); 75 76 88 } else { 77 78 // there are records in DB for our plugin, let's assign them to our variables: 89 // there are records in DB for our plugin, let's check if some of them are not empty: 90 $change_values = FALSE; // do not update settings by default... 91 if ($options['wpfla_avatar_set'] === ''){ 92 $options['wpfla_avatar_set'] = self::WPFLA_AVATAR_SET; 93 $change_values = TRUE; 94 } 95 if ($options['wpfla_letter_index'] === ''){ 96 $options['wpfla_letter_index'] = self::WPFLA_LETTER_INDEX; 97 $change_values = TRUE; 98 } 99 if ($options['wpfla_file_format'] === ''){ 100 $options['wpfla_file_format'] = self::WPFLA_IMAGES_FORMAT; 101 $change_values = TRUE; 102 } 103 if ($options['wpfla_unknown_image'] === ''){ 104 $options['wpfla_unknown_image'] = self::WPFLA_IMAGE_UNKNOWN; 105 $change_values = TRUE; 106 } 107 if ($change_values === TRUE){ 108 $settings['wpfla_use_gravatar'] = $options['wpfla_use_gravatar']; 109 $settings['wpfla_use_js'] = $options['wpfla_use_js']; 110 $settings['wpfla_avatar_set'] = $options['wpfla_avatar_set']; 111 $settings['wpfla_letter_index'] = $options['wpfla_letter_index']; 112 $settings['wpfla_file_format'] = $options['wpfla_file_format']; 113 $settings['wpfla_round_avatars'] = $options['wpfla_round_avatars']; 114 $settings['wpfla_unknown_image'] = $options['wpfla_unknown_image']; 115 update_option('wpfla_settings', $settings); 116 } 117 // and then assign them to our class properties 79 118 $this->use_gravatar = $options['wpfla_use_gravatar']; 119 $this->use_js = $options['wpfla_use_js']; 80 120 $this->avatar_set = $options['wpfla_avatar_set']; 81 121 $this->letter_index = $options['wpfla_letter_index']; … … 83 123 $this->round_avatars = $options['wpfla_round_avatars']; 84 124 $this->image_unknown = $options['wpfla_unknown_image']; 85 86 125 } 87 126 … … 104 143 105 144 // add main CSS file: 106 wp_enqueue_style('prefix-style', plugins_url('css/style.css', __FILE__) ); 145 wp_enqueue_style('prefix-style', plugins_url('css/style.css', __FILE__)); 146 147 // add main JS file, only when JS is used: 148 if ($this->use_js == TRUE){ 149 $js_variables = array( 150 'img_data_attribute' => 'data-wpfla-gravatar', 151 'ajaxurl' => admin_url('admin-ajax.php') 152 ); 153 wp_enqueue_script('wpfla-script-handle', plugins_url('js/script.js', __FILE__), array('jquery')); 154 wp_localize_script('wpfla-script-handle', 'wpfla_vars_data', $js_variables); 155 } 156 157 } 158 159 160 161 public function ajax_gravatar_exists(){ 162 163 $gravatar_uri = $_POST['gravatar_uri']; 164 $gravatar_exists = $this->gravatar_exists_uri($gravatar_uri); 165 166 if ($gravatar_exists == TRUE){ 167 echo '1'; 168 } else { 169 echo '0'; 170 } 171 172 exit; 107 173 108 174 } … … 119 185 120 186 // first check whether Gravatar should be used at all: 121 if ($this->use_gravatar == TRUE ){187 if ($this->use_gravatar == TRUE && $this->use_js == FALSE){ 122 188 // gravatar used as default option, now check whether user's gravatar is set: 123 189 if ($this->gravatar_exists($email)){ … … 128 194 $avatar_output = $this->choose_custom_avatar($name, $size, $alt); 129 195 } 196 } else if ($this->use_gravatar == TRUE && $this->use_js == TRUE){ 197 // gravatar with JS is used as default option, only custom avatars will be used; proceed to choose custom avatar: 198 $avatar_output = $this->choose_custom_avatar($name, $size, $alt, $email); 130 199 } else { 131 // gravatar is not used as default option, only custom avatars will be used; proceed to choose custom avatar:200 // gravatar is not used: 132 201 $avatar_output = $this->choose_custom_avatar($name, $size, $alt); 133 202 } … … 198 267 199 268 200 public function add_set_userbar_avatar_filter(){201 202 add_filter('get_avatar', array($this, 'set_userbar_avatar'), 10, 5);203 204 }205 206 207 208 269 public function set_userbar_avatar($avatar, $id_or_email, $size = '96', $default, $alt = ''){ // only size and alt arguments are used 209 270 … … 222 283 223 284 224 private function output_img($avatar_uri, $size, $alt = '' ){285 private function output_img($avatar_uri, $size, $alt = '', $gravatar_uri = ''){ 225 286 226 287 // prepare extra classes for <img> tag depending on plugin settings: 227 288 $extra_img_class = ''; 289 $extra_img_tags = ''; 290 if (!empty($gravatar_uri)){ 291 $extra_img_tags .= "data-wpfla-gravatar='{$gravatar_uri}'"; 292 } 228 293 if ($this->round_avatars == TRUE){ 229 294 $extra_img_class .= 'round-avatars'; 230 295 } 231 296 232 $output_data = "<img alt='{$alt}' src='{$avatar_uri}' class='avatar avatar-{$size} photo wpfla {$extra_img_class}' height='{$size}' width='{$size}'/>";297 $output_data = "<img alt='{$alt}' src='{$avatar_uri}' {$extra_img_tags} class='avatar avatar-{$size} photo wpfla {$extra_img_class}' height='{$size}' width='{$size}' />"; 233 298 234 299 // return the complete <img> tag: … … 239 304 240 305 241 private function choose_custom_avatar($comment_author, $size, $alt = '' ){306 private function choose_custom_avatar($comment_author, $size, $alt = '', $email = ''){ 242 307 243 308 // get picture filename (and lowercase it) from commenter name: … … 274 339 . $this->images_format; 275 340 341 $gravatar_uri = ''; 342 343 if (!empty($email)){ 344 $gravatar_uri .= $this->generate_gravatar_uri($email, $size); 345 } 346 276 347 // output the final HTML img code: 277 return $this->output_img($avatar_uri, $size, $alt );278 279 } 280 281 282 283 private function output_gravatar_img($comment_email, $size, $alt = ''){348 return $this->output_img($avatar_uri, $size, $alt, $gravatar_uri); 349 350 } 351 352 353 354 private function generate_gravatar_uri($email, $size){ 284 355 285 356 // email to gravatar url: 286 357 $avatar_uri = self::WPFLA_GRAVATAR_URL; 287 $avatar_uri .= md5(strtolower(trim($ comment_email)));358 $avatar_uri .= md5(strtolower(trim($email))); 288 359 $avatar_uri .= "?s={$size}&d=mm&r=g"; 289 360 361 return $avatar_uri; 362 363 } 364 365 366 367 private function output_gravatar_img($comment_email, $size, $alt = ''){ 368 290 369 // output gravatar: 370 $avatar_uri = $this->generate_gravatar_uri($comment_email, $size); 291 371 return $this->output_img($avatar_uri, $size, $alt); 292 372 … … 319 399 } 320 400 401 402 403 private function gravatar_exists_uri($uri){ 404 405 /* Check if there is gravatar assigned to this gravatar url 406 returns bool: true if gravatar is assigned, false if it is not 407 function partially borrowed from http://codex.wordpress.org/Using_Gravatars - thanks! */ 408 409 410 // first check whether it is a gravatar URL; if not, return FALSE 411 if (stripos($uri, 'gravatar.com/avatar') === FALSE){ 412 return FALSE; 413 } 414 415 // strip all GET parameters: 416 $uri = strtok($uri, '?'); 417 $uri .= '?d=404'; 418 $response = wp_remote_head($uri); // response from gravatar server 419 420 if (is_wp_error($response)){ // caused error? 421 $data = 'error'; 422 } else { 423 $data = $response['response']['code']; // no error, assign response code to data 424 } 425 426 if ($data == '200'){ // response code is 200, gravatar exists, return true 427 return TRUE; 428 } else { // response code is not 200, gravatar doesn't exist, return false 429 return FALSE; 430 } 431 432 } 433 321 434 } 322 435
Note: See TracChangeset
for help on using the changeset viewer.