Make WordPress Core

Opened 10 years ago

Closed 8 years ago

#29237 closed enhancement (maybelater)

Add Link Size Parameter to Gallery Shortcode

Reported by: cliffseal's profile cliffseal Owned by: drewapicture's profile DrewAPicture
Milestone: Priority: normal
Severity: normal Version: 3.9.2
Component: Gallery Keywords: dev-feedback needs-patch
Focuses: Cc:

Description

You can't currently choose what image size that each gallery image should _link to_ without some filtering hackery. This allows a linksize parameter to be passed in the shortcode.

If this works, we could easily add it as a parameter in the modal when "Link to" is set to "Media File".

Attachments (4)

gallery-link-size.diff (1.3 KB) - added by cliffseal 10 years ago.
29237.diff (1.9 KB) - added by iamfriendly 9 years ago.
Refreshed the patch and added docs
29237.2.diff (2.1 KB) - added by iamfriendly 9 years ago.
Added the @since doc string to reflect when the linksize attribute was added
29237.3.diff (5.7 KB) - added by iamfriendly 9 years ago.
Changed the name of the attribute to linked_image_size to better self-document

Download all attachments as: .zip

Change History (15)

#1 @cliffseal
10 years ago

  • Keywords has-patch dev-feedback added

#2 @antpb
9 years ago

  • Keywords needs-refresh needs-docs added; has-patch removed

Patch needs a refresh after #22400 because of
if ( ! empty( $link ) && 'file' === $link )
changing to if ( ! empty( $atts['link'] ) && 'file' === $atts['link'] )

Most $link calls have been wrapped in the $atts variable now.

Will also need docs for shortcode addition linksize.

@iamfriendly
9 years ago

Refreshed the patch and added docs

#3 @iamfriendly
9 years ago

  • Keywords needs-refresh needs-docs removed

Patch has now been refreshed and added additional docs

@iamfriendly
9 years ago

Added the @since doc string to reflect when the linksize attribute was added

#4 @iamfriendly
9 years ago

Missed the @since doc string to reflect when the linksize attribute was added. Added in 29237.2.diff

#5 @DrewAPicture
9 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 4.4
  • Owner set to DrewAPicture
  • Status changed from new to reviewing

@iamfriendly: One last request: Can you rename the new argument to 'linked_image_size'? Let's self-document a little more clearly :)

@iamfriendly
9 years ago

Changed the name of the attribute to linked_image_size to better self-document

#6 @iamfriendly
9 years ago

@DrewAPicture You got it.

Updated the patch with the changed parameter name

#7 @DrewAPicture
9 years ago

  • Keywords needs-patch added; has-patch removed

The more I look at this, the less I like the idea of introducing a new attribute. I think the one good viable option would be to allow the link attribute to accept an image size. Passing 'full' would be the same as passing 'file', but that would be OK.

Also, the original patch over complicated generating the link. Pretty much all we'd have to do is handle the empty and none possibilities, then fall back to the image sizes.

For example:

<?php
if ( ! empty( $atts['link'] ) ) {
        if ( 'none' === $attr['link'] ) {
                $image_output = wp_get_attachment_image( $id, $attr['size'], false, $attr );
        } else {
                $size = 'file' === $attr['link'] ? 'full' : $attr['link'];
                $image_output = wp_get_attachment_link( $id, $size, false, false, false, $attr );
        }
} else {
        // $attr['link'] is empty, so just use $attr['size'].
        $image_output = wp_get_attachment_link( $id, $attr['size'], true, false, false, $attr );
}
Last edited 9 years ago by DrewAPicture (previous) (diff)

#8 @DrewAPicture
9 years ago

  • Milestone changed from 4.4 to Awaiting Review

#9 follow-up: @cliffseal
9 years ago

@DrewAPicture That seems doable. Would we still create an additional UI element to choose media size, or would image choices be integrated into the existing dropdown?

#10 in reply to: ↑ 9 @DrewAPicture
9 years ago

Replying to cliffseal:

@DrewAPicture That seems doable. Would we still create an additional UI element to choose media size, or would image choices be integrated into the existing dropdown?

This is kind of the sticking point. There's already an option to choose an image size for the gallery display, and adding a second option while trying to clearly express the difference would be pretty likely to cause confusion.

In reality, this seems like a cool ability, but also pretty edge. My recommendation would be initially added support only for the attribute to accept an image size and handle outputting the correct links.

Of course, the attributes are also already filterable via the shortcode_atts_gallery hook, so it could be done programmatically as well.

If a plugin or theme wanted to extend that functionality into the Gallery UI, the print_media_template hook makes it possible to add a Backbone template. Jetpack uses that hook to add a "Type" drop-down for their Carousel module, for instance.

#11 @DrewAPicture
8 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to maybelater
  • Status changed from reviewing to closed

Moving this to maybelater.

Note: See TracTickets for help on using tickets.