Random WordPress Function

Learn about a new WordPress function every day!


Function Signature:

wp_kses_hair

Function Description:

Given a string of HTML attributes and values, parse into a structured attribute list.

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: Basic usage of wp_kses_hair to sanitize an array of data
$data = array(
    'name' => '',
    'email' => 'example@example.com',
    'message' => 'Click here'
);

$sanitized_data = wp_kses_hair($data, array(
    'name' => array(
        'filter' => FILTER_SANITIZE_STRING,
        'flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH
    ),
    'email' => FILTER_SANITIZE_EMAIL,
    'message' => array(
        'filter' => FILTER_SANITIZE_STRING,
        'flags' => FILTER_FLAG_ENCODE_AMP
    )
));

// Example 2: Using wp_kses_hair to allow specific HTML tags and attributes
$content = '

This is bold text

Click here'; $sanitized_content = wp_kses_hair($content, array( 'p' => array(), 'strong' => array(), 'a' => array( 'href' => true, 'target' => '_blank' ) )); // Example 3: Applying wp_kses_hair to sanitize user input before saving to the database if(isset($_POST['data'])){ $user_input = $_POST['data']; $sanitized_input = wp_kses_hair($user_input, array( 'filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH )); // Save sanitized input to the database }