The WordPress nonce creation function is to be called only on the init
hook:
Use the init or any subsequent action to call this function. Calling
it outside of an action can lead to troubles. See #14024 for details.
Since the init
hook “runs after WordPress has finished loading but before any headers are sent”, nonces are created on every full-page request (not ajax request).
So, technically, you can use the same nonce on multiple requests, but you should make them unique on each request, as other answers have pointed out.
To shed some more light about what nonces are:
Nonces are sent on each Ajax request as a security token, to ensure the request was intended by the user.
Related Posts:
- Do I require the use of nonce?
- Security – Ajax and Nonce use [closed]
- Why ajax doesn’t work on certain wordpress hooks and reload the page instead?
- Why ajax doesn’t work on certain wordpress hooks?
- Are nonces in WP REST API optional by default?
- How to use nonce with front end submission form?
- How can I fetch loop of post titles via AJAX?
- Adding “Remember Me” in custom login
- Retrieve POST data from AJAX call
- username_exists() function can’t be access without logging in
- The correct method to pass query vars in AJAX using ajaxurl
- Using wp_send_json to return HTML
- WordPress AJAX Pagination with query_posts
- How build a custom login/register form with error handling?
- Is having multiple theme customizers for different pages possible?
- How to check if new posts have been published since page load?
- WordPress “Link has expired” error on updating posts
- WordPress Ajax always returns a 404 error
- Where to include php files in wordpress and how to refer to them later [closed]
- Redirect to Page after Post Submit
- problem with ajax and the path to the php page
- Can i check if user is doing any ajax request?
- How to use wp_localize_script in a WordPress page other than functions.php?
- Admin Media grid view images won’t load
- Comparing arrays within a loop
- Real time Duplicate title check
- Ajax template: how to handle head section
- Passing JSON data from WP Query into AJAX causing NULL errors
- simple wordpress ajax plugin not working when not logged in
- Load custom field value into div with AJAX
- AJAX / Read More: multiple check_ajax_referer() and wp_create_nonce() not working independentely
- Jquery ajax to custom php file: returning blank data
- Audio Player not loading when the content is loaded through Ajax, MediaElement.js no applied
- Accessing a random image via ajax
- PHP calling AJAX function that relies on passed PHP function values not working
- Update WordPress Custom Field with AJAX on cached page
- Looking for a better way to handle an ajax script that pulls in post data on click
- Targeting single page with JS
- Data fetch and delete by ajax request
- Handling an Ajax form submit
- Ajax call to my WordPress website from an external application [duplicate]
- Making a follow button, Ajax not talking to php
- How to add default images into theme customizer image control?
- Can’t use get_results() in ajax query
- Is the regular ajax request method safe or I should use admin-ajax.php?
- Constructing a custom login form using ajax
- Debugging PHP object during Ajax call in WordPress
- Validate a users email address when using gmail to register
- Custom WordPress+PHP+MYSQL+AJAX form, submit event not captured by Javascript, but does POST data to the DB
- WordPress Ajax Data problem
- Use ajax to update_post_meta
- Problem with WordPress Ajax form
- Click loads template via ajax
- Display notification only once
- admin-ajax.php returning error 400 namespaced callback
- AJAX in WordPress, sending coords data to MySQL and show after into map
- How to retrieve the content (with a specific ID) via ajax by clicking a link tag
- WooCommerce: update custom fields after checkout validation failure
- Access/update database with jQuery
- How to display something in a div when the user clicks on a text in another div – no page refresh [closed]
- Passing jQuery value using Ajax to a page template
- How to set a custom path, for ajax image upload folder in admin?
- When must I use and verify nonce?
- admin-ajax.php responding with 0
- Ajax form submit within a Post Metabox
- What SQL / WordPress queries would need a nonce?
- ajax_object is not defined when ajax calls the function
- How to speed up admin-ajax.php in wordpress
- Returning a value from a PHP page
- Page Reloads Before AJAX Request Finishes
- WordPress File handle – fopen, fwrite not working with $.ajax or $.post Jquery
- Can I use HTTP POSTs? Is there a better alternative?
- Why is this Ajax not working?
- Stumped – Ajax Response Returns 0
- Colorbox ajax loading of outside HTML content works perfect on localhost but not on server
- How to make custom total price reactive in navigation
- Put CSS inside a PHP file and include it the right way
- Sending jsPDF documents to the server
- Ajax $wpdb not returning table data
- How to prevent those PHP variables from being cached on WordPress?
- Use ajax from function.php
- Ajax return code 400
- How to Fetch values from WP database based on selected option value by onchange using PHP?
- wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated
- doing an ajax request always outputs 0
- How to run JS, PHP and etc. inside WP post?
- Trying to implement Ajax comments in WordPress, getting WP error
- How to test nonce with AJAX – Plugin development
- Can’t search posts using WP_QUERY inside AJAX Function
- Woocommerce add to cart quantity buttons with AJAX
- Why is the post meta[] empty when I make a call to the wordpress rest api?
- WP nonce invalid
- class click counter save number
- Any possible way to make $wpdb->get_results() return anything else than array?
- get post based on category chosen in drop down – The ajax method
- Why is $_REQUEST an empty array in admin-ajax.php?
- Checking for new message using AJAX and PHP. Server overload?
- AJAX request status 200 but no actual “response”
- get current custom post ID by WP_Query method
- How to make drop down post title