Which WordPress function is specifically designed to escape HTML attributes to prevent XSS attacks?
Think about escaping values inside HTML tag attributes like title or alt.
esc_attr() is used to escape data for HTML attributes, preventing XSS by encoding special characters. esc_html() escapes HTML content, wp_kses_post() allows limited HTML tags, and sanitize_text_field() cleans text but does not escape HTML attributes.
Given the user input <script>alert('XSS')</script>, which WordPress function will output the input safely as plain text on a page without executing the script?
Consider which function converts HTML tags to safe text so they show visibly instead of running.
esc_html() converts HTML tags to entities, so the script tag is shown as text, preventing execution. wp_kses_post() allows some HTML tags, so the script tag might be stripped but not escaped. esc_attr() is for attributes, and echoing raw input is unsafe.
Which option correctly uses wp_kses() to allow only <a> tags with href attributes in user content?
Check the correct data type for allowed attributes in wp_kses().
The allowed attributes array must have attribute names as keys and true (boolean) as values to allow them. Only option B uses true boolean correctly. Option B uses the string 'true' which is invalid. Other options use strings or numbers which are invalid.
What is the main security issue in this WordPress snippet?
$user_input = $_POST['comment']; echo "<p>User said: $user_input</p>";
$user_input = $_POST['comment']; echo "<p>User said: $user_input</p>";
Think about what happens if user input contains HTML or script tags.
The code directly outputs user input inside HTML without escaping. This allows attackers to inject scripts. Proper escaping functions like esc_html() or esc_attr() must be used before output.
In WordPress, if you store user input with sanitize_text_field() and later display it with esc_html(), what is the expected behavior?
Consider the difference between sanitizing on input and escaping on output.
sanitize_text_field() cleans input by removing harmful characters before saving. esc_html() safely escapes output for HTML display. Together, they prevent XSS without double escaping or errors.