Created
June 24, 2017 20:58
-
-
Save resonantdoghouse/1da9bb57b6066b07f18b8ee6abcb074d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment