I have created a simple plugin for personal use which I’m trying to extend with an AJAX function. I have added the following:

function cancel_notification() {
    wp_die();
}
add_action('wp_ajax_cancel_notification', 'cancel_notification');
add_action('wp_ajax_nopriv_cancel_notification', 'cancel_notification');

Inside the function I want to use the function “get_option()” to use settings set using the plugin, but all values returned using the function are empty. The settings are set, I’m using them in other places in the plugin.

This is my basic setup:

function cancel_notification() {
    //here I would like to use get_option()
    wp_die();
}
add_action('wp_ajax_cancel_notification', 'cancel_notification');
add_action('wp_ajax_nopriv_cancel_notification', 'cancel_notification');

if(is_admin()) {
    //Call the html code
    add_action('admin_menu', 'foobar_admin_menu');

    function foobar_admin_menu() {
        add_menu_page();
    }
}

function foobar_html_page() {
    //here a form is shown and post actions are done to save data
}

Read more here: WordPress: using get_option inside ajax function


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: