WordPress.org

Make WordPress Core

Opened 15 months ago

Closed 12 months ago

Last modified 12 months ago

#23298 closed defect (bug) (fixed)

Initial gallery 'Link to' setting not applied

Reported by: pokes Owned by: ryan
Milestone: 3.5.2 Priority: normal
Severity: normal Version: 3.5.1
Component: Gallery Keywords: has-patch commit
Focuses: Cc:

Description (last modified by SergeyBiryukov)

When inserting a new gallery in a post, the setting shown in the 'Link to' dropdown of the gallery settings is not applied. Changing the setting (even straight back to what it showed) causes it to be applied.

To demonstrate/reproduce:

  1. New Post.
  2. Add Media.
  3. Create Gallery.
  4. Create a New Gallery.
  5. Under Gallery Settings observe but don't touch the 'Link to' setting.
  6. Insert Gallery.
  7. Resulting gallery shortcode has no link=file or link=post regardless of the 'Link to' setting.

Attachments (3)

1-25-2013 6-53-34 PM.png (17.4 KB) - added by CBarrett123 15 months ago.
Link to Media File
1-25-2013 7-40-50 PM.png (15.2 KB) - added by CBarrett123 15 months ago.
Link to Attachment
23298.patch (1015 bytes) - added by SergeyBiryukov 15 months ago.

Download all attachments as: .zip

Change History (46)

CBarrett12315 months ago

Link to Media File

CBarrett12315 months ago

Link to Attachment

comment:1 CBarrett12315 months ago

I can confirm the bug reported by Pokes using Twelve Eleven with no plugins active.
If you generate a new Gallery using either freshly uploaded images, or existing images previously uploaded, and set the link to "Media File", it's dropping the link="file" rom teh shortcode. You end up with [gallery ids="1,2,3,4"].

During the Gallery generation step, or when editing the gallery after saving, if you toggle from link to "Media File" to link to "Attachment Page" and then back to link to "Media File", now the correct short code of [gallery link="file" ids="1,2,3,4"] is generated.

Cheers!

comment:2 nacin15 months ago

  • Milestone changed from Awaiting Review to 3.5.2

Is this in 3.5.1?

comment:3 pokes15 months ago

  • Cc pokes added

Yes, in 3.5.1

comment:4 SergeyBiryukov15 months ago

  • Description modified (diff)

SergeyBiryukov15 months ago

comment:5 SergeyBiryukov15 months ago

23298.patch makes "Attachment Page" the default value, since it's actually the default behaviour of gallery_shortcode(), and declares it as such in wp.media.gallery.defaults.

We should probably also explicitly declare it in gallery_shortcode() defaults.

Last edited 15 months ago by SergeyBiryukov (previous) (diff)

comment:6 follow-ups: nacin15 months ago

Is this a problem in 3.5.0? I imagine not, then?

comment:7 in reply to: ↑ 6 ; follow-up: DrewAPicture15 months ago

Replying to nacin:

Is this a problem in 3.5.0? I imagine not, then?

