Skip to content
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

Closed
wants to merge 15 commits into from

Conversation

kebbet
Copy link

@kebbet kebbet commented Apr 21, 2023

@kebbet kebbet marked this pull request as ready for review April 22, 2023 06:42
__( 'Copy URL' ),
__( 'Copied!' )
);
if ( ! $this->is_trash && wp_get_attachment_url( $post->ID ) ) {
Copy link
Contributor

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 &#8220;%s&#8221; 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 &#8220;%s&#8221;' ), $att_title ) ),
		__( 'Download file' )
	);
}

What do you think @kebbet?

Copy link
Author

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.

Comment on lines +793 to +801
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 &#8220;%s&#8221;' ), $att_title ) ),
__( 'View' )
);
}
Copy link
Contributor

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:

Suggested change
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 &#8220;%s&#8221;' ), $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 &#8220;%s&#8221;' ), $att_title ) ),
__( 'View' )
);
}
}

Copy link
Contributor

@costdev costdev Jun 20, 2023

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?

Copy link
Author

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?

@kebbet kebbet closed this Jun 21, 2023
@kebbet kebbet deleted the 57893-row-action-media-table branch June 21, 2023 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants