WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 2 years ago

#39724 new enhancement

Defining custom validation callbacks for tag/attribute values in wp_kses()

Reported by: enrico.sorcinelli Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.8
Component: Formatting Keywords:
Focuses: Cc:
PR Number:

Description

This patch allows to define a custom validation callbacks to check tag/attributres values in wp_kes() etc.

The callbacks are defined through wp_kses_allowed_html filter. If a tag and/or tag attribute is a callable function/method, then it will be used to check/validate/process the value, for example:

<?php

add_filter( 'wp_kses_allowed_html', 'my_wp_kses_allowed_html_flter' ), 10, 2 );

function my_wp_kses_allowed_html_flter ( $tags, $context ) {
   $tags['span']['style'] = function ( $name, $value, $element ) { 
      // return sanitized $value or empty to remove it
      return $value;
   };
   // iframe callback
   $tags['iframe'] = function ( $element, $attr ) { 
      // does something with complete attribute string or return empty to remove it
      return $attr;
      };
   return $tags;
}

While waiting for the core updates the list of allowed tags/attribitutes/values (for example for style attribute, see #24157, #37134, #37248 and probaly many others), this enhancement could offer the possibility of having the fine control over every tag attributes value.

Regards

Attachments (3)

39724.patch (3.5 KB) - added by enrico.sorcinelli 3 years ago.
39724.2.patch (3.6 KB) - added by enrico.sorcinelli 2 years ago.
I just updated the patch to the current trunk.
39724.3.patch (3.6 KB) - added by enrico.sorcinelli 2 years ago.
I just updated the patch to the current trunk.

Download all attachments as: .zip

Change History (5)

#1 @SergeyBiryukov
3 years ago

  • Summary changed from Defining custom validation callbacks for tag/attribute values in wp_kes() to Defining custom validation callbacks for tag/attribute values in wp_kses()

@enrico.sorcinelli
2 years ago

I just updated the patch to the current trunk.

#2 @enrico.sorcinelli
2 years ago

I just updated the patch to the current trunk.

@enrico.sorcinelli
2 years ago

I just updated the patch to the current trunk.

Note: See TracTickets for help on using tickets.