From 00f3ebdfa171bea4836c887ab191f832c4e868bc Mon Sep 17 00:00:00 2001 From: Shreyas Ikhar Date: Fri, 8 May 2026 15:36:57 +0530 Subject: [PATCH 1/3] Enhance attachment handling: Use attachment file URL when pages are disabled and update media templates accordingly. Co-authored-by: Copilot --- src/wp-admin/includes/post.php | 6 ++++- src/wp-includes/media-template.php | 9 +++++++ tests/phpunit/tests/admin/includesPost.php | 17 +++++++++++++ tests/phpunit/tests/media.php | 28 ++++++++++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php index 8d52c1487a7a5..54d64f9a3a04f 100644 --- a/src/wp-admin/includes/post.php +++ b/src/wp-admin/includes/post.php @@ -1570,7 +1570,11 @@ function get_sample_permalink_html( $post, $new_title = null, $new_slug = null ) $preview_target = " target='wp-preview-{$post->ID}'"; } else { if ( 'publish' === $post->post_status || 'attachment' === $post->post_type ) { - $view_link = get_permalink( $post ); + if ( 'attachment' === $post->post_type && ! get_option( 'wp_attachment_pages_enabled' ) ) { + $view_link = wp_get_attachment_url( $post->ID ); + } else { + $view_link = get_permalink( $post ); + } } else { // Allow non-published (private, future) to be viewed at a pretty permalink, in case $post->post_name is set. $view_link = str_replace( array( '%pagename%', '%postname%' ), $post->post_name, $permalink ); diff --git a/src/wp-includes/media-template.php b/src/wp-includes/media-template.php index 5fb6b5d894d9b..1b40e76e880ee 100644 --- a/src/wp-includes/media-template.php +++ b/src/wp-includes/media-template.php @@ -822,6 +822,7 @@ function wp_print_media_templates() { +