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' => 'test@example.com',
    'message' => 'Click here'
);

$sanitized_data = wp_kses_hair($data, array(
    'name' => array(
        'filter' => 'sanitize_text_field'
    ),
    'email' => array(
        'filter' => 'sanitize_email'
    ),
    'message' => array(
        'filter' => 'wp_kses_post'
    )
));

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

This is a bold and link

'; $sanitized_content = wp_kses_hair($content, array( '' => array( 'filter' => 'wp_kses', 'args' => array( 'a' => array( 'href' => true ), 'strong' => array() ) ) )); // Example 3: Handling nested arrays with wp_kses_hair $data = array( 'name' => array( 'first' => '', 'last' => 'Doe' ), 'email' => 'test@example.com' ); $sanitized_data = wp_kses_hair($data, array( 'name' => array( 'filter' => 'sanitize_text_field', 'children' => array( 'first' => array( 'filter' => 'sanitize_text_field' ), 'last' => array( 'filter' => 'sanitize_text_field' ) ) ), 'email' => array( 'filter' => 'sanitize_email' ) ));