1

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?

  • The documentation says that parameter is called $type, not $user. Presumably that get_the_author_meta() line is in your callback for this hook, so you know the user can't exist? So you can't use any ID? – Rup Aug 10 '16 at 17:26
  • 2
    Look at this answer: stackoverflow.com/questions/9139614/…. Specially if(current_filter() == 'user_new_form' – Manolo Aug 10 '16 at 19:06
0

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);
}
| improve this answer | |
  • 1
    That may save him creating a temp user object in that particular code since he's only passing the ID (and I don't think $user is a global) but doesn't solve the general problem. – Rup Aug 10 '16 at 17:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.