Unable to whitelist `admin_url(‘admin-post.php’)` for an admin post request
-
I’m utilizing the builtin functionality of WordPress for posting my request to
admin-post.phpwithadmin_post_nopriv_{$action}hook for non-logged in users. But when the request is sent the logged out user is redirected to login page, as expected. So, I tried to whitelist the url where request is sent i.e.admin-post.php.But even after whitelisting the url with query parameters, the request redirects to wp-login. When I tried to debug the code, I found that in whitelist function the current
$urlis root url to WordPress, so it redirects back to wp-login.
Here’s what I have tried:function my_forcelogin_whitelist( $whitelist, $url ) { // $url is root url to WordPress for admin-post.php request. $whitelist[] = admin_url( 'admin-post.php?' . $_SERVER['QUERY_STRING'] ); $whitelist[] = admin_url( 'admin-post.php/?' . $_SERVER['QUERY_STRING'] ); return $whitelist; } add_filter( 'v_forcelogin_whitelist', 'my_forcelogin_whitelist', 10, 2 );Please help to solve this.
The topic ‘Unable to whitelist `admin_url(‘admin-post.php’)` for an admin post request’ is closed to new replies.