WordPress.org

Make WordPress Core

Opened 16 months ago

Last modified 9 months ago

#23041 new defect (bug)

Images Don't Become Attached When Inserting a Gallery

Reported by: miqrogroove Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 3.5
Component: Gallery Keywords: has-patch
Focuses: Cc:

Description

Steps to Reproduce:

  1. Go to the "Upload New Media" page (wp-admin/media-new.php)
  2. Upload an image.
  3. Create a new post.
  4. Create an image gallery that includes the newly-uploaded image.
  5. Insert the gallery into the post.
  6. Publish the post.

Expected result: Any "(Unattached)" image(s) should get attached.

Actual result: Images remain "(Unattached)".

Attachments (1)

23041.diff (982 bytes) - added by koopersmith 16 months ago.

Download all attachments as: .zip

Change History (36)

comment:1 nacin16 months ago

  • Component changed from Media to Gallery
  • Milestone changed from Awaiting Review to 3.5.1

When inserting an image into a post, we attach any unattached images. Not entirely convinced of the need at this point, but it seems sane to do the same for a gallery.

comment:2 follow-up: Frumph16 months ago

... use case: Gallery outside of the_content() section of a post., design wise post data on left, gallery in a column on the right, impossible (as far as I know ;/) to do unless images are attached to the gallery of the post.

This is how I was doing it post 3.5, which no longer works (works with previous pre 3.5 attached images though).

		$columns = get_post_meta( $post->ID, 'comic-gallery-columns', true );
		if (empty($columns)) $columns = 5;
		$args = array(
				'id'         => $post->ID,
				'columns'    => $columns,
				'exclude'    => $post_image_id
				);
		$output .= gallery_shortcode($args);

Now that the images are unattached another way to do this now would be to make another custom meta field to contain the ID's that represent the gallery and store them that way

Just a thought.. didn't exactly want to install a overbearing gallery plugin and waste all that processing when I could be using internal core code.

Last edited 16 months ago by Frumph (previous) (diff)

comment:3 in reply to: ↑ 2 ; follow-up: nacin16 months ago

Replying to Frumph:

... use case: Gallery outside of the_content() section of a post., design wise post data on left, gallery in a column on the right, impossible (as far as I know ;/) to do unless images are attached to the gallery of the post.

My question is, why are the images unattached to begin with? If they are uploaded to the post, they'll be "attached" automatically. That's all you need to do in 3.5, and that's all you could do in 3.4. So I'm curious what workflow worked in 3.4 that no longer works in 3.5. The process was so strict in 3.4 (the images needed to be uploaded to the post) that nothing should have broken.

comment:4 follow-up: Frumph16 months ago

.. Ah, workflow

Creating new post. Create a Gallery. Select which images to use for the gallery. Only options are to "cancel and go back" or "insert into post". Both of those do not attach those images to the gallery (as I would expect), one just enters the shortcode into the post and the other one apparently just cancels what you just did.

Previous version of WordPress retained what images were assigned to the gallery for that post, this one doesn't, or is not. NEW images are attaching themselves to the post yes. But unable to select older images and have it retained.

.. also can't sort order the images added to the post either now - guess those are based off the ids="" string that gets added to the shortcode put into the post.

Last edited 16 months ago by Frumph (previous) (diff)

comment:5 in reply to: ↑ 4 miqrogroove16 months ago

Replying to Frumph:

Previous version of WordPress retained what images were assigned to the gallery for that post, this one doesn't, or is not. NEW images are attaching themselves to the post yes. But unable to select older images and have it retained.

That doesn't seem accurate. Before 3.5 there was no gallery option at all in that situation. You had to attach the images first.

comment:6 Frumph16 months ago

