0
0
Wordpressframework~10 mins

Nonce verification in Wordpress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to verify a nonce in WordPress.

Wordpress
if ( ! wp_verify_nonce( $_POST['[1]'], 'my_action' ) ) {
    wp_die( 'Security check failed' );
}
Drag options to blanks, or click blank then click option'
Acheck_nonce
Bmy_nonce
Cnonce_value
Dsecurity_token
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong nonce field name.
Not checking the nonce at all.
2fill in blank
medium

Complete the code to create a nonce field in a WordPress form.

Wordpress
<?php wp_nonce_field( '[1]', 'my_nonce' ); ?>
Drag options to blanks, or click blank then click option'
Amy_action
Bsave_post
Csubmit_form
Dnonce_check
Attempts:
3 left
💡 Hint
Common Mistakes
Using different action names for creating and verifying nonce.
Omitting the nonce field in the form.
3fill in blank
hard

Fix the error in the nonce verification code.

Wordpress
if ( ! wp_verify_nonce( $_POST['[1]'], 'save_post' ) ) {
    wp_die( 'Invalid nonce' );
}
Drag options to blanks, or click blank then click option'
Amy_nonce
Bnonce
Csecurity
Dtoken
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different nonce field name than the form.
Not checking if the nonce exists before verifying.
4fill in blank
hard

Fill both blanks to create and verify a nonce correctly.

Wordpress
<?php wp_nonce_field( '[1]', '[2]' ); ?>

if ( ! wp_verify_nonce( $_POST['my_nonce'], '[3]' ) ) {
    wp_die( 'Nonce check failed' );
}
Drag options to blanks, or click blank then click option'
Aupdate_data
Bmy_nonce
Csave_data
Dnonce_field
Attempts:
3 left
💡 Hint
Common Mistakes
Using different action names for creation and verification.
Mismatching nonce field names.
5fill in blank
hard

Fill all three blanks to properly create, check, and handle a nonce in WordPress.

Wordpress
<?php wp_nonce_field( '[1]', '[2]' ); ?>

if ( ! isset( $_POST['[2]'] ) || ! wp_verify_nonce( $_POST['[2]'], '[1]' ) ) {
    wp_die( '[3]' );
}
Drag options to blanks, or click blank then click option'
Adelete_post
Bdelete_nonce
CNonce verification failed
DInvalid nonce
Attempts:
3 left
💡 Hint
Common Mistakes
Not checking if nonce is set before verification.
Using different names for nonce field and action.
Using unclear error messages.