From 73ebc7660c647e2834f32817adf9eab25251b02e Mon Sep 17 00:00:00 2001 From: Joe Dolson Date: Fri, 3 Feb 2023 22:23:19 +0000 Subject: [PATCH] Media: Hide 'view' link if empty string passed to attachment_link. Fix empty href attribute on 'View' link when the `attachment_link` filter is used to hide attachment pages. Props oh_hello, iqbalrony. Fixes #54824. git-svn-id: https://develop.svn.wordpress.org/trunk@55218 602fd350-edb4-49c9-b593-d223f7449a82 --- .../includes/class-wp-media-list-table.php | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/wp-admin/includes/class-wp-media-list-table.php b/src/wp-admin/includes/class-wp-media-list-table.php index fec8d717a2..1943a5966f 100644 --- a/src/wp-admin/includes/class-wp-media-list-table.php +++ b/src/wp-admin/includes/class-wp-media-list-table.php @@ -768,13 +768,15 @@ class WP_Media_List_Table extends WP_List_Table { } } - $actions['view'] = sprintf( - '%s', - get_permalink( $post->ID ), - /* translators: %s: Attachment title. */ - esc_attr( sprintf( __( 'View “%s”' ), $att_title ) ), - __( 'View' ) - ); + if ( get_permalink( $post->ID ) ) { + $actions['view'] = sprintf( + '%s', + get_permalink( $post->ID ), + /* translators: %s: Attachment title. */ + esc_attr( sprintf( __( 'View “%s”' ), $att_title ) ), + __( 'View' ) + ); + } if ( current_user_can( 'edit_post', $post->ID ) ) { $actions['attach'] = sprintf( @@ -829,13 +831,15 @@ class WP_Media_List_Table extends WP_List_Table { } if ( ! $this->is_trash ) { - $actions['view'] = sprintf( - '%s', - get_permalink( $post->ID ), - /* translators: %s: Attachment title. */ - esc_attr( sprintf( __( 'View “%s”' ), $att_title ) ), - __( 'View' ) - ); + if ( get_permalink( $post->ID ) ) { + $actions['view'] = sprintf( + '%s', + get_permalink( $post->ID ), + /* translators: %s: Attachment title. */ + esc_attr( sprintf( __( 'View “%s”' ), $att_title ) ), + __( 'View' ) + ); + } $actions['copy'] = sprintf( '',