Random WordPress Function

Learn about a new WordPress function every day!


Function Signature:

wp_pre_kses_block_attributes

Function Description:

Removes non-allowable HTML from parsed block attribute values when filtering in the post context.

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_pre_kses_block_attributes function
add_filter( 'wp_pre_kses_block_attributes', 'my_custom_function', 10, 2 );
function my_custom_function( $block_content, $block ) {
    // Add custom logic here to modify block attributes before they are sanitized
    return $block_content;
}
// Example 2: Prevent certain attributes from being stripped by wp_pre_kses_block_attributes function
add_filter( 'wp_pre_kses_block_attributes', 'prevent_specific_attributes', 10, 2 );
function prevent_specific_attributes( $block_content, $block ) {
    // Check if the block type is 'core/image' and prevent 'alt' attribute from being stripped
    if ( $block['blockName'] === 'core/image' ) {
        $block_content['alt'] = 'Custom Alt Text';
    }
    return $block_content;
}
// Example 3: Modify allowed attributes for specific block types using wp_pre_kses_block_attributes function
add_filter( 'wp_pre_kses_block_attributes', 'modify_allowed_attributes', 10, 2 );
function modify_allowed_attributes( $block_content, $block ) {
    // Check if the block type is 'core/paragraph' and modify allowed attributes
    if ( $block['blockName'] === 'core/paragraph' ) {
        $block_content['data-custom-attribute'] = 'Custom Value';
    }
    return $block_content;
}