admin管理员组文章数量:1130349
I'm using this hook to allow only admin roles access dashboard
add_action( 'admin_init', function() {
if ( defined('DOING_AJAX') && DOING_AJAX ) {
return;
}
if ( !current_user_can('manage_options') ) {
wp_redirect( home_url('/meu-perfil') );
exit();
}
});
Now I need to run a function when a form is submitted on front end, like so:
function editUser() {
error_log('message');
}
add_action( 'admin_post_nopriv_add_foobar', 'editUser' );
add_action( 'admin_post_add_foobar', 'editUser' );
But the first hook is blocking the second one.
I'm using this hook to allow only admin roles access dashboard
add_action( 'admin_init', function() {
if ( defined('DOING_AJAX') && DOING_AJAX ) {
return;
}
if ( !current_user_can('manage_options') ) {
wp_redirect( home_url('/meu-perfil') );
exit();
}
});
Now I need to run a function when a form is submitted on front end, like so:
function editUser() {
error_log('message');
}
add_action( 'admin_post_nopriv_add_foobar', 'editUser' );
add_action( 'admin_post_add_foobar', 'editUser' );
But the first hook is blocking the second one.
Share Improve this question edited Nov 7, 2018 at 20:46 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Nov 7, 2018 at 11:41 MarceloMarcelo 473 bronze badges1 Answer
Reset to default 3All you need to do is to modify your method of restricting users.
add_action( 'admin_init', function() {
if ( (defined('DOING_AJAX') && DOING_AJAX) || ( strpos($_SERVER['SCRIPT_NAME'], 'admin-post.php') ) ) {
return;
}
if ( !current_user_can('manage_options') ) {
wp_redirect( home_url('/meu-perfil') );
exit();
}
}
I'm using this hook to allow only admin roles access dashboard
add_action( 'admin_init', function() {
if ( defined('DOING_AJAX') && DOING_AJAX ) {
return;
}
if ( !current_user_can('manage_options') ) {
wp_redirect( home_url('/meu-perfil') );
exit();
}
});
Now I need to run a function when a form is submitted on front end, like so:
function editUser() {
error_log('message');
}
add_action( 'admin_post_nopriv_add_foobar', 'editUser' );
add_action( 'admin_post_add_foobar', 'editUser' );
But the first hook is blocking the second one.
I'm using this hook to allow only admin roles access dashboard
add_action( 'admin_init', function() {
if ( defined('DOING_AJAX') && DOING_AJAX ) {
return;
}
if ( !current_user_can('manage_options') ) {
wp_redirect( home_url('/meu-perfil') );
exit();
}
});
Now I need to run a function when a form is submitted on front end, like so:
function editUser() {
error_log('message');
}
add_action( 'admin_post_nopriv_add_foobar', 'editUser' );
add_action( 'admin_post_add_foobar', 'editUser' );
But the first hook is blocking the second one.
Share Improve this question edited Nov 7, 2018 at 20:46 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Nov 7, 2018 at 11:41 MarceloMarcelo 473 bronze badges1 Answer
Reset to default 3All you need to do is to modify your method of restricting users.
add_action( 'admin_init', function() {
if ( (defined('DOING_AJAX') && DOING_AJAX) || ( strpos($_SERVER['SCRIPT_NAME'], 'admin-post.php') ) ) {
return;
}
if ( !current_user_can('manage_options') ) {
wp_redirect( home_url('/meu-perfil') );
exit();
}
}
本文标签: Restrict access to admin but allow adminpost hook
版权声明:本文标题:Restrict access to admin but allow admin_post hook 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749199036a2331483.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论