check_admin_referer fails on new AJAX plugin uninstall with “Are you sure you want to do this?”
check_admin_referer fails on new AJAX plugin uninstall with “Are you sure you want to do this?”
check_admin_referer fails on new AJAX plugin uninstall with “Are you sure you want to do this?”
to pass a variable from JavaScript to the AJAX call, you have to put the message in the data : data : {“message” : “my message”} and you retrieve it in the PHP code : function testAJAX() { $returnArray = array(); $returnArray[‘message’] = $_POST[“message”]; wp_send_json($returnArray); } you can read about the use of wp_send_json here … Read more
In the JavaScript, you’re using “action”: “tihom_rating_action”, but in PHP you’re using wp_ajax_nopriv_my_action. Instead of my_action you need to use tihom_rating_action as well.
Overwriting Plugin’s Ajax callback function from theme
length might help yous. Look here or here.
Move the AJAX handler function hook outside of init callback and hook your script registrations to wp_enqueue_scripts. And, the hook to attach the handler callback would be wp_ajax_nopriv_postcode_ajax2. function ajax_postcode_form_init() { wp_register_script(‘ajax-login-script’, get_bloginfo(‘stylesheet_directory’). ‘/ajax-postcode-script.js’, array(‘jquery’) ); wp_localize_script( ‘ajax-login-script’, ‘ajax_login_object’, array( ‘ajax_url’ => admin_url( ‘admin-ajax.php’ ), )); wp_enqueue_script(‘ajax-login-script’); } add_action(‘wp_enqueue_scripts’, ‘ajax_postcode_form_init’); function postcode_ajax2() { $postcode = … Read more
Yes that would be easy. You can use the get_the_permalink() function to retrieve a post’s link. Here’s how to do it: // You are storing the post data here $posts_arr[] = $post; // Add the URL to the same array element $posts_arr[][‘url’] = get_the_permalink(); You can get the index of the current post in the … Read more
Frontend AJAX Request causes Error: ‘Call to undefined function add_action’
How to get the admin page slug using wp_loaded hook?
I wanted to update this older question. I got this working or at least I got the saving worked out. Thanks Tom J Nowell for your input. I considerd using the REST API yes, I looked at some introductions, but this went over my head. The REST API but also AJAX is kinda new to … Read more