Nonces and Cache

I know this question is ancient, but no, it’s not very secure. Anyone with knowledge of the AJAX endpoint would be able to generate valid nonces, which defeats the purpose in the first place. That being said, nonces are a low level defence in the first place: they only stop the simplest of attacks. A … Read more

How to add to cart via AJAX Woocommerce [closed]

are we talking about the single product view or the product archive pages (shop,categories)? because the text beside the checkbox/option states, roughly translated: »activate ajax-checkout-button on product archive pages« and on all the installations i did so for, that is the way its working – ajax checkout on the archives, but not on the single … Read more

Ajax and autocomplete

Use jQuerys getJSON in the autocompletes source method and use WordPress’ admin-ajax.php to handle the request, to avoid having to find wp-load.php (which may have been moved) and would load WordPress on every request. First of all: get the ajax url of your WordPress blog: This is simple: admin_url( ‘admin-ajax.php’ ) But, we want this … Read more

Execute one AJAX request after another AJAX request finished

What you’re experiencing (AJAX works locally, but not on the server) there is a delay problem. Locally everything works that fast, that you can’t see your problem. In short, this is your problem: AJAX callback (A) executes > AJAX Callback (B) doesn’t know that it has to wait for (A) > You can’t see the … Read more

gettext does not translate when called in ajax

it is too late but for public use: /* if qTranslate is installed */ /* set front locale for ajax calls requested from front-end */ function set_locale_for_frontend_ajax_calls() { if ( is_admin() && defined( ‘DOING_AJAX’ ) && DOING_AJAX && substr( $_SERVER[‘HTTP_REFERER’], 0, strlen( admin_url() ) ) != admin_url() ) { load_theme_textdomain( ‘your-theme-domain-name’, get_template_directory() . ‘/languages’ ); … Read more

Displaying PHP Errors from admin-ajax.php

WordPress by default hide errors for ajax request call. This can be confirmed from the source file wp-includes/load.php#L352, here: if ( defined( ‘XMLRPC_REQUEST’ ) || defined( ‘REST_REQUEST’ ) || ( defined( ‘WP_INSTALLING’ ) && WP_INSTALLING ) || wp_doing_ajax() ) { @ini_set( ‘display_errors’, 0 ); } See the function wp_doing_ajax() is being used in the conditional … Read more

WordPress Ajax Data Security

There are a few things you can do to make more secure: First the Ajax call it self should be made with a WordPress nonce like you said: <script type=”text/javascript” > jQuery(document).ready(function($) { var data = { action: ‘ACTION_NAME’, Whatever_data: 1234, _ajax_nonce: <?php echo wp_create_nonce( ‘my_ajax_nonce’ ); ?> }; $.post(ajaxurl, data, function(response) { alert(‘Got this … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)