title: how to add wp nonce to simple ajax function in wordpress
body: <p>i'm trying to make the simple plugins with ajax in wp, and i was make the button such as "like" for posts with support of some peoples</p>
  
  <p>my problem
  1.
  i was find a solution to secure it with nonce, but i refer many in google but not success.</p>
  
  <p>my link when i view code : </p>
  
  <pre><code>&lt;a class="love-button" href="http://localhost/topaco/wp-admin/admin-ajax.php?action=post_love_add_love&amp;amp;post_id=243" data-id="243"&gt;give like for pơst&lt;/a&gt;
  </code></pre>
  
  <p>2.
  I can double click, 3 clicks, 4 clicks and more, the number are Continuous increase if i click to the button.</p>
  
  <p>how to limit one click for one session or set the times user can click to increase the number.</p>
  
  <h1>here is my code,</h1>
  
  <h1>in php plugins file :</h1>
  
  <pre><code>add_action( 'wp_enqueue_scripts', 'ajax_test_enqueue_scripts' );
  function ajax_test_enqueue_scripts() {
      if( is_single() ) {
          wp_enqueue_style( 'love', plugins_url( '/love.css', __FILE__ ) );
      }
      wp_enqueue_script( 'love', plugins_url( '/love.js', __FILE__ ), array('jquery'), '1.0', true );
      wp_localize_script( 'love', 'postlove', array(
          'ajax_url' =&gt; admin_url( 'admin-ajax.php' ),
      ));
  }
  add_filter( 'the_content', 'post_love_display', 99 );
  function post_love_display( $content ) {
  
      //check_ajax_referer( 'thienduc', 'security' );
  
      $love_text = '';
  
      if ( is_single() ) {
  
          $love = get_post_meta( get_the_ID(), 'post_love', true );
          $love = ( empty( $love ) ) ? 0 : $love;
  
          $love_text = '&lt;p class="love-received"&gt;&lt;a class="love-button" href="' . admin_url( 'admin-ajax.php?action=post_love_add_love&amp;post_id=' . get_the_ID() ) . '" data-id="' . get_the_ID() . '"&gt;give love&lt;/a&gt;&lt;span id="love-count"&gt;' . $love . '&lt;/span&gt;&lt;/p&gt;'; 
      }
      return  $love_text . $content;
  }
  add_action( 'wp_ajax_nopriv_post_love_add_love', 'post_love_add_love' );
  add_action( 'wp_ajax_post_love_add_love', 'post_love_add_love' );
  function post_love_add_love() {
      $love = get_post_meta( $_REQUEST['post_id'], 'post_love', true );
      $love++;
      update_post_meta( $_REQUEST['post_id'], 'post_love', $love );
      if ( defined( 'DOING_AJAX' ) &amp;&amp; DOING_AJAX ) { 
          echo $love;
          die();
      }
      else {
          wp_redirect( get_permalink( $_REQUEST['post_id'] ) );
          exit();
      }
  }
  </code></pre>
  
  <p>=============================</p>
  
  <h1>and JS file</h1>
  
  <pre><code>jQuery( document ).on( 'click', '.love-button', function() {
      var post_id = jQuery(this).data('id');
      jQuery.ajax({
          url : postlove.ajax_url,
          type : 'post',
          data : {
              action : 'post_love_add_love',
              post_id : post_id,
          },
          success : function( response ) {
              jQuery('#love-count').html( response );
          }
      });
  
      return false;
  })
  </code></pre>
  
  <hr>