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: Allow only specific attributes in block elements
add_filter( 'wp_pre_kses_block_attributes', function( $block_content, $context ) {
$allowed_attributes = array(
'class',
'data-custom-attribute'
);
return array_intersect_key( $block_content, array_flip( $allowed_attributes ) );
}, 10, 2 );
// Example 2: Remove all attributes from block elements
add_filter( 'wp_pre_kses_block_attributes', function( $block_content, $context ) {
return array();
}, 10, 2 );
// Example 3: Modify specific attributes in block elements
add_filter( 'wp_pre_kses_block_attributes', function( $block_content, $context ) {
if ( isset( $block_content['class'] ) ) {
$block_content['class'] .= ' custom-class';
}
return $block_content;
}, 10, 2 );