Tag Info

Hot answers tagged

3

As of 4.1.1, the nonce is defined in wp-includes/media.php, line 2883: $settings['post'] = array( 'id' => $post->ID, 'nonce' => wp_create_nonce( 'update-post_' . $post->ID ), ); So to verify the nonce: wp_verify_nonce( $nonce, "update-post_$post_ID" );


2

You don't need to check is_admin because the function is hooked to admin_init, so is_admin() is always true in the callback; that makes that ( is_admin() || !empty(DOING_AJAX) ) always verify as true. You only need to check if the constant DOING_AJAX is not defined or if it is defined and it is false (both cases are not an AJAX request), combined with the ...


2

You're sending your AJAX request to the wrong place. Of course calling functions.php directly will get you undefined function errors, because the WordPress API isn't loaded by functions.php ( it's the other way round ). A car doesn't make fuel go forward, fuel makes a car go forward, simply getting in the car won't make fuel magically appear, in the same ...


1

You are going on the wrong way.This will create difficulties and is NOT WORDPRESS STANDARD.Wordpress has a ajax technique to implement this. Call the ajax from your page <script> var data = { 'action': 'insert_data_customtable', 'first_name': firstname, 'last_name': lastname }; // since 2.8 ajaxurl is always defined in the admin header ...


1

The problem is that about.php is not a recognized file by WordPress and won't load any of the actual WordPress functions. <?php wp_header(); ?> in your themes header.php file actually loads most the WordPress functionality that you're used to using. Since you're not calling either get_header() OR wp_header() in your about.php file you don't actually ...


1

First of all, some recommended reading - AJAX in Plugins. I realise this is not a plugin, but the Codex is still relevant, and as you'll see in the PHP section, you can use the WP AJAX handler to handle front end calls as well as those from the admin area. Javascript For this, you would be better advised putting your JS in an external *.js file that is ...


1

Your AJAX callback method should be outputting something followed by a die() statement. function wp_insert() { ..your code echo $whatever_your_results_are; // die(); } I would also recommend against prefixing your custom methods with wp_. That should be reserved for WordPress and will cause confusion to other developers - and probably you ...


1

Authenticated here means according to the is_user_logged_in() function, i.e. if the user is logged in or not, no matter the user role. This part from the admin-ajax.php file, explains it all: if ( is_user_logged_in() ) { /** * Fires authenticated AJAX actions for logged-in users. * * The dynamic portion of the hook name, ...


1

wp-admin/admin-ajax.php is the script used by any plugin or theme using WP Ajax API and Ajax actions can be registered for non-logged in users. For example: //For logged in users add_action( 'wp_ajax_my_action', 'my_action_callback' ); //For non-logged in users add_action( 'wp_ajax_nopriv_my_action', 'my_action_callback' ); There is no problem on that. ...



Only top voted, non community-wiki answers of a minimum length are eligible