WordPress-Plugin-Boilerplate icon indicating copy to clipboard operation
WordPress-Plugin-Boilerplate copied to clipboard

wp_ajax_nopriv

Open harry-maulana opened this issue 8 years ago • 3 comments

where to put wp_ajax_nopriv? in main class (class-plugin-name.php) or in admin class(class-plugin-name-admin.php) or in public class(class-plugin-name-public.php)?

thanks..

harry-maulana avatar Nov 23 '16 01:11 harry-maulana

i has add wp_ajax_nopriv, but still don't work for guest (unauthorized user), please help me master..

harry-maulana avatar Nov 23 '16 08:11 harry-maulana

I don't know if you solved it already but anyway i want to put the solution here.

In class-plugin-name.php there is a public function define_public_hooks(); Add the action needed to handle the form submission there: $this->loader->add_action( 'process_handle_form_submission', $plugin_public, 'process_handle_form_submission' );

In the same file, add the public method process_handle_form_submission. Now when the form is submitted, you can access the $_POST in process_handle_form_submission and handle the request.

For security reasons, always make use of the wp_nonce_field.

If you still have question, let me know.

j92 avatar Jan 28 '17 07:01 j92

Maybe somebody have a repo with this example $this->loader->add_action( 'process_handle_form_submission', $plugin_public, 'process_handle_form_submission' );

ramusdev avatar Feb 21 '18 09:02 ramusdev