Random WordPress Function

Learn about a new WordPress function every day!


Function Signature:

wp_filter_kses

Function Description:

Sanitize content with allowed HTML KSES rules.

Function Examples:

⚠️ Examples below are generated with GPT-3 once every hour. Do not take them too seriously.
Consider them as some extra input in your learning process - reason about them. Will it work? What could fail?
// Example 1: Sanitize a user input before saving it to the database
$user_input = $_POST['user_input'];
$cleaned_input = wp_filter_kses($user_input);
// Now $cleaned_input is sanitized and can be safely stored in the database
// Example 2: Display user input in a template while preventing XSS attacks
$user_input = get_user_meta(get_current_user_id(), 'user_input', true);
$cleaned_input = wp_filter_kses($user_input);
echo $cleaned_input;
// By using wp_filter_kses, we ensure that any potentially harmful content is removed before displaying it to the user
// Example 3: Sanitize content before displaying it on a custom page template
$page_content = get_post_meta(get_the_ID(), 'page_content', true);
$cleaned_content = wp_filter_kses($page_content);
echo apply_filters('the_content', $cleaned_content);
// Using wp_filter_kses here helps prevent any malicious scripts from being executed when displaying the content on the custom page template