Call to undefined function add_action()

WordPress has a native AJAX file that should do all that you want, and this will ensure that all native WP functions are included. If you require additional functionality from ‘framework/AsyncAction.php’, you can include_once(), as you do with ‘SettingsController.php’.

See the Codex for more information and examples – AJAX in Plugins

If you wish to use AJAX on the front end of your website, you need to add the following lines to your functions.php file –

/** Declare the URL to the file that handles the AJAX request (wp-admin/admin-ajax.php) */
wp_enqueue_script('my-ajax-request', admin_url('admin-ajax.php'), array('jquery'));
wp_localize_script('my-ajax-request', 'MyAjax', array('ajaxurl' => admin_url('admin-ajax.php')));

Leave a Comment