admin管理员组文章数量:1122832
I'm trying to submit form using:
`admin_post` && `admin_post_nopriv`
actions. This is a shortcode for users search:
add_shortcode( 'search_users', 'search_users' );
function search_users( $atts ,$content = null ) {
ob_start();?>
<div class="search-box-main-container">
<form method="POST" id="sul-searchform" action="<?php echo home_url() . '/wp-admin/admin-post.php' ?>" class="search-form">
<div class="search-box-container">
<input type="text" class="search-box" name="search" id="sul-s"/>
</div>
<div class="submit-container">
<input type="hidden" name="action" value="search_users_action">
<input type="submit" class="search-box-submit" name="submit" id="sul-searchsubmit"
value="Search"/>
</div>
</form>
</div>
<?php
$output = ob_get_contents();
ob_end_clean();
return $output;
}
And these are the actions:
add_action( 'admin_post_search_users_action', 'list_users' );
add_action( 'admin_post_nopriv_search_users_action', 'list_users' );
function list_users() {
$search = (isset($_POST['search'])) ?sanitize_text_field($_POST['search']) : false;
wp_redirect( home_url() . '/user-listing?search=' . $search );
}
They work only for admin users and unauthenticated users. With authenticated non-admin user, the actions haven't been called. It just redirects to the home page!
Is there another action to handle authenticated non-admin users?
I'm trying to submit form using:
`admin_post` && `admin_post_nopriv`
actions. This is a shortcode for users search:
add_shortcode( 'search_users', 'search_users' );
function search_users( $atts ,$content = null ) {
ob_start();?>
<div class="search-box-main-container">
<form method="POST" id="sul-searchform" action="<?php echo home_url() . '/wp-admin/admin-post.php' ?>" class="search-form">
<div class="search-box-container">
<input type="text" class="search-box" name="search" id="sul-s"/>
</div>
<div class="submit-container">
<input type="hidden" name="action" value="search_users_action">
<input type="submit" class="search-box-submit" name="submit" id="sul-searchsubmit"
value="Search"/>
</div>
</form>
</div>
<?php
$output = ob_get_contents();
ob_end_clean();
return $output;
}
And these are the actions:
add_action( 'admin_post_search_users_action', 'list_users' );
add_action( 'admin_post_nopriv_search_users_action', 'list_users' );
function list_users() {
$search = (isset($_POST['search'])) ?sanitize_text_field($_POST['search']) : false;
wp_redirect( home_url() . '/user-listing?search=' . $search );
}
They work only for admin users and unauthenticated users. With authenticated non-admin user, the actions haven't been called. It just redirects to the home page!
Is there another action to handle authenticated non-admin users?
Share Improve this question edited Sep 12, 2019 at 19:14 Matthew Brown aka Lord Matt 1,0683 gold badges13 silver badges34 bronze badges asked Sep 12, 2019 at 11:58 Rowayda KhayriRowayda Khayri 1215 bronze badges 6 | Show 1 more comment1 Answer
Reset to default 0I found that the issue was due to another plugin on my site. After deactivating it, everything works well. So, the action admin_post
is used for all authenticated users( admins and non-admins ).
本文标签: Wordpress action adminpost for nonadmin authenticated usersForm submission
版权声明:本文标题:Wordpress action admin_post for non-admin authenticated users - Form submission 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736293304a1929119.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
admin_post
can be used for all authenticated users, andadmin_post_nopriv
for all non-authenticated users. But depending on what you want to do, there are other relevant hooks likeinit
andtemplate_redirect
which you can use to process submitted form data, redirect the user, etc. – Sally CJ Commented Sep 12, 2019 at 12:33