action user_new_form param is a string

Question

In the action user_new_form, the parameter $user returns a string add-new-user.

I’ve used esc_attr( get_the_author_meta( '_typeuser', $user->ID ) ); but I get an error.

Another question on the topic is non-response at the moment but I’ve patched the problem with:

/* PROFIL FIELD */
add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
add_action( 'user_new_form', 'my_show_extra_profile_fields');

function my_show_extra_profile_fields( $user ) {

    if(is_string($user) === true){
        $user = new stdClass();//create a new
        $user->ID = -9999;
    }
    $newsletter = esc_attr( get_the_author_meta( '_newsletter', $user->ID ) );
    unset($user);
}

How we can fix this problem without creating an object and setup $user->ID to -9999 for new user?

0
, Jean-philippe Emond 7 years 2016-08-10T12:01:54-05:00 0 Answers 77 views 0

Leave an answer

Browse
Browse