Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AjaxCalls {
- const NONCE = 'ajax-post-nonce';
- public static $instance = null;
- public static function getInstance()
- {
- null === self::$instance AND self::$instance = new self;
- return self::$instance;
- }
- public function getName()
- {
- check_ajax_referer(self::NONCE, 'nonce', true);
- echo "anselmo aroca";
- die();
- }
- /**
- * Handles the AJAX request for my plugin.
- */
- public function getDni()
- {
- check_ajax_referer(self::NONCE, 'nonce', true);
- echo "24353566q";
- die();
- }
- /**
- * Register our AJAX JavaScript.
- */
- public function register_script()
- {
- wp_register_script('wp_ajax', get_template_directory_uri() . '/static/scripts.js', array('jquery'),null,true);
- wp_localize_script('wp_ajax', 'wp_ajax_data', $this->get_ajax_data());
- wp_enqueue_script('wp_ajax');
- }
- private function get_ajax_data()
- {
- return array(
- 'ajaxurl' => admin_url('admin-ajax.php'),
- 'nonce' => wp_create_nonce(AjaxCalls::NONCE)
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement