Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a nonce field for security in a WordPress plugin form.
Wordpress
<?php wp_nonce_field([1], 'my_plugin_nonce'); ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the nonce field name instead of the action name.
Leaving the first argument empty or incorrect.
✗ Incorrect
The first argument to wp_nonce_field is the action name, which should be a unique string identifying the action.
2fill in blank
mediumComplete the code to verify the nonce in a WordPress plugin before processing form data.
Wordpress
if ( ! isset($_POST['my_plugin_nonce']) || ! wp_verify_nonce($_POST['my_plugin_nonce'], [1]) ) { die('Security check failed'); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the nonce field name instead of the action name.
Not checking if the nonce is set before verifying.
✗ Incorrect
The second argument to wp_verify_nonce must match the action name used when creating the nonce.
3fill in blank
hardFix the error in sanitizing a text input from a form in a WordPress plugin.
Wordpress
$user_input = [1]($_POST['user_text']);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using esc_html which is for output escaping, not input sanitization.
Using sanitize_email for non-email inputs.
✗ Incorrect
sanitize_text_field is the correct function to clean plain text input from users.
4fill in blank
hardFill both blanks to safely output a sanitized user input in a WordPress plugin.
Wordpress
echo [1]( [2] );
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not escaping output before echoing.
Trying to sanitize again at output instead of escaping.
✗ Incorrect
Use esc_html to safely display the sanitized user input stored in $user_input.
5fill in blank
hardFill all three blanks to create a secure form handler in a WordPress plugin.
Wordpress
if ( isset($_POST['submit']) && wp_verify_nonce($_POST['[1]'], '[2]') ) { $safe_input = [3]($_POST['user_input']); // Process $safe_input }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up nonce field name and action name.
Not sanitizing input before use.
✗ Incorrect
Verify the nonce field 'my_plugin_nonce' with action 'my_plugin_action' and sanitize input with sanitize_text_field.