最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - How to create WordPress nonce in the foreach loop?

programmeradmin2浏览0评论

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:

发布评论

评论列表(0)

  1. 暂无评论