{"id":18899642,"date":"2026-05-05T14:34:10","date_gmt":"2026-05-05T14:34:10","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/error-undefined-array-key-fixed\/"},"modified":"2026-05-05T14:34:10","modified_gmt":"2026-05-05T14:34:10","slug":"error-undefined-array-key-fixed","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/error-undefined-array-key-fixed\/","title":{"rendered":"Error \u201cUndefined array key\u201d (FIXED)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Sorry I was unable to reply to the thread with the original poster&#8217;s error message.  Here is the fix&#8230;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I patched the plugin, so it now checks whether those URL parameters exist before using them. I also corrected $current_user-&gt;id to $current_user-&gt;ID, added nonce protection handling, and added exit; after the redirect.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Save the following code as user-avatar.php<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Please make a backup copy of the file first!!!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php<br \/>\/*<br \/>Plugin Name: User Avatar<br \/>Plugin URI: https:\/\/wordpress.org\/extend\/plugins\/user-avatar\/<br \/>Description: Allows users to associate photos with their accounts by accessing their \"Your Profile\" page that default as Gravatar or WordPress Default image (from Discussion Page).<br \/>Version: 1.4.12<br \/>Author: Enej Bajgoric \/ Gagan Sandhu \/ CTLT DEV<br \/><br \/><br \/>GNU General Public License, Free Software Foundation &lt;http:\/\/creativecommons.org\/licenses\/GPL\/2.0\/&gt;<br \/>This program is free software; you can redistribute it and\/or modify<br \/>it under the terms of the GNU General Public License as published by<br \/>the Free Software Foundation; either version 2 of the License, or<br \/>(at your option) any later version.<br \/><br \/>This program is distributed in the hope that it will be useful,<br \/>but WITHOUT ANY WARRANTY; without even the implied warranty of<br \/>MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br \/>GNU General Public License for more details.<br \/><br \/>You should have received a copy of the GNU General Public License<br \/>along with this program; if not, write to the Free Software<br \/>Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA<br \/>*\/<br \/><br \/>add_action('init', 'user_avatar_core_set_avatar_constants', 8 );<br \/>add_action('show_user_profile', 'user_avatar_form');<br \/>add_action('edit_user_profile', 'user_avatar_form');<br \/>add_action('wp_ajax_user_avatar_add_photo', 'user_avatar_add_photo');<br \/>add_action('user_avatar_iframe_head','user_avatar_init');<br \/><br \/><br \/>add_action('admin_print_styles-user-edit.php', 'user_avatar_admin_print_styles');<br \/>add_action('admin_print_styles-profile.php', 'user_avatar_admin_print_styles');<br \/>function user_avatar_admin_print_styles() {<br \/>\tglobal $hook_suffix;<br \/>\twp_enqueue_script(\"thickbox\");<br \/>\twp_enqueue_style(\"thickbox\");<br \/>\twp_enqueue_style('user-avatar', plugins_url('\/user-avatar\/css\/user-avatar.css'), 'css');<br \/>}<br \/><br \/><br \/>\/**<br \/> * user_avatar_init function.<br \/> * Description: Initializing user avatar style.<br \/> * @access public<br \/> * @return void<br \/> *\/<br \/>function user_avatar_init(){<br \/><br \/>\twp_enqueue_style( 'global' );<br \/>\twp_enqueue_style( 'wp-admin' );<br \/>\twp_enqueue_style( 'colors' );<br \/>\twp_enqueue_style( 'ie' );<br \/>\twp_enqueue_style('user-avatar', plugins_url('\/user-avatar\/css\/user-avatar.css'), 'css');<br \/>\twp_enqueue_style('imgareaselect');<br \/>\twp_enqueue_script('imgareaselect');<br \/>\tdo_action('admin_print_styles');<br \/>\tdo_action('admin_print_scripts');<br \/>\tdo_action('admin_head');<br \/><br \/>}<br \/>\/**<br \/> * user_avatar_core_set_avatar_constants function.<br \/> * Description: Establishing restraints on sizes of files and dimensions of images.<br \/> * Sets the default constants<br \/> * @access public<br \/> * @return void<br \/> *\/<br \/>function user_avatar_core_set_avatar_constants() {<br \/><br \/>\tglobal $bp;<br \/><br \/>\tif ( !defined( 'USER_AVATAR_UPLOAD_PATH' ) )<br \/>\t\tdefine( 'USER_AVATAR_UPLOAD_PATH', user_avatar_core_avatar_upload_path() );<br \/><br \/>\tif ( !defined( 'USER_AVATAR_URL' ) )<br \/>\t\tdefine( 'USER_AVATAR_URL', user_avatar_core_avatar_url() );<br \/><br \/>\tif ( !defined( 'USER_AVATAR_THUMB_WIDTH' ) )<br \/>\t\tdefine( 'USER_AVATAR_THUMB_WIDTH', 50 );<br \/><br \/>\tif ( !defined( 'USER_AVATAR_THUMB_HEIGHT' ) )<br \/>\t\tdefine( 'USER_AVATAR_THUMB_HEIGHT', 50 );<br \/><br \/>\tif ( !defined( 'USER_AVATAR_FULL_WIDTH' ) )<br \/>\t\tdefine( 'USER_AVATAR_FULL_WIDTH', 150 );<br \/><br \/>\tif ( !defined( 'USER_AVATAR_FULL_HEIGHT' ) )<br \/>\t\tdefine( 'USER_AVATAR_FULL_HEIGHT', 150 );<br \/><br \/>\tif ( !defined( 'USER_AVATAR_ORIGINAL_MAX_FILESIZE' ) ) {<br \/>\t\tif ( !get_site_option( 'fileupload_maxk', 1500 ) )<br \/>\t\t\tdefine( 'USER_AVATAR_ORIGINAL_MAX_FILESIZE', 5120000 ); \/* 5mb *\/<br \/>\t\telse<br \/>\t\t\tdefine( 'USER_AVATAR_ORIGINAL_MAX_FILESIZE', get_site_option( 'fileupload_maxk', 1500 ) * 1024 );<br \/>\t}<br \/><br \/>\tif ( !defined( 'USER_AVATAR_DEFAULT' ) )<br \/>\t\tdefine( 'USER_AVATAR_DEFAULT', plugins_url('\/user-avatar\/images\/mystery-man.jpg') );<br \/><br \/>\tif ( !defined( 'USER_AVATAR_DEFAULT_THUMB' ) )<br \/>\t\tdefine( 'USER_AVATAR_DEFAULT_THUMB', plugins_url('\/user-avatar\/images\/mystery-man-50.jpg') );<br \/><br \/><br \/>\t\/\/ set the language<br \/>\tload_plugin_textdomain( 'user-avatar', false , basename( dirname( __FILE__ ) ) . '\/languages' );<br \/>}<br \/><br \/>\/**<br \/> * user_avatar_core_avatar_upload_path function.<br \/> * Description: Establishing upload path\/area where images that are uploaded will be stored.<br \/> * @access public<br \/> * @return void<br \/> *\/<br \/>function user_avatar_core_avatar_upload_path()<br \/>{<br \/>\tif( !file_exists(WP_CONTENT_DIR.\"\/uploads\/avatars\/\") )<br \/>\t\tmkdir(WP_CONTENT_DIR.\"\/uploads\/avatars\/\", 0777 ,true);<br \/><br \/>\treturn WP_CONTENT_DIR.\"\/uploads\/avatars\/\";<br \/>}<br \/><br \/>\/**<br \/> * user_avatar_core_avatar_url function.<br \/> * Description: Establishing the path of the core content avatar area.<br \/> * @access public<br \/> * @return void<br \/> *\/<br \/>function user_avatar_core_avatar_url()<br \/>{<br \/>\treturn WP_CONTENT_URL.\"\/uploads\/avatars\/\";<br \/>}<br \/><br \/>\/**<br \/> * user_avatar_add_photo function.<br \/> * The content inside the iframe<br \/> * Description: Creating panels for the different steps users take to upload a file and checking their uploads.<br \/> * @access public<br \/> * @return void<br \/> *\/<br \/>function user_avatar_add_photo() {<br \/>\tglobal $current_user;<br \/><br \/>\t$uid  = absint( $_GET&#091;'uid'] );<br \/>\t$step = absint( $_GET&#091;'step'] );<br \/><br \/>\tif(($uid == $current_user-&gt;ID || current_user_can('edit_users')) &amp;&amp;  is_numeric($uid))<br \/>\t{<br \/>\t\t<br \/>\t?&gt;&lt;!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd\"&gt;<br \/>&lt;html xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\" &lt;?php do_action('admin_xml_ns'); ?&gt; &lt;?php language_attributes(); ?&gt;&gt;<br \/>&lt;head&gt;<br \/>&lt;meta http-equiv=\"Content-Type\" content=\"&lt;?php esc_attr( bloginfo('html_type') ); ?&gt;; charset=&lt;?php echo esc_attr( get_option('blog_charset') ); ?&gt;\" \/&gt;<br \/>&lt;title&gt;&lt;?php esc_textarea( bloginfo('name') ) ?&gt; &amp;rsaquo; &lt;?php _e('Uploads'); ?&gt; &amp;#8212; &lt;?php _e('WordPress'); ?&gt;&lt;\/title&gt;<br \/>&lt;script type=\"text\/javascript\"&gt;<br \/>\/\/&lt;!&#091;CDATA&#091;<br \/>addLoadEvent = function(func){if(typeof jQuery!=\"undefined\")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};<br \/>var userSettings = {<br \/>\t\t'url': '&lt;?php echo SITECOOKIEPATH; ?&gt;',<br \/>\t\t'uid': '&lt;?php if ( ! isset($current_user) ) $current_user = wp_get_current_user(); echo $current_user-&gt;ID; ?&gt;',<br \/>\t\t'time':'&lt;?php echo time() ?&gt;'<br \/>\t},<br \/>\tajaxurl = '&lt;?php echo admin_url('admin-ajax.php'); ?&gt;',<br \/>\tpagenow = '&lt;?php echo $current_screen-&gt;id; ?&gt;',<br \/>\ttypenow = '&lt;?php if ( isset($current_screen-&gt;post_type) ) echo $current_screen-&gt;post_type; ?&gt;',<br \/>\tadminpage = '&lt;?php echo esc_attr( $admin_body_class ); ?&gt;',<br \/>\tthousandsSeparator = '&lt;?php echo addslashes( $wp_locale-&gt;number_format&#091;'thousands_sep'] ); ?&gt;',<br \/>\tdecimalPoint = '&lt;?php echo addslashes( $wp_locale-&gt;number_format&#091;'decimal_point'] ); ?&gt;',<br \/>\tisRtl = &lt;?php echo (int) is_rtl(); ?&gt;;<br \/>\/\/]]&gt;<br \/>&lt;\/script&gt;<br \/>&lt;?php<br \/><br \/><br \/>\tdo_action('user_avatar_iframe_head');<br \/><br \/><br \/>?&gt;<br \/><br \/>&lt;\/head&gt;<br \/>&lt;body&gt;<br \/>&lt;?php<br \/><br \/>\tswitch($step)<br \/>\t{<br \/>\t\tcase 1:<br \/>\t\t\tuser_avatar_add_photo_step1($uid);<br \/>\t\tbreak;<br \/><br \/>\t\tcase 2:<br \/>\t\t\tuser_avatar_add_photo_step2($uid);<br \/>\t\tbreak;<br \/><br \/>\t\tcase 3:<br \/>\t\t\tuser_avatar_add_photo_step3($uid);<br \/>\t\tbreak;<br \/>\t}<br \/><br \/>\tdo_action('admin_print_footer_scripts');<br \/>?&gt;<br \/>&lt;script type=\"text\/javascript\"&gt;if(typeof wpOnload=='function')wpOnload();&lt;\/script&gt;<br \/>&lt;\/body&gt;<br \/>&lt;\/html&gt;<br \/>&lt;?php<br \/>\t}else {<br \/>\t\twp_die(__(\"You are not allowed to do that.\",'user-avatar'));<br \/>\t}<br \/>\tdie();<br \/>}<br \/><br \/>\/**<br \/> * user_avatar_add_photo_step1 function.<br \/> * The First Step in the process<br \/> * Description: Displays the users photo and they can choose to upload another if they please.<br \/> * @access public<br \/> * @param mixed $uid<br \/> * @return void<br \/> *\/<br \/>function user_avatar_add_photo_step1($uid)<br \/>{<br \/>\t?&gt;<br \/>\t&lt;p id=\"step1-image\" &gt;<br \/>\t&lt;?php<br \/>\techo user_avatar_get_avatar( absint( $uid ) , 150);<br \/>\t?&gt;<br \/>\t&lt;\/p&gt;<br \/>\t&lt;div id=\"user-avatar-step1\"&gt;<br \/>\t&lt;form enctype=\"multipart\/form-data\" id=\"uploadForm\" method=\"POST\" action=\"&lt;?php echo admin_url('admin-ajax.php'); ?&gt;?action=user_avatar_add_photo&amp;step=2&amp;uid=&lt;?php echo absint( $uid ); ?&gt;\" &gt;<br \/>\t\t&lt;label for=\"upload\"&gt;&lt;?php _e('Choose an image from your computer:','user-avatar'); ?&gt;&lt;\/label&gt;&lt;br \/&gt;&lt;input type=\"file\" id=\"upload\" name=\"uploadedfile\" \/&gt;<br \/><br \/>\t\t&lt;?php wp_nonce_field('user-avatar') ?&gt;<br \/>\t\t&lt;p class=\"submit\"&gt;&lt;input type=\"submit\" value=\"&lt;?php esc_attr_e('Upload'); ?&gt;\" \/&gt;&lt;\/p&gt;<br \/>\t&lt;\/form&gt;<br \/>\t&lt;\/div&gt;<br \/><br \/>\t&lt;?php<br \/>}<br \/><br \/>\/**<br \/> * user_avatar_add_photo_step2 function.<br \/> * The Second Step in the process<br \/> * Description: Takes the uploaded photo and saves it to database.<br \/> * @access public<br \/> * @param mixed $uid<br \/> * @return void<br \/> *\/<br \/>function user_avatar_add_photo_step2($uid)<br \/>{<br \/><br \/><br \/>\t\tif (!(($_FILES&#091;\"uploadedfile\"]&#091;\"type\"] == \"image\/gif\") || ($_FILES&#091;\"uploadedfile\"]&#091;\"type\"] == \"image\/jpeg\") || ($_FILES&#091;\"uploadedfile\"]&#091;\"type\"] == \"image\/png\") || ($_FILES&#091;\"uploadedfile\"]&#091;\"type\"] == \"image\/pjpeg\") || ($_FILES&#091;\"uploadedfile\"]&#091;\"type\"] == \"image\/x-png\"))){<br \/>\t\t\techo \"&lt;div class='error'&gt;&lt;p&gt;\".__(\"Please upload an image file (.jpeg, .gif, .png).\",'user-avatar').\"&lt;\/p&gt;&lt;\/div&gt;\";<br \/>\t\t\tuser_avatar_add_photo_step1($uid);<br \/>\t\t\tdie();<br \/>\t\t}<br \/>\t\t$overrides = array('test_form' =&gt; false);<br \/>\t\t$file = wp_handle_upload($_FILES&#091;'uploadedfile'], $overrides);<br \/><br \/>\t\tif ( isset($file&#091;'error']) ){<br \/>\t\t\tdie( $file&#091;'error'] );<br \/>\t\t}<br \/><br \/>\t\t$url = $file&#091;'url'];<br \/>\t\t$type = $file&#091;'type'];<br \/>\t\t$file = $file&#091;'file'];<br \/>\t\t$filename = basename($file);<br \/><br \/>\t\tset_transient( 'avatar_file_'.$uid, $file, 60 * 60 * 5 );<br \/>\t\t\/\/ Construct the object array<br \/>\t\t$object = array(<br \/>\t\t'post_title' =&gt; $filename,<br \/>\t\t'post_content' =&gt; $url,<br \/>\t\t'post_mime_type' =&gt; $type,<br \/>\t\t'guid' =&gt; $url);<br \/><br \/>\t\t\/\/ Save the data<br \/>\t\tlist($width, $height, $type, $attr) = getimagesize( $file );<br \/><br \/>\t\tif ( $width &gt; 420 ) {<br \/>\t\t\t$oitar = $width \/ 420;<br \/>\t\t\t$image = wp_crop_image($file, 0, 0, $width, $height, 420, $height \/ $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file));<br \/><br \/><br \/>\t\t\t$url = str_replace(basename($url), basename($image), $url);<br \/>\t\t\t$width = $width \/ $oitar;<br \/>\t\t\t$height = $height \/ $oitar;<br \/>\t\t} else {<br \/>\t\t\t$oitar = 1;<br \/>\t\t}<br \/>\t\t?&gt;<br \/>\t\t&lt;form id=\"iframe-crop-form\" method=\"POST\" action=\"&lt;?php echo admin_url('admin-ajax.php'); ?&gt;?action=user_avatar_add_photo&amp;step=3&amp;uid=&lt;?php echo esc_attr($uid); ?&gt;\"&gt;<br \/><br \/>\t\t&lt;h4&gt;&lt;?php _e('Choose the part of the image you want to use as your profile image.','user-avatar'); ?&gt; &lt;input type=\"submit\" class=\"button\" id=\"user-avatar-crop-button\" value=\"&lt;?php esc_attr_e('Crop Image','user-avatar'); ?&gt;\" \/&gt;&lt;\/h4&gt;<br \/><br \/>\t\t&lt;div id=\"testWrap\"&gt;<br \/>\t\t&lt;img src=\"&lt;?php echo esc_url( $url ); ?&gt;\" id=\"upload\" width=\"&lt;?php echo esc_attr($width); ?&gt;\" height=\"&lt;?php echo esc_attr($height); ?&gt;\" \/&gt;<br \/>\t\t&lt;\/div&gt;<br \/>\t\t&lt;div id=\"user-avatar-preview\"&gt;<br \/>\t\t&lt;h4&gt;Preview&lt;\/h4&gt;<br \/>\t\t&lt;div id=\"preview\" style=\"width: &lt;?php echo USER_AVATAR_FULL_WIDTH; ?&gt;px; height: &lt;?php echo USER_AVATAR_FULL_HEIGHT; ?&gt;px; overflow: hidden;\"&gt;<br \/>\t\t&lt;img src=\"&lt;?php echo esc_url($url); ?&gt;\" width=\"&lt;?php echo esc_attr($width); ?&gt;\" height=\"&lt;?php echo esc_attr( $height ); ?&gt;\"&gt;<br \/>\t\t&lt;\/div&gt;<br \/>\t\t&lt;p class=\"submit\" &gt;<br \/>\t\t&lt;input type=\"hidden\" name=\"x1\" id=\"x1\" value=\"0\" \/&gt;<br \/>\t\t&lt;input type=\"hidden\" name=\"y1\" id=\"y1\" value=\"0\" \/&gt;<br \/>\t\t&lt;input type=\"hidden\" name=\"x2\" id=\"x2\" \/&gt;<br \/>\t\t&lt;input type=\"hidden\" name=\"y2\" id=\"y2\" \/&gt;<br \/>\t\t&lt;input type=\"hidden\" name=\"width\" id=\"width\" value=\"&lt;?php echo esc_attr($width) ?&gt;\" \/&gt;<br \/>\t\t&lt;input type=\"hidden\" name=\"height\" id=\"height\" value=\"&lt;?php echo esc_attr($height) ?&gt;\" \/&gt;<br \/><br \/>\t\t&lt;input type=\"hidden\" name=\"oitar\" id=\"oitar\" value=\"&lt;?php echo esc_attr($oitar); ?&gt;\" \/&gt;<br \/>\t\t&lt;?php wp_nonce_field('user-avatar'); ?&gt;<br \/>\t\t&lt;\/p&gt;<br \/>\t\t&lt;\/div&gt;<br \/>\t\t&lt;\/form&gt;<br \/><br \/>\t\t&lt;script type=\"text\/javascript\"&gt;<br \/><br \/>\tfunction onEndCrop( coords ) {<br \/>\t\tjQuery( '#x1' ).val(coords.x);<br \/>\t\tjQuery( '#y1' ).val(coords.y);<br \/>\t\tjQuery( '#width' ).val(coords.w);<br \/>\t\tjQuery( '#height' ).val(coords.h);<br \/>\t}<br \/><br \/>\tjQuery(document).ready(function() {<br \/>\t\tvar xinit = &lt;?php echo USER_AVATAR_FULL_WIDTH; ?&gt;;<br \/>\t\tvar yinit = &lt;?php echo USER_AVATAR_FULL_HEIGHT; ?&gt;;<br \/>\t\tvar ratio = xinit \/ yinit;<br \/>\t\tvar ximg = jQuery('img#upload').width();<br \/>\t\tvar yimg = jQuery('img#upload').height();<br \/><br \/>\t\tif ( yimg &lt; yinit || ximg &lt; xinit ) {<br \/>\t\t\tif ( ximg \/ yimg &gt; ratio ) {<br \/>\t\t\t\tyinit = yimg;<br \/>\t\t\t\txinit = yinit * ratio;<br \/>\t\t\t} else {<br \/>\t\t\t\txinit = ximg;<br \/>\t\t\t\tyinit = xinit \/ ratio;<br \/>\t\t\t}<br \/>\t\t}<br \/><br \/>\t\tjQuery('img#upload').imgAreaSelect({<br \/>\t\t\thandles: true,<br \/>\t\t\tkeys: true,<br \/>\t\t\taspectRatio: xinit + ':' + yinit,<br \/>\t\t\tshow: true,<br \/>\t\t\tx1: 0,<br \/>\t\t\ty1: 0,<br \/>\t\t\tx2: xinit,<br \/>\t\t\ty2: yinit,<br \/>\t\t\t\/\/maxHeight: &lt;?php echo USER_AVATAR_FULL_HEIGHT; ?&gt;,<br \/>\t\t\t\/\/maxWidth: &lt;?php echo USER_AVATAR_FULL_WIDTH; ?&gt;,<br \/>\t\t\tonInit: function () {<br \/>\t\t\t\tjQuery('#width').val(xinit);<br \/>\t\t\t\tjQuery('#height').val(yinit);<br \/>\t\t\t},<br \/>\t\t\tonSelectChange: function(img, c) {<br \/>\t\t\t\tjQuery('#x1').val(c.x1);<br \/>\t\t\t\tjQuery('#y1').val(c.y1);<br \/>\t\t\t\tjQuery('#width').val(c.width);<br \/>\t\t\t\tjQuery('#height').val(c.height);<br \/><br \/><br \/><br \/>\t\t\t\tif (!c.width || !c.height)<br \/>        \t\t\treturn;<br \/><br \/>\t\t\t    var scaleX = &lt;?php echo USER_AVATAR_FULL_WIDTH; ?&gt; \/ c.width;<br \/>\t\t\t    var scaleY = &lt;?php echo USER_AVATAR_FULL_HEIGHT; ?&gt; \/ c.height;<br \/><br \/>\t\t\t    jQuery('#preview img').css({<br \/>\t\t\t        width: Math.round(scaleX * &lt;?php echo floatval( $width ); ?&gt;),<br \/>\t\t\t        height: Math.round(scaleY * &lt;?php echo floatval( $height ); ?&gt;),<br \/>\t\t\t        marginLeft: -Math.round(scaleX * c.x1),<br \/>\t\t\t        marginTop: -Math.round(scaleY * c.y1)<br \/>\t\t\t    });<br \/><br \/>\t\t\t}<br \/>\t\t});<br \/>\t});<br \/>&lt;\/script&gt;<br \/>\t\t&lt;?php<br \/>}<br \/>\/**<br \/> * user_avatar_add_photo_step3 function.<br \/> * The Third Step in the Process<br \/> * Description: Deletes previous uploaded picture and creates a new cropped image in its place.<br \/> * @access public<br \/> * @param mixed $uid<br \/> * @return void<br \/> *\/<br \/>function user_avatar_add_photo_step3($uid)<br \/>{<br \/>\t$oitar  = floatval( $_POST&#091;'oitar'] );<br \/>\t$x1     = floatval( $_POST&#091;'x1'] );<br \/>\t$y1     = floatval( $_POST&#091;'y1'] );<br \/>\t$width  = floatval( $_POST&#091;'width'] );<br \/>\t$height = floatval( $_POST&#091;'height'] );<br \/>\t$uid    = intval( $uid );<br \/><br \/>\tif ( $oitar &gt; 1 ) {<br \/>\t\t$x1 = $x1 * $oitar;<br \/>\t\t$y1 = $y1 * $oitar;<br \/>\t\t$width = $width * $oitar;<br \/>\t\t$height = $height * $oitar;<br \/>\t}<br \/><br \/>\t$original_file = get_transient( 'avatar_file_'.$uid );<br \/>\t\t\t\t\t delete_transient('avatar_file_'.$uid );<br \/>\tif( !file_exists($original_file) ) {<br \/>\t\techo \"&lt;div class='error'&gt;&lt;p&gt;\". __('Sorry, No file available','user-avatar').\"&lt;\/p&gt;&lt;\/div&gt;\";<br \/>\t\treturn true;<br \/>\t}<br \/><br \/>\t$cropped_full = USER_AVATAR_UPLOAD_PATH.\"{$uid}\/\".time().\"-bpfull.jpg\";<br \/>\t$cropped_thumb = USER_AVATAR_UPLOAD_PATH.\"{$uid}\/\".time().\"-bpthumb.jpg\";<br \/><br \/>\t\/\/ delete the previous files<br \/>\tuser_avatar_delete_files($uid);<br \/><br \/>\tif(!file_exists(USER_AVATAR_UPLOAD_PATH.\"{$uid}\/\"))<br \/>\t\tmkdir(USER_AVATAR_UPLOAD_PATH.\"{$uid}\/\");<br \/><br \/>\t\/\/ update the files<br \/>\t$cropped_full = wp_crop_image( $original_file, $x1, $y1, $width, $height, USER_AVATAR_FULL_WIDTH, USER_AVATAR_FULL_HEIGHT, false, $cropped_full );<br \/><br \/>\t$cropped_thumb = wp_crop_image( $original_file, $x1, $y1, $width, $height, USER_AVATAR_THUMB_WIDTH, USER_AVATAR_THUMB_HEIGHT, false, $cropped_thumb );<br \/><br \/>\t\/* Remove the original *\/<br \/>\t@unlink( $original_file );<br \/><br \/>\tif ( is_wp_error( $cropped_full ) )<br \/>\t\twp_die( __( 'Image could not be processed.  Please go back and try again.' ), __( 'Image Processing Error' ) );<br \/>\t?&gt;<br \/>\t&lt;script type=\"text\/javascript\"&gt;<br \/>\t\tself.parent.user_avatar_refresh_image('&lt;?php echo user_avatar_get_avatar($uid, 150); ?&gt;');<br \/>\t\tself.parent.add_remove_avatar_link();<br \/>\t&lt;\/script&gt;<br \/>\t&lt;div id=\"user-avatar-step3\"&gt;<br \/>\t\t&lt;h3&gt;&lt;?php _e(\"Here's your new profile picture...\",'user-avatar'); ?&gt;&lt;\/h3&gt;<br \/>\t\t&lt;span style=\"float:left;\"&gt;<br \/>\t\t&lt;?php<br \/>\t\techo user_avatar_get_avatar( $uid, 150);<br \/>\t\t?&gt;<br \/>\t\t&lt;\/span&gt;<br \/>\t\t&lt;a id=\"user-avatar-step3-close\" class=\"button\" onclick=\"self.parent.tb_remove();\" &gt;&lt;?php _e('Close','user-avatar'); ?&gt;&lt;\/a&gt;<br \/>\t&lt;\/div&gt;<br \/>&lt;?php<br \/>}<br \/>\/**<br \/> * user_avatar_delete_files function.<br \/> * Description: Deletes the avatar files based on the user id.<br \/> * @access public<br \/> * @param mixed $uid<br \/> * @return void<br \/> *\/<br \/>function user_avatar_delete_files($uid)<br \/>{<br \/>\t$avatar_folder_dir = USER_AVATAR_UPLOAD_PATH.\"{$uid}\/\";<br \/>\tif ( !file_exists( $avatar_folder_dir ) )<br \/>\t\treturn false;<br \/><br \/>\tif ( is_dir( $avatar_folder_dir ) &amp;&amp; $av_dir = opendir( $avatar_folder_dir ) ) {<br \/>\t\twhile ( false !== ( $avatar_file = readdir($av_dir) ) ) {<br \/>\t\t\t\t@unlink( $avatar_folder_dir . '\/' . $avatar_file );<br \/>\t\t}<br \/>\t\tclosedir($av_dir);<br \/>\t}<br \/><br \/>\t@rmdir( $avatar_folder_dir );<br \/><br \/>}<br \/><br \/>\/**<br \/> * Based on the<br \/> * user_avatar_core_fetch_avatar_filter() 1.2.5 BP<br \/> *<br \/> * Description: Attempts to filter get_avatar function and let Word\/BuddyPress have a go at<br \/> * \t\t\t\tfinding an avatar that may have been uploaded locally.<br \/> *<br \/> * @global array $authordata<br \/> * @param string $avatar The result of get_avatar from before-filter<br \/> * @param int|string|object $user A user ID, email address, or comment object<br \/> * @param int $size Size of the avatar image (thumb\/full)<br \/> * @param string $default URL to a default image to use if no avatar is available<br \/> * @param string $alt Alternate text to use in image tag. Defaults to blank<br \/> * @return &lt;type&gt;<br \/> *\/<br \/>function user_avatar_fetch_avatar_filter( $avatar, $user, $size, $default, $alt ) {<br \/>\tglobal $pagenow;<br \/><br \/>\t\/\/If user is on discussion page, return $avatar<br \/>    if($pagenow == \"options-discussion.php\")<br \/>    \treturn $avatar;<br \/><br \/>\t\/\/ If passed an object, assume $user-&gt;user_id<br \/>\tif ( is_object( $user ) )<br \/>\t\t$id = $user-&gt;user_id;<br \/><br \/>\t\/\/ If passed a number, assume it was a $user_id<br \/>\telse if ( is_numeric( $user ) )<br \/>\t\t$id = $user;<br \/><br \/>\t\/\/ If passed a string and that string returns a user, get the $id<br \/>\telse if ( is_string( $user ) &amp;&amp; ( $user_by_email = get_user_by( 'email', $user ) ) )<br \/>\t\t$id = $user_by_email-&gt;ID;<br \/><br \/>\t\/\/ If somehow $id hasn't been assigned, return the result of get_avatar<br \/>\tif ( empty( $id ) )<br \/>\t\treturn !empty( $avatar ) ? $avatar : $default;<br \/><br \/>\t\/\/ check yo see if there is a file that was uploaded by the user<br \/>\tif( user_avatar_avatar_exists($id) ):<br \/><br \/>\t\t$user_avatar = user_avatar_fetch_avatar( array( 'item_id' =&gt; $id, 'width' =&gt; $size, 'height' =&gt; $size, 'alt' =&gt; $alt ) );<br \/>\t\tif($user_avatar)<br \/>\t\t\treturn $user_avatar;<br \/>\t\telse<br \/>\t\t\treturn !empty( $avatar ) ? $avatar : $default;<br \/>\telse:<br \/>\t\treturn !empty( $avatar ) ? $avatar : $default;<br \/>\tendif;<br \/>\t\/\/ for good measure<br \/>\treturn !empty( $avatar ) ? $avatar : $default;<br \/>}<br \/><br \/>add_filter( 'get_avatar', 'user_avatar_fetch_avatar_filter', 10, 5 );<br \/><br \/>\/**<br \/> * user_avatar_core_fetch_avatar()<br \/> *<br \/> * Description: Fetches an avatar from a BuddyPress object. Supports user\/group\/blog as<br \/> * \t\t\t\tdefault, but can be extended to include your own custom components too.<br \/> *<br \/> * @global object $bp<br \/> * @global object $current_blog<br \/> * @param array $args Determine the output of this function<br \/> * @return string Formatted HTML &lt;img&gt; element, or raw avatar URL based on $html arg<br \/> *\/<br \/>function user_avatar_fetch_avatar( $args = '' ) {<br \/><br \/>\t$defaults = array(<br \/>\t\t'item_id'\t\t=&gt; false,<br \/>\t\t'object'\t\t=&gt; \"user\",\t\t\/\/ user\/group\/blog\/custom type (if you use filters)<br \/>\t\t'type'\t\t\t=&gt; 'full',\t\t\/\/ thumb or full<br \/>\t\t'avatar_dir'\t=&gt; false,\t\t\/\/ Specify a custom avatar directory for your object<br \/>\t\t'width'\t\t\t=&gt; false,\t\t\/\/ Custom width (int)<br \/>\t\t'height'\t\t=&gt; false,\t\t\/\/ Custom height (int)<br \/>\t\t'class'\t\t\t=&gt; '',\t\t\t\/\/ Custom &lt;img&gt; class (string)<br \/>\t\t'css_id'\t\t=&gt; false,\t\t\/\/ Custom &lt;img&gt; ID (string)<br \/>\t\t'alt'\t\t\t=&gt; '',\t\/\/ Custom &lt;img&gt; alt (string)<br \/>\t\t'email'\t\t\t=&gt; false,\t\t\/\/ Pass the user email (for gravatar) to prevent querying the DB for it<br \/>\t\t'no_grav'\t\t=&gt; false,\t\t\/\/ If there is no avatar found, return false instead of a grav?<br \/>\t\t'html'\t\t\t=&gt; true\t\t\t\/\/ Wrap the return img URL in &lt;img \/&gt;<br \/>\t);<br \/><br \/>\t\/\/ Compare defaults to passed and extract<br \/>\t$params = wp_parse_args( $args, $defaults );<br \/>\textract( $params, EXTR_SKIP );<br \/><br \/>\t$avatar_folder_dir = USER_AVATAR_UPLOAD_PATH.\"{$item_id}\/\";<br \/>\t$avatar_folder_url = USER_AVATAR_URL.\"{$item_id}\";<br \/><br \/>\tif($width &gt; 50)<br \/>\t\t$type = \"full\";<br \/><br \/>\t$avatar_size = ( 'full' == $type ) ? '-bpfull' : '-bpthumb';<br \/>\t$class .= \" avatar \";<br \/>\t$class .= \" avatar-\". $width .\" \";<br \/>\t$class .= \" photo\";<br \/><br \/>\tif ( false === $alt)<br \/>\t\t$safe_alt = '';<br \/>\telse<br \/>\t\t$safe_alt = esc_attr( $alt );<br \/><br \/><br \/>\t\/\/ Add an identifying class to each item<br \/>\t$class .= ' ' . $object . '-' . $item_id . '-avatar';<br \/><br \/>\t\/\/ Set CSS ID if passed<br \/>\tif ( !empty( $css_id ) )<br \/>\t\t$css_id = \" id=\\\"\".esc_attr($css_id).\"\\\"\";<br \/><br \/>\t\/\/ Set avatar width<br \/>\tif ( $width )<br \/>\t\t$html_width = \" width=\\\"\".esc_attr($width).\"\\\"\";<br \/>\telse<br \/>\t\t$html_width = ( 'thumb' == $type ) ? ' width=\"' . USER_AVATAR_THUMB_WIDTH . '\"' : ' width=\"' . USER_AVATAR_FULL_WIDTH . '\"';<br \/><br \/>\t\/\/ Set avatar height<br \/>\tif ( $height )<br \/>\t\t$html_height = \" height=\\\"\".esc_attr($height).\"\\\"\";<br \/>\telse<br \/>\t\t$html_height = ( 'thumb' == $type ) ? ' height=\"' . USER_AVATAR_THUMB_HEIGHT . '\"' : ' height=\"' . USER_AVATAR_FULL_HEIGHT . '\"';<br \/><br \/><br \/><br \/>\tif( $avatar_img = user_avatar_avatar_exists( $item_id ) ):<br \/><br \/>\t\t$avatar_src = get_site_url().\"\/wp-content\/uploads\/avatars\/\".$item_id.\"\/\".$avatar_img;<br \/>\t\tif(function_exists('is_subdomain_install') &amp;&amp; !is_subdomain_install())<br \/>\t\t\t$avatar_src = \"\/wp-content\/uploads\/avatars\/\".$item_id.\"\/\".$avatar_img;<br \/><br \/>\t\t$avatar_folder_dir = USER_AVATAR_UPLOAD_PATH.\"{$item_id}\/\";<br \/><br \/>\t\t$file_time = filemtime ($avatar_folder_dir.\"\/\".$avatar_img);<br \/><br \/>\t\t$avatar_url = plugins_url('\/user-avatar\/user-avatar-pic.php').\"?src=\".$avatar_src .\"&amp;w=\".$width.\"&amp;id=\".$item_id.\"&amp;random=\".$file_time;<br \/><br \/>\t\t\/\/ Return it wrapped in an &lt;img&gt; element<br \/>\t\tif ( true === $html ) { \/\/ this helps validate stuff<br \/>\t\t\treturn '&lt;img src=\"' . esc_url($avatar_url) . '\" alt=\"' . esc_attr($alt) . '\" class=\"' . esc_attr($class) . '\"' . $css_id . $html_width . $html_height . ' \/&gt;';<br \/>\t\t\/\/ ...or only the URL<br \/>\t\t} else {<br \/>\t\t\treturn  esc_url( $avatar_url ) ;<br \/>\t\t}<br \/>\telse:<br \/>\t\treturn false;<br \/>\tendif;<br \/>}<br \/>add_action(\"admin_init\", \"user_avatar_delete\");<br \/>\/**<br \/> * user_avatar_delete function.<br \/> *<br \/> * @access public<br \/> * @return void<br \/> *\/<br \/>function user_avatar_delete(){<br \/><br \/>\t\tglobal $pagenow;<br \/><br \/>\t\t$current_user = wp_get_current_user();<br \/><br \/>\t\t$user_id = isset( $_GET&#091;'user_id'] ) ? absint( $_GET&#091;'user_id'] ) : 0;<br \/>\t\t$u       = isset( $_GET&#091;'u'] ) ? absint( $_GET&#091;'u'] ) : 0;<br \/>\t\t$nonce   = isset( $_GET&#091;'_nononce'] ) ? sanitize_text_field( wp_unslash( $_GET&#091;'_nononce'] ) ) : '';<br \/><br \/>\t\t\/\/ If user clicks the remove avatar button, in URL delete_avatar=true<br \/>\t\tif( isset($_GET&#091;'delete_avatar']) &amp;&amp; wp_verify_nonce( $nonce, 'user_avatar') &amp;&amp; ( $u == $current_user-&gt;ID || current_user_can('edit_users')) )<br \/>\t\t{<br \/>\t\t\t$redirect_user_id = '';<br \/><br \/>\t\t\tif( ! empty( $user_id ) )<br \/>\t\t\t\t$redirect_user_id = \"?user_id=\" . $user_id;<br \/><br \/>\t\t\tuser_avatar_delete_files(absint( $u ));<br \/>\t\t\twp_redirect(get_option('siteurl') . '\/wp-admin\/'. $pagenow. $redirect_user_id);<br \/>\t\t\texit;<br \/><br \/>\t\t}<br \/>}<br \/>\/**<br \/> * user_avatar_form function.<br \/> * Description: Creation and calling of appropriate functions on the overlay form.<br \/> * @access public<br \/> * @param mixed $profile<br \/> * @return void<br \/> *\/<br \/>function user_avatar_form($profile)<br \/>{<br \/>\tglobal $current_user;<br \/><br \/>\t$user_id = isset( $_GET&#091;'user_id'] ) ? absint( $_GET&#091;'user_id'] ) : 0;<br \/><br \/>\t\/\/ Check if it is current user or super admin role<br \/>\tif( $profile-&gt;ID == $current_user-&gt;ID || current_user_can('edit_user', $current_user-&gt;ID) || is_super_admin($current_user-&gt;ID) )<br \/>\t{<br \/>\t\t$avatar_folder_dir = USER_AVATAR_UPLOAD_PATH.\"{$profile-&gt;ID}\/\";<br \/>\t?&gt;<br \/>\t&lt;div id=\"user-avatar-display\" class=\"submitbox\" &gt;<br \/>\t&lt;h3 &gt;&lt;?php _e('Picture','user-avatar'); ?&gt;&lt;\/h3&gt;<br \/>\t&lt;p id=\"user-avatar-display-image\"&gt;&lt;?php echo user_avatar_get_avatar($profile-&gt;ID, 150); ?&gt;&lt;\/p&gt;<br \/>\t&lt;a id=\"user-avatar-link\" class=\"button-primary thickbox\" href=\"&lt;?php echo admin_url('admin-ajax.php'); ?&gt;?action=user_avatar_add_photo&amp;step=1&amp;uid=&lt;?php echo absint( $profile-&gt;ID ); ?&gt;&amp;TB_iframe=true&amp;width=720&amp;height=450\" title=\"&lt;?php _e('Upload and Crop an Image to be Displayed','user-avatar'); ?&gt;\" &gt;&lt;?php _e('Update Picture','user-avatar'); ?&gt;&lt;\/a&gt;<br \/><br \/>\t&lt;?php<br \/>\t\t\/\/ Remove the User-Avatar button if there is no uploaded image<br \/><br \/>\t\tif(isset($_GET&#091;'user_id'])):<br \/>\t\t\t$remove_url = admin_url('user-edit.php?user_id='.$user_id.'&amp;delete_avatar=true&amp;_nononce='. wp_create_nonce('user_avatar').'&amp;u='.absint( $profile-&gt;ID ));<br \/>\t\telse:<br \/>\t\t\t$remove_url = admin_url('profile.php?delete_avatar=true&amp;_nononce='. wp_create_nonce('user_avatar').'&amp;u='.absint( $profile-&gt;ID ));<br \/><br \/>\t\tendif;<br \/>\t\tif ( user_avatar_avatar_exists($profile-&gt;ID) ):?&gt;<br \/>\t\t\t&lt;a id=\"user-avatar-remove\" class=\"submitdelete deleteaction\" href=\"&lt;?php echo esc_url_raw($remove_url); ?&gt;\" title=\"&lt;?php _e('Remove User Avatar Image','user-avatar'); ?&gt;\" &gt;&lt;?php _e('Remove','user-avatar'); ?&gt;&lt;\/a&gt;<br \/>\t\t\t&lt;?php<br \/>\t\tendif;<br \/>\t?&gt;<br \/>\t&lt;\/div&gt;<br \/>\t&lt;script type=\"text\/javascript\"&gt;<br \/>\tfunction user_avatar_refresh_image(img){<br \/>\t jQuery('#user-avatar-display-image').html(img);<br \/>\t}<br \/>\tfunction add_remove_avatar_link(){<br \/>\t\tif(!jQuery(\"#user-avatar-remove\").is('a')){<br \/>\t\t\tjQuery('#user-avatar-link').after(\" &lt;a href='&lt;?php echo esc_url( $remove_url ); ?&gt;' class='submitdelete'  id='user-avatar-remove' &gt;&lt;?php _e('Remove','user-avatar'); ?&gt;&lt;\/a&gt;\")<br \/>\t\t}<br \/><br \/><br \/>\t}<br \/><br \/>\t&lt;\/script&gt;<br \/>\t&lt;?php<br \/>\t}<br \/>}<br \/><br \/>\/*-- HELPER FUNCTIONS --*\/<br \/>\/**<br \/> * user_avatar_avatar_exists function.<br \/> *<br \/> * @access public<br \/> * @param mixed $id<br \/> * @return void<br \/> *\/<br \/>function user_avatar_avatar_exists($id){<br \/><br \/>\t$avatar_folder_dir = USER_AVATAR_UPLOAD_PATH.\"{$id}\/\";<br \/>\t$return = false;<br \/><br \/>\tif ( is_dir( $avatar_folder_dir ) &amp;&amp; $av_dir = opendir( $avatar_folder_dir ) ) {<br \/><br \/>\t\t\t\/\/ Stash files in an array once to check for one that matches<br \/>\t\t\t$avatar_files = array();<br \/>\t\t\twhile ( false !== ( $avatar_file = readdir($av_dir) ) ) {<br \/>\t\t\t\t\/\/ Only add files to the array (skip directories)<br \/>\t\t\t\tif ( 2 &lt; strlen( $avatar_file ) )<br \/>\t\t\t\t\t$avatar_files&#091;] = $avatar_file;<br \/>\t\t\t}<br \/><br \/>\t\t\t\/\/ Check for array<br \/>\t\t\tif ( 0 &lt; count( $avatar_files ) ) {<br \/>\t\t\t\t\/\/ Check for current avatar<br \/>\t\t\t\tif( is_array($avatar_files) ):<br \/>\t\t\t\t\tforeach( $avatar_files as $key =&gt; $value ) {<br \/>\t\t\t\t\t\tif(strpos($value, \"-bpfull\")):<br \/>\t\t\t\t\t\t\t$return =  $value;<br \/>\t\t\t\t\t\tendif;<br \/>\t\t\t\t\t}<br \/>\t\t\t\tendif;<br \/><br \/>\t\t\t}<br \/><br \/>\t\t\/\/ Close the avatar directory<br \/>\t\tclosedir( $av_dir );<br \/><br \/>\t}<br \/><br \/>\treturn $return;<br \/>}<br \/>\/**<br \/> * user_avatar_get_avatar function.<br \/> *<br \/> * @access public<br \/> * @param mixed $id<br \/> * @param mixed $width<br \/> * @return void<br \/> *\/<br \/>function user_avatar_get_avatar($id,$width) {<br \/><br \/>\tif(! get_option('show_avatars')):<br \/><br \/>\t\tif( user_avatar_avatar_exists($id) ):<br \/><br \/>\t\t\t$user_avatar = user_avatar_fetch_avatar( array( 'item_id' =&gt; absint( $id ), 'width' =&gt; esc_attr( $width ), 'height' =&gt; esc_attr( $width ), 'alt' =&gt; '' ) );<br \/>\t\t\tif($user_avatar):<br \/>\t\t\t\treturn $user_avatar;<br \/>\t\t\telse:<br \/>\t\t\t\treturn '&lt;img src=\"'.USER_AVATAR_DEFAULT.'\" width=\"'.esc_attr( $width ).'\" height=\"'.esc_attr( $width ).'\" class=\"avatar\" \/&gt;';<br \/>\t\t\tendif;<br \/>\t\telse:<br \/>\t\t\treturn '&lt;img src=\"'.USER_AVATAR_DEFAULT.'\" width=\"'.esc_attr( $width ).'\" height=\"'.esc_attr( $width ).'\" class=\"avatar\" \/&gt;';<br \/>\t\tendif;<br \/>\telse:<br \/>\t\treturn get_avatar($id,$width);<br \/>\tendif;<br \/>}<br \/>\/* --- END OF FILE --- *\/<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-18899642","topic","type-topic","status-publish","hentry","topic-tag-fixed"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18899642","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18899642\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=18899642"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}