Home Wordpress admin-post.php only working if role=admin, but need subscriber role to work too
Reply: 1

Wordpress admin-post.php only working if role=admin, but need subscriber role to work too

tjp
1#
tjp Published in 2018-02-14 10:14:48Z

On a Wordpress website, I am using admin-post.php in a form (code below) on my website to trigger an action upon submitting the form, where I can process the $_POST items and set some cookies. This works fine if I set my account role to admin, but does not work if I simply change the role to subscriber (I will need my subscribers to be able to submit this form). As subscriber role, instead of running admin-post.php, it just redirects me to the website homepage, even though I am still logged in. So it acts like admin-post.php is not executable as subscriber role, but I am not sure how to change this... maybe I need a some kind of .htaccess code in the wp-admin dir? I am stumped... any ideas?

< form method='post' action='/wp-admin/admin-post.php'>

< input type='hidden' name='action' value='run_my_wp_action'   >
//Other form items removed

<input type='submit' name='submit' value='Next' >
</form >

PHP in my WP plugin

add_action( 'admin_post_nopriv_run_my_wp_action', 'my_wp_action' );     
add_action( 'admin_post_input_run_my_wp_action', 'my_wp_action' );          

function my_wp_action() {   //code  }
vel
2#
vel Reply to 2018-02-14 10:44:33Z

Try with wp_ajax.

add_action( 'wp_ajax_my_wp_action', 'my_wp_action' );          
add_action( 'wp_ajax_nopriv_my_wp_action', 'my_wp_action' ); 

function my_wp_action() {   //code  }
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.358071 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO