[wp-trac] [WordPress Trac] #47745: get_term will send back term_id as string if $filter = 'edit'. Use of 'edit' causes issues with hooks in edit-tag-form passing a non-conforming WP_Term object as $tag

WordPress Trac noreply at wordpress.org
Sun Jul 21 00:36:25 UTC 2019


#47745: get_term will send back term_id as string if $filter = 'edit'. Use of
'edit' causes issues with hooks in edit-tag-form passing a non-conforming
WP_Term object as $tag
------------------------------+-----------------------------------------
 Reporter:  majemedia         |      Owner:  (none)
     Type:  defect (bug)      |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  Taxonomy          |    Version:  trunk
 Severity:  normal            |   Keywords:  dev-feedback needs-dev-note
  Focuses:  coding-standards  |
------------------------------+-----------------------------------------
 The file "edit-tag-form.php" contains multiple hooks that pass $tag as an
 argument.

 Within each of these hooks the $tag->term_id type is `string`.

 using this as a test against a vanilla 5.2.2 & trunk site (theme:
 twentynineteen, plugins: none... not even akismet and hello).

 {{{#!php
 add_action( 'edit_category_form_fields', 'test_category_term_id_type' );
 function test_category_term_id_type( $tag ) {
         error_log( gettype( $tag->term_id ) );
 }
 }}}

 `[21-Jul-2019 00:04:41 UTC] string`

 `$tag` is set in `term.php` using `get_term` using the filter `'edit'`

 within the `get_term()` method `$_term` is filtered by `edit` which then
 utilizes `sanitize_term()` which passes the term object through
 `sanitize_term_field` which uses `$context='edit'`.

 Within sanitize_term_field if `$context='edit'` the field is passed
 through `esc_attr()`.

 `esc_attr()` immediately casts the value sent to it to `(string)` and then
 returns it.

 Other places where `edit` is used as a filter in core for `get_term`:

 - `class-wp-terms-list-table.php | column_name()`
 - `taxonomy.php | get_category_to_edit()`

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/47745>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list