Make WordPress Core

Changeset 55218


Ignore:
Timestamp:
02/03/2023 10:23:19 PM (4 years ago)
Author:
joedolson
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-media-list-table.php

    r55198 r55218  
    769769                        }
    770770
    771                         $actions['view'] = sprintf(
    772                                 '<a href="%s" aria-label="%s" rel="bookmark">%s</a>',
    773                                 get_permalink( $post->ID ),
    774                                 /* translators: %s: Attachment title. */
    775                                 esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $att_title ) ),
    776                                 __( 'View' )
    777                         );
     771                        if ( get_permalink( $post->ID ) ) {
     772                                $actions['view'] = sprintf(
     773                                        '<a href="%s" aria-label="%s" rel="bookmark">%s</a>',
     774                                        get_permalink( $post->ID ),
     775                                        /* translators: %s: Attachment title. */
     776                                        esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $att_title ) ),
     777                                        __( 'View' )
     778                                );
     779                        }
    778780
    779781                        if ( current_user_can( 'edit_post', $post->ID ) ) {
     
    830832
    831833                        if ( ! $this->is_trash ) {
    832                                 $actions['view'] = sprintf(
    833                                         '<a href="%s" aria-label="%s" rel="bookmark">%s</a>',
    834                                         get_permalink( $post->ID ),
    835                                         /* translators: %s: Attachment title. */
    836                                         esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $att_title ) ),
    837                                         __( 'View' )
    838                                 );
     834                                if ( get_permalink( $post->ID ) ) {
     835                                        $actions['view'] = sprintf(
     836                                                '<a href="%s" aria-label="%s" rel="bookmark">%s</a>',
     837                                                get_permalink( $post->ID ),
     838                                                /* translators: %s: Attachment title. */
     839                                                esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $att_title ) ),
     840                                                __( 'View' )
     841                                        );
     842                                }
    839843
    840844                                $actions['copy'] = sprintf(
Note: See TracChangeset for help on using the changeset viewer.