Skip to content

Instantly share code, notes, and snippets.

@resonantdoghouse
Created June 24, 2017 20:58
Show Gist options
  • Select an option

  • Save resonantdoghouse/1da9bb57b6066b07f18b8ee6abcb074d to your computer and use it in GitHub Desktop.

Select an option

Save resonantdoghouse/1da9bb57b6066b07f18b8ee6abcb074d to your computer and use it in GitHub Desktop.

Revisions

  1. resonantdoghouse created this gist Jun 24, 2017.
    32 changes: 32 additions & 0 deletions WP Nonces.phtml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@

    <form method="post">
    <input type="hidden" id="wpf_nonce_field" name="wpf_nonce_field" value="1cfd4c0539" />
    <input type="hidden" name="_wp_http_referer" value="/wp-trunk/contact/" />
    Enter your name: <input type="text" name="text" /><br />
    <input type="submit" name="submit" value="Save Options" />
    </form>

    <?php

    /*
    After your form is posted, the fi rst thing you need to do is check your nonce secret key using the wp _ verify _ nonce() function like so:
    */

    if ( isset( $_POST['submit'] ) ) {
    //check nonce for security
    wp_verify_nonce( 'wpf_settings_form_save', 'wpf_nonce_field' );
    //nonce passed, now do stuff
    }


    // Verifying that the nonce is valid is as simple as calling the wp _ verify _ nonce() function

    /*
    Nonces can also be used on links that perform actions. To create a URL nonce, you use the wp _ nonce _ url() function. This can be used in conjunction with multiple query strings in your URL like so:
    */

    $link = 'my-url.php?action=delete&ID=15';
    ?>

    <a href="<?php echo wp_nonce_url( $link, 'wpf_delete_action', 'wpf_nonce_url_check' ); ?>">Delete</a>