-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
57893 row action media table #4364
Conversation
__( 'Copy URL' ), | ||
__( 'Copied!' ) | ||
); | ||
if ( ! $this->is_trash && wp_get_attachment_url( $post->ID ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know the aim is to keep each action in its own separate condition block, but I'm thinking we can reduce the calls to wp_get_attachment_url()
here.
$attachment_url = wp_get_attachment_url( $post->ID );
if ( $attachment_url ) {
if ( ! $this->is_trash ) {
$actions['copy'] = sprintf(
'<span class="copy-to-clipboard-container"><button type="button" class="button-link copy-attachment-url media-library" data-clipboard-text="%s" aria-label="%s">%s</button><span class="success hidden" aria-hidden="true">%s</span></span>',
esc_url( $attachment_url ),
/* translators: %s: Attachment title. */
esc_attr( sprintf( __( 'Copy “%s” URL to clipboard' ), $att_title ) ),
__( 'Copy URL' ),
__( 'Copied!' )
);
}
$actions['download'] = sprintf(
'<a href="%s" aria-label="%s" download>%s</a>',
esc_url( $attachment_url ),
/* translators: %s: Attachment title. */
esc_attr( sprintf( __( 'Download “%s”' ), $att_title ) ),
__( 'Download file' )
);
}
What do you think @kebbet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While it's reducing calls to wp_get_attachment_url()
it nests two action in one conditional check. I don't like the look of it, but my opinion on that is just opinonated. Reduced number of calls is better I guess.
if ( ! $this->is_trash && get_permalink( $post->ID ) ) { | ||
$actions['view'] = sprintf( | ||
'<a href="%s" aria-label="%s" rel="bookmark">%s</a>', | ||
get_permalink( $post->ID ), | ||
/* translators: %s: Attachment title. */ | ||
esc_attr( sprintf( __( 'View “%s”' ), $att_title ) ), | ||
__( 'View' ) | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can reduce the number of calls to get_permalink()
here too:
if ( ! $this->is_trash && get_permalink( $post->ID ) ) { | |
$actions['view'] = sprintf( | |
'<a href="%s" aria-label="%s" rel="bookmark">%s</a>', | |
get_permalink( $post->ID ), | |
/* translators: %s: Attachment title. */ | |
esc_attr( sprintf( __( 'View “%s”' ), $att_title ) ), | |
__( 'View' ) | |
); | |
} | |
if ( ! $this->is_trash ) { | |
$permalink = get_permalink( $post->ID ); | |
if ( $permalink ) { | |
$actions['view'] = sprintf( | |
'<a href="%s" aria-label="%s" rel="bookmark">%s</a>', | |
$permalink, | |
/* translators: %s: Attachment title. */ | |
esc_attr( sprintf( __( 'View “%s”' ), $att_title ) ), | |
__( 'View' ) | |
); | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh also, shouldn't the permalink be passed through esc_url()
? It isn't current escaped in trunk
though 🤔.
@SergeyBiryukov What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the permalink could be escaped through esc_url()
. Do you think get_edit_post_link()
and wp_nonce_url()
should be escaped with it too, the pattern exists in core/trunk. Any directions what to do here Sergey?
https://core.trac.wordpress.org/ticket/57893