WordPress.org

Make WordPress Core

Opened 4 months ago

Closed 2 months ago

Last modified 2 months ago

#51396 closed defect (bug) (fixed)

[Media upload.php] Switch back from grid to list mode reopen the modal

Reported by: Mista-Flo Owned by: antpb
Milestone: 5.6 Priority: normal
Severity: normal Version: 4.0
Component: Media Keywords: has-patch
Focuses: administration Cc:

Description

Steps to reproduce:

  • Go to the media library in grid mode (wp-admin/upload.php?mode=grid)
  • Click on an item, you should have something like this in the URL : wp-admin/upload.php?item=27&mode=grid
  • Refresh the page
  • Close the modal
  • Switch to list mode
  • Switch back to grid mode
  • The modal is now opened with the previous item

This is due because the URL to switch between modes are generated in PHP src/wp-includes/media-template.php, meaning the URL is set once and do not get updated if there are some dynamic changes in the page.

The code is:

<?php
                <a href="<?php echo esc_url( add_query_arg( 'mode', 'list', $_SERVER['REQUEST_URI'] ) ); ?>" class="view-list">
                        <span class="screen-reader-text"><?php _e( 'List view' ); ?></span>
                </a>
                <a href="<?php echo esc_url( add_query_arg( 'mode', 'grid', $_SERVER['REQUEST_URI'] ) ); ?>" class="view-grid current" aria-current="page">
                        <span class="screen-reader-text"><?php _e( 'Grid view' ); ?></span>
                </a>

So we have to find a better way to handle this I guess, even if it's very edgecase.

I do not know all URL parameters you can have in this page, so I'm not sure about the solution, but I think we can just assume to reset any parameter when switching from one mode to another. If so, then we could stay in PHP and just print the admin_url of upload.php.

Attachments (1)

51396.1.patch (1.1 KB) - added by Mista-Flo 4 months ago.
Fix with PHP

Download all attachments as: .zip

Change History (9)

@Mista-Flo
4 months ago

Fix with PHP

#1 @Mista-Flo
4 months ago

  • Component changed from General to Media
  • Focuses administration added
  • Keywords has-patch added
  • Version changed from trunk to 4.0

This ticket was mentioned in Slack in #core-media by florian-tiar. View the logs.


4 months ago

#3 @mukesh27
4 months ago

Hi there!

51396.1.patch patch working fine for me.

This ticket was mentioned in Slack in #core-media by florian-tiar. View the logs.


4 months ago

This ticket was mentioned in Slack in #core-media by florian-tiar. View the logs.


3 months ago

This ticket was mentioned in Slack in #core-media by antpb. View the logs.


2 months ago

#7 @antpb
2 months ago

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

In 49568:

Media: Allow users to switch from media grid to list mode in media library.

Fixes issue where media modal would open when switching from grid to list mode.

Props mista-flo, mukesh27.

Fixes #51396.

#8 @antpb
2 months ago

  • Milestone changed from Awaiting Review to 5.6
Note: See TracTickets for help on using tickets.