Hi again @kubitomakita
I am currently trying to work this out and write my custom notification for this password protected form.
I have declared my custom trigger, and got that showing up – which is meant to be able to send an email straight away isn’t it? (albeit missing the custom merge tags)
I don’t get any email at all..
My code that I am using is:
if ( isset( $_POST['post_Submit'] ) ) {
//Add our action ready for our setting up notification
add_action( 'admin_post_property_password_form', 'property_password_form_handler' );
add_action( 'admin_post_nopriv_property_password_form', 'property_password_form_handler' );
function property_password_form_handler() {
//Set up our action getting the form fields content
do_action( 'property_password_sent', $_POST['post_Name'], $_POST['post_Email'], $_POST['post_Course'] );
exit;
}
}
//Decalare our Trigger with the notification plugin
class PropertyPasswordForm extends \BracketSpace\Notification\Abstracts\Trigger {
public function __construct() {
// Add slug and the title.
parent::__construct(
'propertypasswordsent',
__( 'Property password form sent', 'propertypasswordsent' )
);
// Hook to the action.
$this->add_action( 'property_password_sent', 10, 2 );
}
public function merge_tags() {}
}
//and now register our Trigger
register_trigger( new PropertyPasswordForm() );
The original code we talked about didn’t seem to work correctly – even with commenting out the action this filter just made the password form break and automatically resolve as entered so the content for the page shows up straight away.
add_filter( 'post_password_required', function( $required, $post ) {
if ( $required == false && ! empty( $post->post_password ) ) {
do_action( 'whatever_handle', $post );
}
}, 10, 2 );
Secondly.. I’m not sure how to create my merge tags from the input fields.
I am following your (very handy) tutorial on Smashing Magazine, where your merge tags use content from the post, like the title etc. But I’m really not sure how I can get the content of my do_action where I state the form field inputs and use them in the merge tag.
Do you have any advice at all?
I know this is custom work, but I’d be super grateful for any pointers!
Thanks!