// Enqueue JS and pass ajax_url + nonce add_action('admin_enqueue_scripts', function () { wp_enqueue_script('pr-custom-ajax', plugin_dir_url(__FILE__) . 'admin.js', array('jquery'), null, true); wp_localize_script('pr-custom-ajax', 'myAjax', array( 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('pr_download_nonce') )); }); // AJAX callback for property download add_action("wp_ajax_pr_import_auth", "pr_import_auth"); function pr_import_auth() { if (!isset($_POST['security']) || !wp_verify_nonce($_POST['security'], 'pr_download_nonce')) { wp_send_json_error('Unauthorized request'); } $pr_import = new pr_properties_class(); $pr_import->download_xml(); $data = array( 'action' => 'delete', 'chunk' => 0, 'size' => 1000 ); update_option('pr_api_info', json_encode($data)); wp_send_json_success('Properties downloaded'); }{"id":1,"count":4,"description":"","link":"https:\/\/www.odmor.webexperts.me\/en\/category\/uncategorized\/","name":"Uncategorized","slug":"uncategorized","taxonomy":"category","parent":0,"meta":[],"_links":{"self":[{"href":"https:\/\/www.odmor.webexperts.me\/en\/wp-json\/wp\/v2\/categories\/1","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.odmor.webexperts.me\/en\/wp-json\/wp\/v2\/categories"}],"about":[{"href":"https:\/\/www.odmor.webexperts.me\/en\/wp-json\/wp\/v2\/taxonomies\/category"}],"wp:post_type":[{"href":"https:\/\/www.odmor.webexperts.me\/en\/wp-json\/wp\/v2\/posts?categories=1"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}