• Resolved CoreyFF

    (@coreyff)


    When the plugin is active, wp_insert_user calls from a custom API don’t function correctly. I have a feeling it’s the same issue mentioned in this thread. The business end of the code is as follows:

    $user_id = wp_insert_user( $user_data ); 
      
      if ( ! is_wp_error( $user_id ) ) {
        foreach( $user_meta as $key => $val ) {
          update_user_meta( $user_id, $key, $val ); 
        }  
      }

    When the plugin is deactivated, the $user_id var is populated with the new user id, as expected. The user is created and all user meta is inserted. However, when the plugin is active, this call always returns “Sorry, that username already exists!” The user record is created, but the user meta update fails along with everything after that in the function. Any idea what could cause this? Thanks!

    • This topic was modified 6 years ago by CoreyFF.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Jeff Sherk

    (@jsherk)

    What is the actual error you are seeing or that is being logged in the error log?

    Most likely my plugin is getting triggered by the user_registration action hook.

    I will do some testing to see if I can distinguish when the new user comes from my plugin versus other code/plugin.

    Thread Starter CoreyFF

    (@coreyff)

    I appreciate it Jeff. “Sorry, that username already exists!” is the message that gets returned directly by wp_insert_user (a WP_Error object). I don’t see any error in the log when this runs.

    Plugin Author Jeff Sherk

    (@jsherk)

    Just updated to version 1.9.1

    I added a hidden field on my registration page, and the plugin will not do anything if that field is not present.

    This should fix the issue.

    Please test and let me know.

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘wp_user_insert doesn’t behave properly’ is closed to new replies.