action user_new_form param is a string

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?

Topic user-meta profiles Wordpress

Category Web


Just check if ID member is set:

function my_show_extra_profile_fields( $user ) {
    $id = isset($user->ID)? $user->ID : -9999;
    $newsletter = esc_attr( get_the_author_meta( '_newsletter', $id ) );
}

use like this:

$id = $user->ID;

And if user is new set $id = 9999

function my_show_extra_profile_fields( $user ) {

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

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.