Skip to content

Instantly share code, notes, and snippets.

@barbietunnie
Forked from danielpataki/nonce-url.php
Last active September 13, 2015 17:35
Show Gist options
  • Save barbietunnie/11e482af78438556f936 to your computer and use it in GitHub Desktop.
Save barbietunnie/11e482af78438556f936 to your computer and use it in GitHub Desktop.
Nonces
$delete_link = wp_get_shortlink( get_the_ID() ) . '&delete=true';
$nonced_link = wp_nonce_url( $delete_link, 'delete-post-' . get_the_ID(), '_mynonce' );
<input type="hidden" id="_wpnonce" name="_wpnonce" value="37b392c8a0" />
<input type="hidden" name="_wp_http_referer" value="/2015/02/13/my-article/" />
wp_nonce_field( 'delete-post-' . get_the_ID() );
if ( ! isset( $_GET['_mynonce'] ) || ! wp_verify_nonce( $_GET['_mynonce'], 'delete-post-' . $_GET['p'] )
) {
// Do something if the nonce does not verify
exit();
}
// Process your form
if ( ! isset( $_POST['field_name'] ) || ! wp_verify_nonce( $_POST['field_name'], 'action_name' )
) {
// Do something if the nonce does not verify
exit();
}
// Process your form
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment