DevinVinson / WordPress-Plugin-Boilerplate

[WordPress] A foundation for WordPress Plugin Development that aims to provide a clear and consistent guide for building your plugins.
http://wppb.io
7.69k stars 2.27k forks source link

wp_ajax_nopriv #410

Open harry-maulana opened 8 years ago

harry-maulana commented 8 years ago

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 commented 8 years ago

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

j92 commented 7 years ago

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.

ramusdev commented 6 years ago

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