• Resolved jnorell

    (@jnorell)


    Hello,

    I am trying to integrate WP Approve User with Notification sending a user registration welcome email only when a user is approved.

    The normal process for wpau looks to be that it disables the register_new_user action which sends a welcome email, and then calls wp_new_user_notification() itself when a user is approved by an admin. I found a handy wpau_approve action hook which fires just prior to sending the new user notification.

    The process for Notification is to also disable the default new user notification tied to the register_new_user action, and instead run it’s own function (disable_new_user_notify()) on that action to send the email to the admin and/or user as desired.

    So effectively what I want to happen is stop Notification from sending on the register_new_user action, and instead be able to have it send the notification from a custom function (called from the wpau_approve action). Or I’m open to other ideas, too, but that’s my current approach.

    I haven’t found any hooks in Notification at the point the user registration trigger fires to stop that email (I suspect there is something further up the classes though), but I do have a functioning way preventing this message by using the new filter-id: feature. (Ie. I specify a filter-id, and setup a filter function to return no recipient addr if the user has not been approved yet, which I determine by a lookup of the wp-approve-user user_meta.)

    At this point I have a function firing on wpau_approve where I think I need to fire the Notification trigger for user registrations. My first attempt was this which failed:

    `
    add_action( ‘wpau_approve’, function ( $user_id ) {
    if ( class_exists( ‘\BracketSpace\Notification\Defaults\Trigger\User\UserRegistered’ ) ) {
    $trigger = new \BracketSpace\Notification\Defaults\Trigger\User\UserRegistered();
    $trigger::action( $user_id );
    }
    });
    `

    If you know of a way to make that call work as intended, an example of how to setup and fire a trigger from code, or some other approach entirely to the matter, I’d sure appreciate it.

    Thanks,
    Jesse

Viewing 1 replies (of 1 total)
  • Plugin Author Kuba Mikita

    (@kubitomakita)

    Hi Jesse,

    you could simply switch the trigger actions inside. Like this:

    add_action( 'notification/trigger/registered', function( $trigger ) {
    
    	// Check if registered Trigger is the one we need.
    	if ( 'wordpress/user_registered' !== $trigger->get_slug() ) {
    		return;
    	}
    
    	$trigger->remove_action( 'user_register', 1000 );
    	$trigger->add_action( 'wpau_approve' );
    
    } );

    Because both user_register and wpau_approve has the same single argument (user ID), there’s no proxy needed.

    I hope this helps

Viewing 1 replies (of 1 total)
  • The topic ‘how to instantiate and call a trigger from code’ is closed to new replies.