Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to safely output a user input in WordPress.
Wordpress
<?php echo [1]($_GET['user_input']); ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using print_r or var_dump which do not escape output
Using htmlspecialchars_decode which decodes entities
✗ Incorrect
Use esc_html to safely escape HTML characters and prevent XSS.
2fill in blank
mediumComplete the code to sanitize a text input before saving in WordPress.
Wordpress
$safe_text = [1]($_POST['comment']);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using sanitize_email for non-email input
Using esc_url which is for URLs
✗ Incorrect
sanitize_text_field cleans text input by stripping tags and harmful content.
3fill in blank
hardFix the error in escaping a URL output in WordPress.
Wordpress
<a href="[1]($url)">Link</a>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using esc_html which is for HTML content, not URLs
Using esc_url_raw which is for saving URLs, not output
✗ Incorrect
esc_url properly escapes URLs for safe output in HTML attributes.
4fill in blank
hardFill both blanks to allow safe HTML tags in user input and output it.
Wordpress
<?php $allowed_tags = [1](); echo [2]($user_input, $allowed_tags); ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using esc_html which escapes all HTML
Using sanitize_text_field which strips all tags
✗ Incorrect
wp_kses_allowed_html returns allowed HTML tags, and wp_kses filters input to allow only those tags.
5fill in blank
hardFill all three blanks to create a safe attribute output with a default fallback.
Wordpress
<?php $title = isset($data['title']) ? [1]($data['title']) : [2]; echo '<h1 title="' . [3]($title) . '">' . $title . '</h1>'; ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not escaping attribute output
Using esc_html instead of esc_attr for attributes
✗ Incorrect
sanitize_text_field cleans the input, "Default Title" is fallback text, and esc_attr safely escapes the attribute.