0
0
Wordpressframework~20 mins

Data sanitization in Wordpress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
WordPress Data Sanitization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What does the sanitize_text_field() function do in WordPress?
Choose the best description of what sanitize_text_field() does when processing user input.
AConverts all text to uppercase without removing any characters.
BOnly trims whitespace but leaves HTML tags intact.
CEncrypts the text to store it securely in the database.
DRemoves all HTML tags and encodes special characters to prevent code injection.
Attempts:
2 left
💡 Hint
Think about how to safely clean text inputs to avoid harmful code.
component_behavior
intermediate
2:00remaining
What will be the output of this WordPress code snippet?
Given the following code, what will echo $cleaned; output?
Wordpress
<?php
$input = "<script>alert('hack');</script>Hello <b>World</b>!";
$cleaned = sanitize_text_field($input);
echo $cleaned;
?>
Aalert('hack');Hello World!
B&lt;script&gt;alert('hack');&lt;/script&gt;Hello &lt;b&gt;World&lt;/b&gt;!
CHello World!
D<script>alert('hack');</script>Hello <b>World</b>!
Attempts:
2 left
💡 Hint
Remember what sanitize_text_field() removes from the input.
📝 Syntax
advanced
2:00remaining
Which option correctly sanitizes a URL input in WordPress?
Select the code snippet that properly sanitizes a URL stored in $url before saving.
A$safe_url = sanitize_text_field($url);
B$safe_url = htmlspecialchars($url);
C$safe_url = esc_url_raw($url);
D$safe_url = wp_strip_all_tags($url);
Attempts:
2 left
💡 Hint
Think about which WordPress function is designed specifically for URLs.
🔧 Debug
advanced
2:00remaining
Why does this WordPress code fail to sanitize user input properly?
Identify the problem in this code snippet that tries to sanitize a user-submitted email:
Wordpress
<?php
$email = $_POST['email'];
$clean_email = sanitize_email;
echo $clean_email($email);
?>
Asanitize_email should be replaced with sanitize_text_field.
BThe function sanitize_email is not called correctly; it should be sanitize_email($email).
CThe variable $email is not defined before sanitization.
Dsanitize_email does not exist in WordPress.
Attempts:
2 left
💡 Hint
Check how the function is used in the code.
state_output
expert
2:00remaining
What is the value of $result after running this WordPress code?
Consider this code snippet and determine the final value of $result:
Wordpress
<?php
$input = "<a href='http://example.com'>Click</a> & <b>Bold</b>";
$step1 = wp_strip_all_tags($input);
$step2 = sanitize_text_field($step1);
$result = $step2;
?>
AClick & Bold
BClick & Bold
CClick &amp; Bold
DClick &amp; & Bold
Attempts:
2 left
💡 Hint
Check what each function removes or encodes.