admin管理员组

文章数量:1418591

In my plugin list of email page, I need to remove email using Ajax call. I can delete it using Ajax call but how I can secure this ajax call?

I need to create nonce, right? Well, then how?

If I create a nonce inside foreach loop to the data attribute then it's showing me the same value!

foreach ( $results as $result ) {                   
    echo "<tr>";
        echo "<td>" . intval ( $count )."</td>";
        echo "<td>" . esc_html ( $result['email_address'] ) ."</td>";
        echo "<td>" . esc_html ( $result['added_time'] ) ."</td>";
        echo "<td><a href='?page=simple-newsletter-send-email&e=".esc_url ( $result['email_address'] ) ."'>Send Email</a> | <a href='#' data-nonce='".wp_create_nonce( 'sn_email_list_tab' )."' id='sn_remove_email'>Remove</a></td>";
    echo "</tr>";
    $count++;   
}

My questions are

1) what is the correct way to secure the ajax call in this scenario?
2) Is there any way to add a nonce to the ajax URL?

Email List with remove button:

本文标签: pluginsHow to create WordPress nonce in the foreach loop