WordPress.org

Make WordPress Core

Opened 3 months ago

Closed 8 weeks ago

#47858 closed defect (bug) (fixed)

Incorrect redirect after deleting a term from a taxonomy of a custom post type

Reported by: johnbillion Owned by: SergeyBiryukov
Milestone: 5.3 Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: has-patch
Focuses: administration Cc:
PR Number:

Description

Given a taxonomy attached to a custom post type, deleting a term from the individual term editing screen redirects the user to the term listing screen without the post_type query var, which is incorrect and means the Posts menu is highlighted.

Steps to reproduce on a site with a taxonomy attached to a custom post type:

  • Navigate to the term listing screen for the taxonomy
  • Click the Edit link below a term
  • Click the Delete link at the bottom of the screen and confirm the prompt

Observe that the URL you're redirected to is missing the post_type query var and that the Posts admin menu is highlighted.

Attachments (2)

47858.diff (684 bytes) - added by donmhico 3 months ago.
47858.2.diff (587 bytes) - added by mukesh27 3 months ago.
Updated patch.

Download all attachments as: .zip

Change History (8)

@donmhico
3 months ago

#1 @donmhico
3 months ago

  • Keywords has-patch added; needs-patch removed

Nice find @johnbillion. I can't believe we've missed this up until now.

In my attached patch, 47858.diff, you'll notice that I removed esc_url() in

wp_redirect( $sendback );

This is because esc_url() will transform & to & which is not what we wanted in our url query args. Also, the base url is defined as $sendback = admin_url( 'edit-tags.php' ); and the url query args are added using add_query_arg() so I think it's safe to remove the esc_url().

#2 @SergeyBiryukov
3 months ago

  • Milestone changed from Awaiting Review to 5.3
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

@mukesh27
3 months ago

Updated patch.

#3 @mukesh27
3 months ago

Updated patch 47858.2.diff with different code change.

@SergeyBiryukov, @donmhico Can you please check it.

#4 @donmhico
3 months ago

@mukesh27 IMHO

if ( 'post' !== get_current_screen()->post_type )

is better than

if ( ! empty( $typenow ) ) 

because the former is easier to understand.

#5 @mukesh27
3 months ago

@donmhico As per $taxnow variable we can access $typenow from parent code.

Check https://github.com/WordPress/WordPress/blob/master/wp-admin/term.php#L15

#6 @johnbillion
8 weeks ago

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

In 46263:

Taxonomy: Redirect to the correct URL after deleting a taxonomy term attached to a post type other than Post.

Props donmhico, mukesh27

Fixes #47858

Note: See TracTickets for help on using tickets.