I can reproduce the bug on 3.5. It defaults to no link attribute without deliberately switching the option first.

  • Create gallery, leave as 'Attachment Page', get [gallery ids="1,2,3"]
  • Edit gallery, change to 'Image Link', get [gallery link="file" ids="1,2,3"]
  • Edit gallery again, change to 'Attachment Page', get [gallery link="post" ids="1,2,3]

@SergeyBiryukov: 23298.patch doesn't apply cleanly as the media-template.php additions are already in place in both 3.5 and 3.5.1

comment:8 DrewAPicture15 months ago

I should mention that if the dropdown value isn't changed by say, a user setting, to the last-used setting, it's not as big of a deal because absent a link attribute, gallery images default to attachment page links anyway.

comment:9 in reply to: ↑ 6 SergeyBiryukov15 months ago

  • Keywords needs-patch added

Replying to nacin:

Is this a problem in 3.5.0? I imagine not, then?

The symptoms in 3.5.0 and 3.5.1 are different.

In 3.5.0, the (minor) issue is just that the default value (link="post") is not always removed from the shortcode as it should per [22715], since it's not explicitly declared in wp.media.gallery.defaults.

In 3.5.1, the (bigger) issue is that the default value (link="file") is not respected, unless you toggle the dropdown from "Media File" to "Attachment Page" and back. This was introduced in [23262].

Now I see that linking to media files as the default was intentional in [23262]. 23298.patch reverts that, so I guess a new patch is needed.

comment:10 in reply to: ↑ 7 SergeyBiryukov15 months ago

Replying to DrewAPicture:

23298.patch doesn't apply cleanly as the media-template.php additions are already in place in both 3.5 and 3.5.1

Only in 3.5, see the changes in [23262].

comment:11 follow-up: danix115 months ago

I can also confirm problem in my installation of wordpress 3.5.1. It's odd, that when I select "Attachment Page" and than select back "Media File", the link="file" attribute is inserted well. But when I leave default "Media File" selected, it doesn't work. It seems, that there is same where missing default attribute in js, to insert link="file".

comment:12 nacin15 months ago

  • Version changed from 3.5 to 3.5.1

[23262] may have been done in error for galleries. The default for images is linking to the file; the default for galleries is linking to the attachment page. I didn't catch the latter, making [23262] a bit overzealous (which I realized, and is why I immediately questioned 3.5 versus 3.5.1 behavior). 23298.patch is therefore probably the correct fix.

comment:13 SergeyBiryukov15 months ago

  • Keywords has-patch added; needs-patch removed

comment:14 follow-ups: helgatheviking15 months ago

Probably isn't the place, but you should be able to have a link="none" where the gallery images don't link anywhere.

comment:15 in reply to: ↑ 14 krembo9915 months ago

Replying to helgatheviking:

Probably isn't the place, but you should be able to have a link="none" where the gallery images don't link anywhere.

I agree . and it is probably not the right place either , but while already meddling with the code , should´t there be also a "custom URL" option at this very same place ?

comment:16 follow-up: helgatheviking15 months ago

in the gallery shortcode, if you replace:

$link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);

with

if ( isset($attr['link']) && 'none' == $attr['link'] ) {
	$link = wp_get_attachment_image($id, $size, false, false);
} elseif ( isset($attr['link']) && 'file' == $attr['link'] ) {
	$link = wp_get_attachment_link($id, $size, false, false);
} else {
	$link = wp_get_attachment_link($id, $size, true, false);
}

a non-linking gallery is easily accomplished.

@krembo99 - I think a custom URL would be a lot more difficult to accomplish. Does every image link to the custom URL? Or does each image have a custom URL?

comment:17 helen15 months ago

#23390 was marked as a duplicate.

comment:18 in reply to: ↑ 16 krembo9914 months ago

  • Cc krembo99 added

Replying to helgatheviking:


@krembo99 - I think a custom URL would be a lot more difficult to accomplish. Does every image link to the custom URL? Or does each image have a custom URL?

When one uploads an image , there is already a custom URL option "Allows you to set a custom link URL for your inserted image to link to when clicked".

This option however , even when set upon upload, is not available when using said image in a gallery shortcode. IMHO it should be . It will allow a much desired flexibility to the gallery shortcode (just imagine a "posts gallery" ).
But like I mentioned before , it might not be the right place to mention it , and it might require a new enhancement ticket.
(This option is possibly achieved with some plugin / core modifications seen for example HERE)

Last edited 14 months ago by krembo99 (previous) (diff)

comment:19 in reply to: ↑ 14 ; follow-up: SergeyBiryukov14 months ago

Replying to helgatheviking:

Probably isn't the place, but you should be able to have a link="none" where the gallery images don't link anywhere.

Related: #18178

comment:20 in reply to: ↑ 19 ; follow-up: helgatheviking14 months ago

Replying to SergeyBiryukov:

Replying to helgatheviking:

Probably isn't the place, but you should be able to have a link="none" where the gallery images don't link anywhere.

Related: #18178

How do you do that!? I even posted on the other ticket and couldn't find it again. Then, I can't find anything in trac.

comment:21 helgatheviking14 months ago

@krembo - I don't think that link URL is saved anywhere, so you can't use it in the gallery shortcode.

Back to the initial ticket, I can confirm this on 3.5.1 as well.

comment:22 helgatheviking14 months ago

  • Cc helgatheviking@… added

comment:23 in reply to: ↑ 20 DrewAPicture14 months ago

Replying to helgatheviking:

How do you do that!? I even posted on the other ticket and couldn't find it again. Then, I can't find anything in trac.

Google site search is your friend :)

