WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#37205 closed defect (bug) (fixed)

Shared term's edit screen is inaccessible

Reported by: dlh Owned by: boonebgorges
Milestone: 4.6 Priority: normal
Severity: normal Version: 4.5
Component: Taxonomy Keywords: has-patch
Focuses: administration Cc:
PR Number:

Description

term.php populates $tag by calling get_term() without a $taxonomy. If the term ID being edited is still shared, then that get_term() call will return an 'ambiguous_term_id' error, which leads to wp_die().

Per ticket:34988#comment:10, term.php assumes there are no shared terms, so this might be an invalid report. I can understand if, by this point, core considers shared terms to be edge cases at most.

Technically, the error message ("You attempted to edit an item that doesn't exist") is also inaccurate. I can't think of a user-friendly description for it, though.

Attachments (1)

37205.2.diff (522 bytes) - added by alleynoah 4 years ago.
Shared term backward compatibility for term.php

Download all attachments as: .zip

Change History (8)

@alleynoah
4 years ago

Shared term backward compatibility for term.php

#1 @alleynoah
4 years ago

  • Keywords has-patch added

I agree with David -- I understand if this feels like a Wile E. Coyote edge case, but it also is a real live production issue on a couple of sites and seems like a pretty harmless backwards compatibility patch.

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


4 years ago

#3 @boonebgorges
4 years ago

  • Owner set to boonebgorges
  • Status changed from new to reviewing

#4 @boonebgorges
4 years ago

  • Keywords dev-feedback added
  • Milestone changed from Awaiting Review to 4.6

Thinking through this issue. $taxnow was removed from the call to get_term() in term.php in [36874]. The commit message suggests that the taxonomy context should be set in WP_Screen, but I don't fully understand how this is the case - get_term() doesn't reference the current screen anywhere.

The fix suggested in 37205.2.diff (which is too verbose - $taxnow falls back on 'post_tag', so is never empty) depends on the ?taxonomy query arg being set when visiting term.php. This is in fact the case when coming from edit-tags.php, which I think is the main path into term.php.

Passing $taxnow into get_term() seems harmless as far as I can see, but I'd like a confirmation from @swissspidy (author of [36874]) before going forward with it.

#5 @swissspidy
4 years ago

  • Keywords dev-feedback removed

Thanks for pinging me!

The commit message suggests that the taxonomy context should be set in WP_Screen, but I don't fully understand how this is the case - get_term() doesn't reference the current screen anywhere.

wp-admin/admin.php calls set_current_screen(), which in turn calls WP_Screen::get(). [36874] made sure that inside that method $taxonomy, $post_type and the screen ID are properly populated.

The fix suggested in 37205.2.diff (which is too verbose - $taxnow falls back on 'post_tag', so is never empty) depends on the ?taxonomy query arg being set when visiting term.php. This is in fact the case when coming from edit-tags.php, which I think is the main path into term.php.

The $taxonomy variable inside WP_Screen::get() falls back to post_tag, but not $taxnow, which is being set in wp-admin/admin.php and defaults to an empty string.

Therefore replacing get_term( $tag_ID, '', OBJECT, 'edit' ); with get_term( $tag_ID, $taxnow, OBJECT, 'edit' ); should be enough. Definitely makes sense to me.

#6 @boonebgorges
4 years ago

Thanks, @swissspidy !

#7 @boonebgorges
4 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 38069:

On term.php, use $taxnow when fetching currently edited term.

[36874] changed the get_term() call so that no $taxonomy parameter
was passed, as 4.4 made the parameter optional. This change made it
impossible to access a shared term that has not yet been splitr, since
passing an ambiguous $term_id to get_term() results in an error.
Restoring the $taxonomy parameter fixes the regression.

Props alleynoah, dlh.
Fixes #37205.

Note: See TracTickets for help on using tickets.