Hi everyone,
As MB AIO now supports MB Framework, I tried to deactivate the Metabox plugin and a snippet stopped functioning. The snippet is supposed to update user avatar from 'avatar' single image custom field. It just stopped functioning and all the avatar reverts back to placeholder. All the setting and ID are not changed at all for CPT and custom fields.
Upon reactivating Metabox plugin, the avatar photos came back like normal. Here is the snippet I'm using which I don't know if AIO now has different function that normal Metabox plugin or not:
// Get user avatar from Metabox Image field
add_filter( 'get_avatar_url', 'mb_get_avatar_url', 10, 3 );
function mb_get_avatar_url( $url, $id_or_email, $args ) {
if ( is_numeric( $id_or_email ) ) {
$user_id = $id_or_email;
} elseif ( is_string( $id_or_email ) && ( $user = get_user_by( 'email', $id_or_email ) ) ) {
$user_id = $user->ID;
} elseif ( is_object( $id_or_email ) && ! empty( $id_or_email->user_id ) ) {
$user_id = (int) $id_or_email->user_id;
}
if ( empty( $user_id ) ) {
return $url;
}
// change after rwmb_meta to 'the custom field id'
$custom_avatar = rwmb_meta( 'avatar', [ 'object_type' => 'user' ], $user_id );
if ( ! $custom_avatar ) {
return $url;
}
$url = $custom_avatar['full_url'];
return $url;
}
add_filter( 'init', function() {
global $wp_rewrite;
$wp_rewrite->author_base = 'user';
});