最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

actions - admin_post hook not called

programmeradmin1浏览0评论

I have good experience in other CMS. but I'm very new in Wordpress. My goal is to intercept POST values in some of the form of a pre-existent site. Following documentation I've done the following steps:

  • I had a look on the page source, finding that the form action:

< form method='post' enctype='multipart/form-data' id='gform_4' action='/volunteer/'>

  • in theme folder I modified function.php adding the code:

add_action( 'admin_post_nopriv_/volunteer/', 'send_contact_to_civicrm');

add_action( 'admin_post_/volunteer/', 'send_contact_to_civicrm' );

  • finally in the same .php file I added the function

function send_contact_to_civicrm() { ... };

But my function is not executed. I also tried to modify the action name in 'admin_post_nopriv_volunteer' but with no result.

Where am I doing wrong? Thanks

I have good experience in other CMS. but I'm very new in Wordpress. My goal is to intercept POST values in some of the form of a pre-existent site. Following documentation I've done the following steps:

  • I had a look on the page source, finding that the form action:

< form method='post' enctype='multipart/form-data' id='gform_4' action='/volunteer/'>

  • in theme folder I modified function.php adding the code:

add_action( 'admin_post_nopriv_/volunteer/', 'send_contact_to_civicrm');

add_action( 'admin_post_/volunteer/', 'send_contact_to_civicrm' );

  • finally in the same .php file I added the function

function send_contact_to_civicrm() { ... };

But my function is not executed. I also tried to modify the action name in 'admin_post_nopriv_volunteer' but with no result.

Where am I doing wrong? Thanks

Share Improve this question edited Nov 16, 2016 at 11:24 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Nov 16, 2016 at 10:54 marcellomarcello 1311 silver badge3 bronze badges 1
  • The action on the form needs to be the the admin url and then you need a hidden form element with name="action" and value="volunteer". – mistertaylor Commented Nov 16, 2016 at 11:31
Add a comment  | 

2 Answers 2

Reset to default 2

Modify your form to include:

<form action="<?php echo admin_url('admin-post.php'); ?>" method="post">
    <input type="hidden" name="action" value="volunteer">
    ...
</form>

and add an action to run your function:

add_action( 'admin_post_volunteer', 'send_contact_to_civicrm' );
add_action( 'admin_post_nopriv_volunteer', 'send_contact_to_civicrm' );

function send_contact_to_civicrm() {
   // stuff here
}

Just checked the code in admin-post.php. Apparently when the user is authenticated the hook admin_post_ACTIONNAME is called.

BUT for an unauthorized request the hook admin_post_nopriv_register_ACTIONAME is called. So I thought everything worked fine on the website. Until an actual client of my practice informed me the register forms weren't operational at all.

AWESOME.

SO! I though I share this information for people who are trying to debug this damn hook.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论