Question

I'm using UserUltra Pro plugin and I need to create a custom post type after user register in the site. UserUltra plugin uses wp_create_user() which I know is a wrapper for wp_insert_user(). Moreover, I know that 'user_register' is the hook called after wp_insert_user().

Beside this, I can't create new custom post type because it seems that user_register hook is not called. Is this possible? How can I manage it?

Was it helpful?

Solution

There are actually two actions: One when the profile is updated and one when the user is registered.

# Fires immediately after an existing user is updated.
do_action( 'profile_update', $user_id, $old_user_data );

# Fires immediately after a new user is registered.
do_action( 'user_register', $user_id );

So as long as the user login is not empty and the user name does not exist, it should proceed. Take a look at the return clauses:

if ( empty( $user_login ) ) {
    return new WP_Error('empty_user_login', __('Cannot create a user with an empty login name.') );
}

if ( ! $update && username_exists( $user_login ) ) {
    return new WP_Error( 'existing_user_login', __( 'Sorry, that username already exists!' ) );
}

That means if you ain't get an WP_Error object back, it should execute. You can try the numerous filters inside the core function to narrow down where things break if your hook isn't executing. The one running before the error returns, is the following:

apply_filters( 'pre_user_login', $sanitized_user_login );

If this one works, then the plugin simply isn't checking for is_wp_error() and ignoring the failing insert call.

<?php /** Plugin Name: Test if wp_insert_user() filters work */
add_filter( 'pre_user_login', function( $user )
{
    var_dump( current_filter()." works fine" );
    return $user;
} );
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top