Skip to content

Instantly share code, notes, and snippets.

@videlais
Last active January 27, 2017 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save videlais/a4d3c299bddfb624413c1d558d89bf46 to your computer and use it in GitHub Desktop.
Save videlais/a4d3c299bddfb624413c1d558d89bf46 to your computer and use it in GitHub Desktop.
<?php
// Assume this is part of a larger plugin project
// Enqueue our AJAX script
// Tell WordPress to make sure jQuery is also loaded as part of our dependency array
wp_enqueue_script( 'ajax-script', plugins_url( '/js/test.js', __FILE__ ), array('jquery') );
// Add 'wp_ajax' tied to the "example_function" action
add_action( 'wp_ajax_example_function', 'example_function_callback' );
// Callback function for the wp_ajax_example_function action
function example_function_callback() {
// Echo back the some_value passed to it
echo $_POST["some_value"];
// Die gracefully to guarantee proper return response
wp_die();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment