mardi 15 décembre 2015

WP nonce field verification and if statment usage

I have a strange problem in my project if you can please explain me what's going wrong.

So... related to the Codex enter link description here

<?php

if ( 
    ! isset( $_POST['name_of_nonce_field'] ) 
    || ! wp_verify_nonce( $_POST['name_of_nonce_field'], 'name_of_my_action' ) 
) {

   print 'Sorry, your nonce did not verify.';
   exit;

} else {

   // process form data
}

I used this code and its works fine. But now I want to modify this project and tried this code to find my bug.

public function user_can_save($post_id){

    if (isset( $_POST['tutsplus-post-notice-nonce'] ) && wp_verify_nonce( $_POST['tutsplus-post-notice-nonce'], 'tutsplus-post-notice-save' ) )
    {
        $is_autosave = wp_is_post_autosave($post_id);
        $is_revision = wp_is_post_revision($post_id);

        return ! ($is_autosave||$is_revision);

    } else exit;
}

it does not work. At the final of this coding I want to fix this piece of code:

    public function user_can_save($post_id){

        $is_valid_nonce =
            ( isset( $_POST['tutsplus-post-notice-nonce'] ) ) &&
            wp_verify_nonce(
                $_POST[ 'tutsplus-post-notice-nonce' ],
                'tutsplus-post-notice-save'
            );

        $is_autosave = wp_is_post_autosave($post_id);
        $is_revision = wp_is_post_revision($post_id);

        return ! ($is_autosave||$is_revision) && $is_valid_nonce;

    }
}

What is my mistake ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire