increase nonce lifespan

I want to increase the nonce lifespan from the default 12-24h, to 36-48h. I found the following code in the codex, but don’t know where to put it. add_filter( ‘nonce_life’, function () { return 172800; } ); can i put this line in the functions.php to change the nonce lifespan sitewide? Is there an easy … Read more

ajax and nonce when JavaScript is in a seperate file

I’m a little confused about how nonces work with ajax requests. It looks like I’m supposed to use this: https://codex.wordpress.org/Function_Reference/check_ajax_referer The request looks like this: <?php //Set Your Nonce $ajax_nonce = wp_create_nonce( “my-special-string” ); ?> <script type=”text/javascript”> jQuery(document).ready(function($){ var data = { action: ‘my_action’, security: ‘<?php echo $ajax_nonce; ?>’, my_string: ‘Hello World!’ }; $.post(ajaxurl, data, … Read more

how to get nonce using json api

I try to open this url in my browser or calling from my frontend application: http://78.47.177.214/blog/api/get_nonce/?controller=posts&method=create_post i keep getting the response {“status”:”error”,”error”:”Include ‘controller’ and ‘method’ vars in your request.”} what is wrong, I want to be able to create a custom post type with custom fields in the end but using json api I need … Read more

WP REST API: check if user is logged in

The idea is to show or hide some sections of the site in a theme that’s fetching all data from the REST API, using AngularJS. I thought this check would help me (nonce is passed as header, as suggested by docs): wp_localize_script(‘angularjs’, ‘params’, array( ‘nonce’ => wp_create_nonce(‘wp_rest’), ‘nonce_verify’ => wp_verify_nonce($_REQUEST[‘X-WP-Nonce’], ‘wp_rest’) )); The nonce parameter … Read more

Reduce nonce lifespan

for a personal plugin (nothing going to the public or commercial), I built an AJAX form and its endpoint is a custom endpoint (REST Api). When a certain Page containing my form is accessed, I generate a nonce. Then, the user sends the form, I add the conventional header (X-WP-Nonce) and in the endpoint function … Read more

Undefined index: at_nonce in custom post metabox

I’m getting this error with my custom post metabox. The custom post and metabox works fine, but if i have debug on and when i try to save any other page or post, i will get an error: Notice: Undefined index: at_nonce in /Users/jay/site/wp-content/themes/mytheme/dogs-post-type.php on line 53 Notice: Undefined index: at_nonce in /Users/jay/site/wp-content/themes/mytheme/dogs-post-type.php on line … Read more

wp_verify_nonce always returns false when logged in as admin

I’ve implemented some AJAX functionality for my plugin and it works fine as long as I’m not logged in as admin – then wp_verify_nonce fails. It works for unauthorized users and authorized regular users too. Here’s my PHP class (I removed everything that is not relevant to the issue): class My_Ajax { function __construct() { … Read more