Right, you loaded up the add media button (used to be a * at some point) then you clicked on the media library portion and selected it etc, which added it to the gallery page with the others. (don't remember if they were ones labelled unattached or they were attached to another post at the time)

comment:7 miqrogroove16 months ago

Maybe there needs to be a discussion about going back to showing only attached images on the gallery tab as the default filter. Let authors "insert" anything from the Library tab as an IMG, but restrict what goes into a gallery by default, to save the confusion.

comment:8 philiparthurmoore16 months ago

  • Cc philip@… added

comment:9 in reply to: ↑ 3 obenland16 months ago

Replying to nacin:

My question is, why are the images unattached to begin with? So I'm curious what workflow worked in 3.4 that no longer works in 3.5.

I think it's something that works in 3.5, that did not work before: You can add images to a gallery, that were not uploaded to the post.

While attaching on insert works for previously unattached images, it won't scale for images that are part of multiple galleries, since attachements can only have one parent. See #22960.

comment:10 follow-up: paulwp16 months ago

My apology in advance if I mistaken something, but I think this ticket is invalid and is confusing.

"Image don't become attached when inserting a gallery"

This is normal and expected.

The way gallery(shortcode) works now (WP3.5) doesn't care if the images assign to what posts, it just take the ids and pull them up, this doesn't need images to be able to be attached to multiple parents.

Why do we need to make images in a gallery (WP3.5+) become attached to any post that appears to be using images pulled from other post ?

At least for me, an image should have only 1 parent, because there is no reason for otherwise.

comment:11 in reply to: ↑ 10 ; follow-up: trivum16 months ago

  • Cc trivum added

Why do we need to make images in a gallery (WP3.5+) become attached to any post that appears to be using images pulled from other post ?


I think it's important because, for one, it lets you insert galleries into template files and then update those galleries via the Media Manager. Suppose you had a gallery inserted in multiple spots in your template files. You would need to go back into each template and update the galleries by hand.

The same goes for posts. You could make a gallery and then insert that gallery into multiple posts (let's say 10 different posts). If you wanted to update that gallery the way it is now, you would need to update each of the 10 different posts by hand. If the images were attached to the original gallery, you could just update that one gallery and the rest would be updated automatically. You could also update that gallery with the visual Media Manager (and not the less user-friendly hand-edited shortcode).

I came across this issue when trying to use a gallery id in a shortcode. I outlined it here:

It seems that in 3.5 when you try to insert a gallery into a template file with the gallery id, it no longer works.

Previously, for example, this would work:

<?php echo do_shortcode('[gallery id="123"]'); ?>

Now, however, because the shortcode has been changed to list out the individual images, referring to the gallery as a whole doesn't work anymore.

The advantage of still having a reference to the entire gallery and not individual images in this case is that you can go in and edit the gallery in the visual editor without digging back into the template code. Just update the gallery as you like, and it's updated everywhere you inserted that gallery in your template files.

Does anyone know if this is just a glitch, or is this how it will be going forward?

According to this page (which seems to have been updated for 3.5 -- at least partly), referring to the entire gallery should still work.

comment:12 follow-up: miqrogroove16 months ago

To the recent commenters: This ticket is not for attaching an image to multiple posts. Could you please take that debate to a new ticket?

comment:13 in reply to: ↑ 11 paulwp16 months ago

Replying to trivum:

Why do we need to make images in a gallery (WP3.5+) become attached to any post that appears to be using images pulled from other post ?

I think it's important because, for one, it lets you insert galleries into template files and then update those galleries via the Media Manager.


Please take a look here
http://core.trac.wordpress.org/browser/tags/3.5/wp-includes/media.php#L671

The id attribute, along with include, exclude, are still there in WP3.5

If it doesn't work, there must be a bug or something else going on.
Whatever it is, I can't see it has anything to do with this ticket. #22960 is what you need.

comment:14 in reply to: ↑ 12 ; follow-up: paulwp16 months ago

Replying to miqrogroove:

Expected result: Any "(Unattached)" image(s) should get attached.

This ticket is asking for the ability to have multiple parents (for an image), if this is not the case, then please close this ticket and focus on #22960 instead.

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

Replying to paulwp:

Replying to miqrogroove:

Expected result: Any "(Unattached)" image(s) should get attached.

This ticket is asking for the ability to have multiple parents (for an image)

No, it's not. It's saying that, on gallery creation, any images that currently do not have a parent should be assigned one. Images with an existing parent would be untouched.

comment:16 follow-up: paulwp16 months ago

Before WP3.5 there is "insert into post" that automatically assign the unattached image to become attached to whatever post (or page) that it is being inserted to.

This ability is still there in WP3.5 ( I just tested, it works).

Upload an image via Media so that it's unattached, once uploaded see the "Attached to" column (in WP3.5 the text changed to "Uploaded to") it is now saying "(unattached)" with the clickable link underneath saying "Attach" that invites you to attach it to any post of your choice, now keep this page open, then make a new post and click "Add Media" select images then click "insert into post" now go back to refresh the Media Library page, you will see it now become attached to that post.

The ability to attach the unattached image has been there and is still there. Users upload images directly thru the Media Library so that it is not attached and they can decide (with intention) to attach them later thru "insert into post" or thru Media Library page.

Let's not forget this is a ticket for WP3.5 onward. There is no need to add this ability into gallery, it will defeat the purpose of having multiple galleries regardless of its parents.

comment:17 in reply to: ↑ 16 ; follow-up: miqrogroove16 months ago

Replying to paulwp:

Let's not forget this is a ticket for WP3.5 onward. There is no need to add this ability into gallery, it will defeat the purpose of having multiple galleries regardless of its parents.

Honestly, the way this new Media UI is designed, I don't think most users can tell the difference between an attachment and a gallery. Or for that matter, the difference between uploading to Add Media vs. uploading to Upload New Media. The differences are confusing.

There is a problem for users who still expect a relationship between images and posts. If images are showing up in a post but don't have the correct parent/child permalinks or paging links or post parent API then that is a regression from 3.4. Inserting a gallery should not leave images totally orphaned.

comment:18 in reply to: ↑ 17 paulwp16 months ago

Replying to miqrogroove:


Honestly, the way this new Media UI is designed, I don't think most users can tell the difference between an attachment and a gallery. Or for that matter, the difference between uploading to Add Media vs. uploading to Upload New Media. The differences are confusing.

Yes Sir, ditto, we all have been thru that.


There is a problem for users who still expect a relationship between images and posts. If images are showing up in a post but don't have the correct parent/child permalinks or paging links or post parent API then that is a regression from 3.4

I believe this #23044 will fix it, it's marked for 3.6 though.


Inserting a gallery should not leave images totally orphaned.

Inserting (placing) image as a single or several img tag(s) OR having a WP's gallery in the post doesn't necessary mean that you want those images attached to that post.

comment:19 follow-up: paulwp16 months ago

I personally see attachment in WP the same way it is in email's attachment.

If you upload file thru a post (or an email) then it's attached to that particular post (or email) because it's your intention to do so, but if you upload it thru skydrive(hotmail) or gdrive(gmail) then it's unattached by intention, usage is done by pasting links.

If the above makes sense…

then we should remove the ability to auto attach the unattached when "insert into post" (and do not add this ability to gallery). Also, the "insert into post" should be renamed to "paste into post" or "place into post" because that's what it actually is.

Users upload images directly via Media Library because they want them unattached and if decide later, the attach business can be done directly via Media Library as well. (this is doable then and still doable now - even in bulk)

comment:20 in reply to: ↑ 19 miqrogroove16 months ago

Yeah, I have to disagree. I don't believe in creating a "right" place and a "wrong" place to upload images. It would confuse the hell out of me.

koopersmith16 months ago

comment:21 koopersmith16 months ago

23041.diff changes "create gallery" and "add to gallery" tabs to use the settings for "uploaded to this post" in their default libraries.

comment:22 nacin16 months ago

I think I am +1 on 23041.diff for 3.5.1. We can sidestep the enhancement (attach unattached images when adding them to a gallery) and attempt a slight correction in the user workflow.

comment:23 nacin16 months ago

  • Keywords has-patch added

comment:24 follow-up: nacin16 months ago

Say you have no images attached to this post and you go create a gallery, with "Uploaded to this post" being the default. It would give you an upload window. I am not sure if that is expected behavior, or weird behavior. Probably both. Closest to expected would be to only use "Uploaded to this post" as the default if there were already such images.

comment:25 in reply to: ↑ 24 nacin16 months ago

Replying to nacin:

Say you have no images attached to this post and you go create a gallery, with "Uploaded to this post" being the default. It would give you an upload window. I am not sure if that is expected behavior, or weird behavior. Probably both. Closest to expected would be to only use "Uploaded to this post" as the default if there were already such images.

Which is not easy to do and seems to indicate that it is time to punt.

comment:27 jond3r16 months ago

  • Cc jond3r@… added

My two cents: I think it is valuable to be able to view a gallery one image at a time using the attachment page, and navigating using next_ and previous_image_link(), which in its current implementation requires the same post parent on all images.

Hopefully this can be solved reliably later via #22960, #23044 and others.

In the meantime the original proposal in this ticket would offer an improvement. I was thinking along two ways of solving this. Either via a new AJAX call when the gallery is inserted or possible better (and simpler?) when the post is updated, by parsing the content for gallery ids. The latter way could be implemented as a plugin, if desired.

Setting "Uploaded to this post" as default as in attachment:23041.diff is better than nothing. Even better would be a possibility to disable the (All) "Images" option (by a theme/plugin), which is really the option that causes all trouble. - But this would exclude unattached images, which is not ideal, so these should be possible to include in some way, which is probably not easy to come up with at this time...

Version 0, edited 16 months ago by jond3r (next)

comment:28 markjaquith16 months ago

+1 on punting for 3.5.x

comment:29 nacin16 months ago

  • Milestone changed from 3.5.1 to 3.6

comment:30 greenshady16 months ago

  • Cc justin@… added

comment:32 follow-up: Frumph11 months ago

Let's see if I can articulate what I am thinking is erm, not necessarily wrong, but method of utilization.

As you know I create comic sites for people; recently made comic easel which is a plugin that uses the media library. When people upload comics to their custom post type it's attached as a featured image. Previous to the 3.? whatever, attachments were associated to the post via the post ID, so I could let people who wanted multiple comics per day attach them into the gallery and they would attach to the post id. So I would search for all of the attachments on that post ID and then loop display them, there is multiple images for that post.

Now however, I can still do that; unfortunately the media UI doesn't show all of the images that are attached to the current post, it shows them all. So the end user cannot see the images that they attached to the post and modify the gallery for that post since .. really there isn't a way to do it anymore. Once the media library changed; that UI functionality is gone. The 'core' backend function is still there though; so the attached-to-the-post-images still get displayed; just no way to work it with the UI.

comment:33 in reply to: ↑ 32 SergeyBiryukov11 months ago

Replying to Frumph:

unfortunately the media UI doesn't show all of the images that are attached to the current post, it shows them all.

It does, just select "Uploaded to this post" in the dropdown filter.

comment:34 Frumph11 months ago

Holy $#!+ there it is! Going to have to write up good documentation for my end users on that one; that's not easily found.

comment:35 nacin9 months ago

  • Milestone changed from 3.6 to Future Release

Six months and I haven't seen much in the way of clamoring for 23041.diff, nor particularly loud or numerous complaints. At this point, it's possibly a degraded behavior change (or, certainly, a change in what people may have gotten used to after 3.5) — and needs user testing. Time to punt.

Note: See TracTickets for help on using tickets.