I found the following link which talks about this issue, and also gives an solution:
https://wordpress.org/support/topic/fix-media-php-on-line-647-non-numeric-value/
If someone needs the fix, please see below.
PHP Warning: A non-numeric value encountered in /var/www/staging/wp-includes/media.php on line 647
Fix:
Replace the following function in class-wp-user-avatar-functions.php
public function wpua_get_avatar_original($id_or_email="", $size="", $default="", $alt="") {
global $avatar_default, $mustache_avatar, $wpua_avatar_default, $wpua_disable_gravatar, $wpua_functions;
// Remove get_avatar filter
remove_filter('get_avatar', array($wpua_functions, 'wpua_get_avatar_filter'));
if((bool) $wpua_disable_gravatar != 1) {
// User doesn't have Gravatar and Default Avatar is wp_user_avatar, show custom Default Avatar
if(!$wpua_functions->wpua_has_gravatar($id_or_email) && $avatar_default == 'wp_user_avatar') {
// Show custom Default Avatar
if(!empty($wpua_avatar_default) && $wpua_functions->wpua_attachment_is_image($wpua_avatar_default)) {
// $wpua_avatar_default_image = $wpua_functions->wpua_get_attachment_image_src($wpua_avatar_default, array($size,$size));
$size_numeric_w_x_h = array( get_option( $size . '_size_w' ), get_option( $size . '_size_h' ) );
$wpua_avatar_default_image = $wpua_functions->wpua_get_attachment_image_src($wpua_avatar_default, $size_numeric_w_x_h);
$default = $wpua_avatar_default_image[0];
} else {
$default = $mustache_avatar;
}
} else {
// Get image from Gravatar, whether it's the user's image or default image
$wpua_image = get_avatar($id_or_email, $size);
// Takes the img tag, extracts the src
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $wpua_image, $matches, PREG_SET_ORDER);
$default = !empty($matches) ? $matches [0] [1] : "";
}
} else {
if(!empty($wpua_avatar_default) && $wpua_functions->wpua_attachment_is_image($wpua_avatar_default)) {
// $wpua_avatar_default_image = $wpua_functions->wpua_get_attachment_image_src($wpua_avatar_default, array($size,$size));
$size_numeric_w_x_h = array( get_option( $size . '_size_w' ), get_option( $size . '_size_h' ) );
$wpua_avatar_default_image = $wpua_functions->wpua_get_attachment_image_src($wpua_avatar_default, $size_numeric_w_x_h);
$default = $wpua_avatar_default_image[0];
} else {
$default = $mustache_avatar;
}
}
// Enable get_avatar filter
add_filter('get_avatar', array($wpua_functions, 'wpua_get_avatar_filter'), 10, 5);
/**
* Filter original avatar src
* @since 1.9
* @param string $default
*/
return apply_filters('wpua_get_avatar_original', $default);
}
-
This reply was modified 5 years, 2 months ago by opicron.
If an second notice is thrown:
Notice: Trying to get property 'display_name' of non-object in /var/www/../class-wp-user-avatar.php on line 176
The solution is to add an short if to line 176 of class-wp-user-avatar.php:
<p id="<?php echo ($user=='add-new-user') ? 'wpua-add-button' : 'wpua-add-button-existing'?>"><button type="button" class="button" id="<?php echo ($user=='add-new-user') ? 'wpua-add' : 'wpua-add-existing'?>" name="<?php echo ($user=='add-new-user') ? 'wpua-add' : 'wpua-add-existing'?>" data-title="<?php _e('Choose Image','wp-user-avatar'); ?>: <?php echo ( ! empty( $user->display_name ) ? $user->display_name:''); ?>"><?php _e('Choose Image','wp-user-avatar'); ?></button></p>
I noticed an new version was pushed out. I re-added above changes to avoid the notices thrown.
Would you be so kind to implement above changes to avoid notices on staging servers?
Hello,
We have added these changes and released a minor update. Thanks for your efforts.
Thanks