From b5da3803340400a038c0bf22399101c558d0f7f0 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Mon, 19 Jun 2023 23:20:21 +0000 Subject: [PATCH] Media: Redirect deprecated `wp-admin/media.php` file. Redirect users visiting the `wp-admin/media.php` file to the media library, `wp-admin/upload.php`. An user facing warning is displayed when the media library is reached via a deprecated link. Follow up to [55647]. Props jorbin, audrasjb, azaozz, NekoJonez, kebbet, costdev. Fixes #57612. Built from https://develop.svn.wordpress.org/trunk@55943 git-svn-id: http://core.svn.wordpress.org/trunk@55455 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/media.php | 25 ++++++++++++++++++++++++- wp-admin/upload.php | 10 +++++++++- wp-includes/media-template.php | 5 +++++ wp-includes/version.php | 2 +- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/wp-admin/media.php b/wp-admin/media.php index abfc056351..5b7ac353c6 100644 --- a/wp-admin/media.php +++ b/wp-admin/media.php @@ -9,4 +9,27 @@ * @subpackage Administration */ -_deprecated_file( basename( __FILE__ ), '6.3.0', 'wp-admin/upload.php' ); +/** Load WordPress Administration Bootstrap. */ +require_once __DIR__ . '/admin.php'; + +$parent_file = 'upload.php'; +$submenu_file = 'upload.php'; + +wp_reset_vars( array( 'action' ) ); + +switch ( $action ) { + case 'editattachment': + case 'edit': + if ( empty( $_GET['attachment_id'] ) ) { + wp_redirect( admin_url( 'upload.php?error=deprecated' ) ); + exit; + } + $att_id = (int) $_GET['attachment_id']; + + wp_redirect( admin_url( "upload.php?item={$att_id}&error=deprecated" ) ); + exit; + + default: + wp_redirect( admin_url( 'upload.php?error=deprecated' ) ); + exit; +} diff --git a/wp-admin/upload.php b/wp-admin/upload.php index 52f5be8b4b..08c6241107 100644 --- a/wp-admin/upload.php +++ b/wp-admin/upload.php @@ -141,7 +141,15 @@ if ( 'grid' === $mode ) { wp_enqueue_script( 'media-grid' ); wp_enqueue_script( 'media' ); - remove_action( 'admin_head', 'wp_admin_canonical_url' ); + // Remove the error parameter added by deprecation of wp-admin/media.php. + add_filter( + 'removable_query_args', + function() { + return array( 'error' ); + }, + 10, + 0 + ); $q = $_GET; // Let JS handle this. diff --git a/wp-includes/media-template.php b/wp-includes/media-template.php index 3207d48a06..6bb31a7bb0 100644 --- a/wp-includes/media-template.php +++ b/wp-includes/media-template.php @@ -373,6 +373,11 @@ function wp_print_media_templates() {