WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My code is so simple like when admin delete a post by Wordpress fucntion (PHP) and do action with jQuery

$id = $_POST['ID'];



This is my code , what are you think about security ? this is enough ?

share|improve this question
up vote 3 down vote accepted

At first, read something about WordPress Ajax API and about Roles and Capabilities - capability to "edit_posts" has even Contributor. I would suggest to check for 'delete_others_posts' to prove the user is at least Editor. Or use capability of 'manage_options' (has Administrator, not Editor).

Further, there is a check ajax referer function for you to help prevent entries from outside your website. Read more about nonces also.

Here is an example from the codex on using nonces when in AJAX:

In your main file, set the nonce like this:

<script type="text/javascript">
    var data = {
        action: 'my_action',
        security: '<?php echo $ajax_nonce; ?>',
        my_string: 'Hello World!'
    $.post(ajaxurl, data, function(response) {
        alert("Response: " + response);

In your ajax file, check the referrer like this:

add_action( 'wp_ajax_my_action', 'my_action_function' );
function my_action_function() {
    check_ajax_referer( 'my-special-string', 'security' );
    echo $_POST['my_string'];
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.