wordpress - admin-post.php not calling custom handler hook
Get the solution ↓↓↓I've got a basic email form that I want to use a custom handler on. I tried following this tutorial https://blog.osmosys.asia/2016/05/07/handling-form-submissions-in-wordpress/ but it seems that my custom hook is not being called.
<form class="" action="<?php echo admin_url('admin-post.php') ?>" method="post">
<input type="hidden" name="action" value="bb_submit_email">
<input type="email" id="email" name="email" value="[email protected]" required>
<?php wp_nonce_field('submit-email', '_mynonce'); ?>
<input type="submit" class="float-right btn btn-primary form-button" value="Submit">
</form>
<?php
add_action('admin_post_bb_submit_email', 'bb_handle_email_submit');
add_action('admin_post_nopriv_bb_submit_email', 'bb_handle_email_submit');
function bb_handle_email_submit() {
$logger = wc_get_logger();
$logger->add('submit-email-debug', 'triggered!');
if ( !isset($_POST['_mynonce']) || !wp_verify_nonce($_POST['_mynonce'], 'register-user')) {
return;
}
wp_remote_post('example.com', $_POST );
}
I tried usingwp_ajax
instead but that didn't work either. Anyone see something I'm missing here?
Update: I don't know if this helps but I checked the POST Request data and it has the following:
action: bb_submit_email
email: [email protected]
_mynonce: a2c0e80de7
_wp_http_referer: /
That all looks right to me?
Answer
Solution:
I moved this
<?php
add_action('admin_post_bb_submit_email', 'bb_handle_email_submit');
add_action('admin_post_nopriv_bb_submit_email', 'bb_handle_email_submit');
function bb_handle_email_submit() {
$logger = wc_get_logger();
$logger->add('submit-email-debug', 'triggered!');
if ( !isset($_POST['_mynonce']) || !wp_verify_nonce($_POST['_mynonce'], 'register-user')) {
return;
}
wp_remote_post('example.com', $_POST );
}
tofunctions.php
and it started working. Honestly not sure why?
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: filter_sanitize_string deprecated
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.