SHARE
TWEET

Untitled

a guest Jun 16th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class AjaxCalls {
  2.  
  3.   const NONCE = 'ajax-post-nonce';
  4.  
  5.   public static $instance = null;
  6.  
  7.   public static function getInstance()
  8.   {
  9.     null === self::$instance AND self::$instance = new self;
  10.     return self::$instance;
  11.   }
  12.  
  13.   public function getName()
  14.   {
  15.  
  16.     check_ajax_referer(self::NONCE, 'nonce', true);
  17.  
  18.     echo "anselmo aroca";
  19.  
  20.     die();
  21.   }
  22.  
  23.   /**
  24.    * Handles the AJAX request for my plugin.
  25.    */
  26.   public function getDni()
  27.   {
  28.  
  29.     check_ajax_referer(self::NONCE, 'nonce', true);
  30.  
  31.     echo "24353566q";
  32.  
  33.     die();
  34.   }
  35.  
  36.   /**
  37.    * Register our AJAX JavaScript.
  38.    */
  39.   public function register_script()
  40.   {
  41.       wp_register_script('wp_ajax', get_template_directory_uri() . '/static/scripts.js', array('jquery'),null,true);
  42.       wp_localize_script('wp_ajax', 'wp_ajax_data', $this->get_ajax_data());
  43.       wp_enqueue_script('wp_ajax');
  44.   }
  45.  
  46.  
  47.   private function get_ajax_data()
  48.   {
  49.     return array(
  50.       'ajaxurl' => admin_url('admin-ajax.php'),
  51.       'nonce' => wp_create_nonce(AjaxCalls::NONCE)
  52.     );
  53.   }
  54.  
  55.  
  56.  
  57.  
  58. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top