site:core.trac.wordpress.org search terms

comment:24 glrss14 months ago

  • Cc glrss added

I've noticed the same thing with 3.5.1 on installations I manage and also on WordPress.com.

comment:25 pthomson8714 months ago

  • Cc pthomson87 added

comment:26 in reply to: ↑ 11 pthomson8714 months ago

Hey Guys/Gals,

I'm still a little confused as to how I can set link="file" as the default value for galleries? I have no use for the link to attachments for single images or galleries.

Does anybody know how best to achieve this?

Thanks in advance,
Paul

Replying to danix1:

I can also confirm problem in my installation of wordpress 3.5.1. It's odd, that when I select "Attachment Page" and than select back "Media File", the link="file" attribute is inserted well. But when I leave default "Media File" selected, it doesn't work. It seems, that there is same where missing default attribute in js, to insert link="file".

comment:27 SergeyBiryukov14 months ago

  • Keywords commit added

comment:28 follow-up: manyakabi14 months ago

I agree with you. It's very annoying bug. The bug is still there. That's unbelievable, they don't distribute the new version. I think it's end of the WordPress.

comment:29 pthomson8714 months ago

Commit added? - Does this mean that the patch is being added for WP 3.5.2 release? It doesn't seem like it's fully resolved and likely be raised again in next release?

Not better to nip it in the bud now?

comment:30 desrosj14 months ago

  • Cc desrosj@… added

comment:31 manyakabi14 months ago

  • Cc manyakabi added

comment:32 xavivars14 months ago

  • Cc xavi.ivars@… added

comment:33 greenshady14 months ago

  • Cc justin@… added

comment:34 mordauk13 months ago

  • Cc pippin@… added

comment:35 in reply to: ↑ 28 ghost122713 months ago

Replying to manyakabi:

I agree with you. It's very annoying bug. The bug is still there. That's unbelievable, they don't distribute the new version. I think it's end of the WordPress.

Seriously? WordPress is a massive project that is provided for your use free of charge. Bugs are constantly reported, features are suggested, and tweaks made to make your use of the platform easier... and you're going to say it's the end of WordPress because of something this inconsequential? Now, I have no direct affiliation with WordPress... in fact, I've yet to submit a patch to core, but this is just silly.

Be thankful that people are willing to dedicate the time and energy to this product to keep it alive. Be thankful that you are being given a solution that is as flexible and extensible as WordPress is for free. Give back to the community through finding bugs, suggesting features, or making otherwise useful comments. Dig into the forums if you have experience with plugins or themes... you'd be surprised how simple some questions are even for a regular user to answer. Dig into the bugtracker if you're a dev... every little bit of development support helps. If you don't think you're competent enough to do either of those things, then start off by reading this and leaving a word of encouragement or thanks to your favorite developer, or a random one, or the community as a whole.

tl;dr: Seriously? Don't complain about a free product that has a minor bug in it. It'll get fixed. Contribute if you can.

</endrant>

comment:36 spaceda13 months ago

if you do not need image to be linked to page you can use it: (found at support pages):

If you want to force the link to be directly to the image itself, go to around line 762-ish
where this code appears...

$link = isset($attr['link']) && 'file' == $attr['link'] ?
wp_get_attachment_link($id, $size, false, false) :
wp_get_attachment_link($id, $size, true, false);

Change it to just this...

$link = wp_get_attachment_link($id, $size, false, false);

You should get direct links to the big image after that.

regs

Last edited 13 months ago by spaceda (previous) (diff)

comment:37 SergeyBiryukov12 months ago

#24053 was marked as a duplicate.

comment:38 DaganLev12 months ago

  • Cc DaganLev added

comment:39 SergeyBiryukov12 months ago

#24086 was marked as a duplicate.

comment:40 ryan12 months ago

23298.patch seems to fix it for me.

comment:41 ryan12 months ago

Patch seem fine for trunk and the 3.5 branch. SergeyBiryukov, do you want to refresh anything with the patch?

comment:42 ryan12 months ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In 24161:

Respect the link to setting when inserting a gallery.

Props SergeyBiryukov
fixes #23298

comment:43 ryan12 months ago

In 24162:

Respect the link to setting when inserting a gallery.

Props SergeyBiryukov
fixes #23298 for 3.5

Note: See TracTickets for help on using tickets.