action hook after registration - Pie Register
2018-12-11 22:19:17

action hook after registration

Home Forums Pie-Register 2.0 Support action hook after registration

This topic contains 6 replies, has 3 voices, and was last updated by  Ashley T 1 year, 1 month ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #4556

    Vanessa Grimes
    Participant

    I have a custom plugin that I would like to fire ~after~ a user has registered with the pie register screen, but before verification. The custom plugin code is using the ‘user_register’ action hook at which time I query the user metadata for the register_type. Using WP_DEBUG_LOG and error_log, I can see that inside my function, the register_type metadata is not there yet. So apparently hooking into user_register is too early. Can you please recommend an appropriate action to hook into once the registration is complete but before the user verifies?

    TIA
    -VG

    #4557

    Pie Register
    Keymaster

    Hello,

    You can “pie_register_after_register_validate” hook that fires before activating the user. This action provides you user object that were newly created into the system.

    Best

    #4558

    Vanessa Grimes
    Participant

    Thank you Hasnain, I just tried using that hook but I have a few problems with doing so.

    First, is that when I use that hook, the user’s meta-data still appears to not be set yet. Here is my code:

    function __construct() {
    	add_action( 'pie_register_after_register_validate', array( $this, 'registered' ) );
    ...
    }
    function registered( $user ) {
    	$user_ID = get_current_user_id();
    	$regtype = get_user_meta($user_id,"register_type",true);
    	error_log($regtype, 0);
    }

    The log file shows a blank line for $regtype.

    My second issue is that if I want my plugin to work for everyone, I need to be able to hook into a common action that is available regardless of whether your plugin is installed or not, so when I originally asked for another action hook, I wasn’t expecting you to suggest a proprietary one. I was hoping you had a do_action somewhere that calls the standard WP actions to complete the process, such as the user_register action. Lastly, I still have a separate hook for the user_register action, and that does fire AFTER your proprietary action, and with the same get_user_meta command, the register_type value is still not in the database. If it’s available in pie_register_after_register_validate and that fires before user_register, then I shouldn’t need pie_register_after_register_validate, and should just need user_register, but the data’s just not there. Or am I using get_user_meta incorrectly? I’m sorry, this is my first try at developing this plugin, but I thought for sure that is the proper way to use get_user_meta.

    Thanks for any additional help you can provide.
    -VG

    #4559

    Pie Register
    Keymaster

    Hello,

    Thanks for your more details, well, the user_register is the first hook that available after the user registers so on that hook the register_type meta wont be available, to have the register_meta available I would recommend you to use pie_register_after_register hook.

    Best

    #4562

    Vanessa Grimes
    Participant

    Thank you Hasnain. That action hook does work to get the register_type. Can I make a request that your next version move up the logic that creates this meta data to be ~before~ the user_register action since all meta data should already be available by that time and allows other developers to be more generic?

    Thanks again
    -VG

    #4564

    Pie Register
    Keymaster

    Hello,

    I am glad you got it working. Well, since PR uses wp registration functions to register a user so its not possible to have user meta available on or before user_register hook, however, perhaps we will try our best to have other global hook available on the registration.

    Thanks

    #5254

    Ashley T
    Participant

    I’m also working on a plugin that will create a draft post when a user registers. Tried using pie_register_after_register as suggested in this thread, but it’s still not wanting to work.

    I’ve narrowed it down to having the Paypal active and installed on the reg form. Draft post is created as expected without the Paypal gateway active. As soon as I activate and register another test user…no draft post.

    I started my own topic on this, but haven’t had any bites yet. Any help is appreciated! My code is as follows:

    add_action( 'pie_register_after_register', 'restaurant_profile_create', 10, 1 );
    function restaurant_profile_create( $user_id )
    {
        // Get user info
        $user_meta = get_user_meta( $user_id, 'pie_text_7', true );
    
        // Create a new post
        $user_post = array(
            'post_author'  => $user_id,
            'post_title'   => $user_meta,
            'post_content' => print_r( $user_meta, true ),
            'post_type'    => 'post', 
        );
        // Insert the post into the database
        $post_id = wp_insert_post( $user_post ); 
        
    } 
Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.