Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#40575 closed defect (bug) (fixed)

Typo in wp_kses_allowed_html()

Reported by: henrywright's profile henry.wright Owned by: drewapicture's profile DrewAPicture
Milestone: 4.9 Priority: normal
Severity: normal Version: 4.7.4
Component: Formatting Keywords: has-patch
Focuses: Cc:

Description

There's a typo in the first occurrence of the wp_kses_allowed_html filter inside wp_kses_allowed_html(). The 2nd arg in the call to apply_filters() should read $tags, not $context.

This may confuse users of the filter.

Attachments (3)

40575.patch (1.6 KB) - added by ketuchetan 8 years ago.
40575-2.patch (944 bytes) - added by bor0 8 years ago.
40575-3.patch (1.4 KB) - added by bor0 8 years ago.

Download all attachments as: .zip

Change History (13)

@ketuchetan
8 years ago

#1 @ketuchetan
8 years ago

  • Keywords has-patch added
  • Version set to 4.7.4

Made the typo correction.

#2 @henry.wright
8 years ago

@ketuchetan thanks for 40575.patch but it's not quite right. Even though I said $tags in the ticket description, it's not the variable to use. $allowedposttags and $allowedtags both hold "allowed HTML" at the point the filter runs.

#3 @SergeyBiryukov
8 years ago

  • Component changed from General to Formatting
  • Keywords needs-patch added; has-patch removed

Introduced in [21790], docs added in [27739].

Given that this instance of the filter is only applied if is_array( $context ) and provides explicit as the actual context, the usage appears to be correct, it just needs to be documented better.

The function docs should mention that $context itself can be an array of allowed tags.

#4 @SergeyBiryukov
8 years ago

  • Milestone changed from Awaiting Review to 4.8

#5 @henry.wright
8 years ago

@SergeyBiryukov agreed. If the argument passed to wp_kses_allowed_html() is an array, the filter in question will run and $context will be that passed array. It's worth making it clear in the inline docs for the filter that the array won't actually be "context" data, instead it'll be "allowed tags" data.

Of course, in the wild, what is passed to wp_kses_allowed_html() can be anything, but I'm basing the above on what the function is intended to accept (described in the function signature and inline docs):

 * @param string $context The context for which to retrieve tags.
 *                        Allowed values are post, strip, data,entities, or
 *                        the name of a field filter such as pre_user_description.
 * @return array List of allowed tags and their allowed attributes.
 */
function wp_kses_allowed_html( $context = '' ) {

This ticket was mentioned in Slack in #core by obenland. View the logs.


8 years ago

#7 @obenland
8 years ago

  • Milestone changed from 4.8 to Future Release

@bor0
8 years ago

#8 @bor0
8 years ago

  • Keywords has-patch added; needs-patch removed

@bor0
8 years ago

#9 @DrewAPicture
8 years ago

  • Milestone changed from Future Release to 4.9

@bor0 Thanks for the patches!

#10 @DrewAPicture
8 years ago

  • Owner set to DrewAPicture
  • Resolution set to fixed
  • Status changed from new to closed

In 40950:

Docs: Adjust notation for the $context parameter in the DocBlocks for the wp_kses_allowed_html() function and its associated wp_kses_allowed_html filter.

$context|$allowedtags can be either a string or array.

Props bor0.
Fixes #40575.

Note: See TracTickets for help on using tickets.