See documentation here but don’t miss the note 2 and the following points :
- AJAX on the front-end is more complicated, ajaxurl is not defined so
you have to call it with wp_localize_script(). - you have to use wp_ajax_nopriv_{action} for non logged in users
- there could be security issue !!!
About the third point :
Be careful because you give access to non logged in users to some data and functions. So you need to ask yourself about what you want to do. It could seem a little bit too much but to me when using AJAX on the front-end of WP you should make $_GET things, only for reading, for example infinite scroll ans stuffs like that, not delete, create and update actions.
Related Posts:
- What Are Security Best Practices for WordPress Plugins and Themes? [closed]
- Why “Contact Form 7” doesn’t update PHPmailer library?
- Help making my pagination plugin better
- admin-ajax returning 400 error when request is made with Fetch API
- Does WordPress contain “default” anti-SQL injection code that responds with a 404 error?
- What does a security risk in a plugin look like?
- WordPress Capabilities: edit_user vs edit_users
- Custom plugin giving: wp-admin/admin-ajax.php 400 (Bad Request)
- Ajax Load More and Masonry: is it possible to load admin-ajax.php in the front end?
- Errors while using ajax from external wordpress page
- Built in admin ajax hooks?
- How many security plugins are too many? [closed]
- Will WordPress username displayed somewhere in the site?
- Only execute jQuery function(on document ready) on the page has shortcode from plugin [duplicate]
- Ajax with jQuery UI dialog not working
- Shortcode in AJAX popup
- How can I process xml file on upload?
- How to limit WordPress pages during updates?
- ajax front-end increment views on click
- rms_unique_wp_mu_pl_fl_nm.php
- Why none of the plugins that have ajax doesn’t work in my website?
- wp_create_nonce function doesn’t work inside a plugin?
- How to Create a Custom Panel and Fields in Post Page [Plugin]
- WordPress Ajax Posting from App
- Headers Content-Security-Policy CSP Major Issue
- Nonce failing on form submission
- Theme is Causing Ajax Conflicts for a plugin I cant identify it
- Why WordPress plugin url ajax doesn’t work?
- Search for categories
- Ajax call returning 0
- Ajax fail and get 504 error
- Display wordpress post’s in popup?
- Using color picker in plugin, does input attribute order matter?
- Ajax : Call undefined function plugin_function() … can’t call any plugin function
- AJAX call – failling to call do_action
- What are the Best Practises When Using AJAX in Plugin Development?
- Can some vulnerabilities in plugins be exploited even when the plugin is inactive?
- Prevent direct access to WordPress plugin assets?
- Does having more than 30 Admin Ajax affects site performance (plugin)?
- Submit Form data to another page via Ajax (WordPress Way)
- plugin shortcode not working on ajax request call
- wordpress add_action() issue in ajax call
- PHP script from functions php is loaded via admin-ajax to div…and the result is 0, not the desired content
- Too many login attempts
- Ajax Plugin Not Echoing Response
- Website show Google Ads when we have no Google Ads linked to our website
- WordPress Ajax code is not Working
- don’t call ajax if not plugin page
- woocommerce search by sku and title ajax
- Where Should i write the code for wordpress ajax voting?
- Chrome Dev Tools console says every page in my blog has link to http://maps.google.com [closed]
- Webservice credential storage [duplicate]
- How to include my Ajax calls in one function instead of calling different ones every time?
- Regarding plugin security
- Call ajax on the frontend
- Is this plugin safe to run?
- Using AJAX to run SQL statement and populate dropdown
- Is the Block Bad Queries Plugin Still Relevant?
- best way to run a php script away from the template?
- Need help creating asynchronous data scraper in WordPress
- Ajax call not working in wordpress through a plugin
- Ajax 400 error when used inside a plugin
- Strange admin-ajax / CSS / $_SESSION issue
- wc_get_template_part doesnt display the content [duplicate]
- In a plugin, How to update a json file using ajax
- Cannot pass value variable to WP AJAX functions
- Can you add a shortcode to a custom post type that gets the post_title, post_content, etc. and then passes that to a plugin function?
- JS working when used normally but not in wordpress
- Use AJAX to fetch Current Post Thumbnail for WordPress when Uploaded throughMedia Uploader Frontend
- How to avoid the 403 Forbidden error in a WP Plugin with Ajax and PHP
- wp-admin/admin-ajax.php 400 (Bad Request) plugin
- Bing/msn bots is heavily requesting random of my website
- AJAX update fails for public/non-admin users
- WordPress Ajax request “Failed to load resource: the server responded with a status of 400 ()”
- How to disable/enable PHP plugin functionality based on a TinyMCE toggle-button
- ajax voting for custom post type
- Conditional Fields depending on checkboxes
- Ajax call fails and returns [object Object]
- WordPress environment not loading properly
- wordpress ajax pagination object value does not change
- Ajax specific template not loading in replacement of index.php
- Write mysql credentials in plugin
- Ajax return 0 in plugin – ajax only used in wp-admin
- What’s the preferred method of writing AJAX-enabled plugins?
- using jquery serialize in ajax operation for plugin
- Like/Dislike Bar not working when updating
- SWF in wordpress post
- Unwanted Links and Spam WordPress Pages and Posts
- Trouble Removing Plugin [closed]
- Help me with my first very basic plugin
- How to change response of admin-ajax request?
- File permissions for wp-minify plugin
- Ajax not working for logged in users
- What is the recommended way to be notified of security updates to my plugins? [closed]
- Inline AJAX script passing variables to PHP
- WordPress User Registration/ Sign Up -> Able to take Paid Certification Courses & keep track of Completed Certificates
- Block Root REST API Route using custom &/or iThemes
- Secure way to add JS Script to WordPress filesystem
- Not applying update field (acf) in my plugin
- How to verify/test that a custom built wordpress theme is as secure as possible?