0
<?php
/**
* Template Name: Manage Days
*/


if ( isset($_GET['remove_date']) && isset($_GET['_wpnonce']) ) {
    $delete_date = $_GET['remove_date'];
    $delete_nonce = $_GET['_wpnonce'];

    if ( ! wp_verify_nonce( $delete_nonce, 'holiday_nonce' ) ) {
        die( 'Failed security check' );
    } else {
        $delete_holiday = $wpdb->delete( 
        $wpdb->prefix . 'ab_holidays',
            [ 'staff_id' => $staff_id, 'date' => $delete_date ],
            [ '%d', '%s' ] );
    }

}

get_header(); ?>

    <?php
        $disable_dates = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}ab_holidays WHERE staff_id = '$staff_id'");

        foreach ( $disable_dates as $disable_date ) {
            $originalDate = $disable_date->date;
            $newDate = date("F j, Y", strtotime($originalDate));

            $nonce = wp_create_nonce( 'holiday_nonce' . $originalDate );
            echo '<a href="' . get_permalink() . '?remove_date=' . $originalDate . '&_wpnonce=' . $nonce . '" class="delete-holiday"><i class="fa fa-times-circle"></i></a>' . $newDate . '<br />';
        }
    ?>

<?php
get_footer();

if ( ! wp_verify_nonce( $delete_nonce, 'holiday_nonce' ) ) { .... } else { ..... }

This code isn't working....

  • 1
    What exactly is your question? The Theme Handbook has a chapter about using nonces, where everything should be explained – kero Aug 13 '18 at 9:12
  • I can't verify nonce in header, if ( ! wp_verify_nonce( $delete_nonce, 'holiday_nonce' ) ) { ....... } this code is not working in header – Sonjoy Datta Aug 13 '18 at 9:21
  • 1
    Please edit your question and make it clear what is it that you are asking about so even people that do not look at your computer can understand it ;) A wall of code can be good in addition to a textual description but it rarely makes a good question by itself – Mark Kaplun Aug 13 '18 at 9:23
  • I have edited my question. The blockquote don't working.... – Sonjoy Datta Aug 13 '18 at 9:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.