WordPress.org

Make WordPress Core

Opened 23 months ago

Closed 20 months ago

Last modified 5 weeks ago

#32692 closed enhancement (fixed)

Remove removable query vars from certain redirect URLs

Reported by: johnbillion Owned by: johnbillion
Milestone: 4.4 Priority: normal
Severity: minor Version: 4.2
Component: Administration Keywords: good-first-bug has-patch dev-feedback
Focuses: Cc:

Description

Scenario:

  1. Edit a post and hit 'Update' or 'Publish'
  2. Navigate to Appearance -> Customize
  3. Do all the things
  4. Close the Customizer

Note that you are returned to the post editing screen, but the 'Post updated' message persists because the message query var is still present.

#23367 introduced a list of removable query vars which get hidden from the page's URL once the page loads. This list of query vars should be abstracted into its own function so the list can be reused. It can then be used to remove these query vars from the redirect destination URL after closing the Customizer, and maybe also in other situations (logging in?).

My User Switching plugin already does this when switching between users, but it has to implement its own list of removable query vars.

Attachments (4)

32692.patch (2.3 KB) - added by Mte90 22 months ago.
wp_admin_canonical_url with two parameters
32692.2.patch (1.5 KB) - added by Mte90 22 months ago.
correct patch
32692.diff (2.4 KB) - added by swissspidy 22 months ago.
Another approach like in the original suggestion.
32692.2.diff (2.4 KB) - added by swissspidy 20 months ago.

Download all attachments as: .zip

Change History (14)

#1 @Mte90
22 months ago

I'm exploring your plugin i see this:

add_filter( 'removable_query_args',            array( $this, 'filter_removable_query_args' ) );

So filter_removable_query_args return new values in the array and elsewhere is used to add new parameters

add_query_arg( $args, $redirect_to )

to add this parameters.
In wp-admin/customize.php i see two add_query_arg to two different url, home_url and wp_login_url.
Can you help me to find the correct file to edit for fix this bug?

#2 @swissspidy
22 months ago

add_query_arg isn't the problem here.

First, the removable query vars inside wp_admin_canonical_url should be moved to their own function (pretty easy). Then you need to use that function in wp-admin/customize.php, just at the beginning where $return is set.

I will try to create a patch for that at the WordCamp Europe Contributor Day on Sunday.

@Mte90
22 months ago

wp_admin_canonical_url with two parameters

#3 @Mte90
22 months ago

I've changed wp_admin_canonical_url, now have 2 parameters, one for the url to filter and one for print.
In this way i can get the url cleaned in customize.php for $return.

But after your comment i think that a function that wrap wp_admin_canonical_url and to the same thing is better.

@Mte90
22 months ago

correct patch

@swissspidy
22 months ago

Another approach like in the original suggestion.

#4 @swissspidy
22 months ago

  • Keywords has-patch added; needs-patch removed

Oops, wrong file extension, but you'll get the point. My patch introduces a new wp_removable_query_args function.

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


22 months ago

#6 @johnbillion
22 months ago

  • Milestone changed from Awaiting Review to Future Release

32692.diff is exactly what I was thinking.

@swissspidy
20 months ago

#7 @swissspidy
20 months ago

  • Keywords dev-feedback added
  • Milestone changed from Future Release to 4.4

32692.2.diff is an updated patch for trunk. I also simplified the wp_removable_query_args function a bit. IMHO a good candidate for 4.4.

#8 @johnbillion
20 months ago

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

In 33849:

Introduce wp_removable_query_args(), which returns an array of single-use query variables which can be removed from a URL.

Also applies the function to the return URL when the Customizer is closed.

Fixes #32692
Props swissspidy, Mte90

#9 @westonruter
5 weeks ago

In 40313:

Customize: Prevent links to customize.php from being generated which have query vars from wp_removable_query_args() present.

Props dlh.
See #23367, #32692.
Fixes #31850.

#10 @swissspidy
5 weeks ago

In 40331:

Customize: Prevent links to customize.php from being generated which have query vars from wp_removable_query_args() present.

Props dlh.
See #23367, #32692.
Fixes #31850.

Merges [40313] to the 4.7 branch.

Note: See TracTickets for help on using tickets.