/**
* Add Avatar URL to custom user fields and update user
* on specific action.
*
* @since 1.0
*/
class XFWP_Avatar_Integration extends XFWP_Integration {
/**
* Fire actions to plugin hooks and filters.
*
* @since 1.0
*/
public function init() {
add_action( 'xprofile_avatar_uploaded', array( $this, 'update_user_avatar' ) );
add_filter( 'xfwp_custom_fields', array( $this, 'add_custom_user_fields' ) );
add_filter( 'xfwp_custom_user_fields_data', array( $this, 'set_custom_user_fields' ), 10, 4 );
}
/**
* Register field to XFtoWP + adds to Custom fields select box
*
* @since 1.0
*/
public function add_custom_user_fields( $custom_fields ) {
$custom_fields['user']['url_avatar'] = array(
'label' => 'Custom avatar URL'
);
return $custom_fields;
}
/**
* Set dynamic value to custom user field as set in add_custom_user_fields() method.
*
* @since 1.0
*/
public function set_custom_user_fields( $custom_fields, $wp_user, $wp_usermeta, $post_id ) {
$custom_fields['url_avatar'] = 'https://domain.com/avatar5.png';
return $custom_fields;
}
/**
* Update XF user when action is run.
*
* @since 1.0
*/
public function update_user_avatar( $wp_user_id ) {
$wp_user = new WP_User( $wp_user_id );
$this->users->update_user( $wp_user_id, array(
'email' => sanitize_email( $wp_user->user_email ),
'action' => 'sync_user'
) );
}
}
new XFWP_Avatar_Integration;