Skip to content

Commit 4a807b3

Browse files
committed
KSES: Conditionally remove the <form> element from $allowedposttags.
To avoid backwards compatibility issues, `<form>` is re-added if a custom filter has added the `<input>` or `<select>` elements to `$allowedposttags`. Merges [43994] to the 4.9 branch. git-svn-id: https://develop.svn.wordpress.org/branches/4.9@43997 602fd350-edb4-49c9-b593-d223f7449a82
1 parent ff58a69 commit 4a807b3

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/wp-includes/kses.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,6 @@
184184
'lang' => true,
185185
'xml:lang' => true,
186186
),
187-
'form' => array(
188-
'action' => true,
189-
'accept' => true,
190-
'accept-charset' => true,
191-
'enctype' => true,
192-
'method' => true,
193-
'name' => true,
194-
'target' => true,
195-
),
196187
'h1' => array(
197188
'align' => true,
198189
),
@@ -610,6 +601,7 @@ function wp_kses_one_attr( $string, $element ) {
610601
* Return a list of allowed tags and attributes for a given context.
611602
*
612603
* @since 3.5.0
604+
* @since 5.0.1 `form` removed as allowable HTML tag.
613605
*
614606
* @global array $allowedposttags
615607
* @global array $allowedtags
@@ -638,7 +630,27 @@ function wp_kses_allowed_html( $context = '' ) {
638630
switch ( $context ) {
639631
case 'post':
640632
/** This filter is documented in wp-includes/kses.php */
641-
return apply_filters( 'wp_kses_allowed_html', $allowedposttags, $context );
633+
$tags = apply_filters( 'wp_kses_allowed_html', $allowedposttags, $context );
634+
635+
// 5.0.1 removed the `<form>` tag, allow it if a filter is allowing it's sub-elements `<input>` or `<select>`.
636+
if ( ! CUSTOM_TAGS && ! isset( $tags['form'] ) && ( isset( $tags['input'] ) || isset( $tags['select'] ) ) ) {
637+
$tags = $allowedposttags;
638+
639+
$tags['form'] = array(
640+
'action' => true,
641+
'accept' => true,
642+
'accept-charset' => true,
643+
'enctype' => true,
644+
'method' => true,
645+
'name' => true,
646+
'target' => true,
647+
);
648+
649+
/** This filter is documented in wp-includes/kses.php */
650+
$tags = apply_filters( 'wp_kses_allowed_html', $tags, $context );
651+
}
652+
653+
return $tags;
642654

643655
case 'user_description':
644656
case 'pre_user_description':

0 commit comments

Comments
 (0)