WordPress.org

Make WordPress Core

Opened 20 months ago

Closed 17 months ago

Last modified 17 months ago

#21776 closed task (blessed) (fixed)

Integrate featured images with new media workflow

Reported by: koopersmith Owned by: koopersmith
Milestone: 3.5 Priority: normal
Severity: normal Version: 3.5
Component: Media Keywords: has-patch needs-testing
Focuses: Cc:

Description

Fairly self-explanatory. I'd like featured images to be one of the first workflows integrated, as it is one of the simplest.

Attached is a patch that mirrors the current workflow (but does not remove/alter the code). It is certainly not perfect; I'd like to build up some methods to make a few of these tasks simpler. Moving forward, I also plan on adding a dropzone directly to the featured image metabox. This may turn out to be a common pattern (as we use a similar UI in the customizer), in which case we should consider abstracting it.

Attachments (10)

21776.diff (6.9 KB) - added by koopersmith 20 months ago.
21776.2.diff (6.0 KB) - added by koopersmith 20 months ago.
21776.non-image.png (18.7 KB) - added by SergeyBiryukov 20 months ago.
21776.3.diff (4.2 KB) - added by nacin 17 months ago.
21776.4.diff (3.6 KB) - added by nacin 17 months ago.
21776.5.diff (5.6 KB) - added by nacin 17 months ago.
21776.6.diff (18.6 KB) - added by koopersmith 17 months ago.
21776.7.diff (21.2 KB) - added by koopersmith 17 months ago.
21776.7-refresh.diff (21.2 KB) - added by DrewAPicture 17 months ago.
refresh at r22973
21776.galleries.diff (1.0 KB) - added by koopersmith 17 months ago.

Download all attachments as: .zip

Change History (58)

koopersmith20 months ago

comment:2 scribu20 months ago

  • Cc scribu added

comment:3 nacin20 months ago

I think a different Ajax endpoint is preferred due to the change in return values, but we'll probably want to keep the existing meta box, and simply replace the contents of post_thumbnail_meta_box(). This is mainly to keep consistency with a plugin that might replace or remove that box.

We might want to just do a ?return=json and keep the same endpoint.

koopersmith20 months ago

comment:4 koopersmith20 months ago

21776.2.diff replaces the AJAX endpoint with code in edit_post(), as the thumbnail should update when the publish/update button is clicked (rather than instantly). It does not, however merge the meta box functions.

comment:5 nacin20 months ago

Marked #17100 and #12922 as duplicates, as 21776.2.diff would no longer save the thumbnail instantly, instead requiring a save.

comment:6 koopersmith20 months ago

Marked #14762 as a duplicate, as 21776.2.diff eliminates the ambiguity between choosing a featured image and inserting an image into a post.

comment:7 koopersmith20 months ago

In [21770]:

First pass at integrating featured images with the new media workflow.

Updates the featured image when the publish/update button is clicked (rather than instantly). Uses the existing post_thumbnail_meta_box() function. Does not remove the old featured image meta box JS, ajax handler, or CSS.

see #21776, #21390.

comment:3 koopersmith20 months ago

In [21771]:

Prevent JS events from being garbage collected when a media.view.Modal is re-rendered. see #21390, #21776.

comment:4 SergeyBiryukov20 months ago

Non-images should be filtered out when selecting a featured image: 21776.non-image.png.

comment:5 dosboy19 months ago

When adding a featured image with the current codebase, the lightbox appears, throws a JS error, then fails to let me do anything.

Uncaught ReferenceError: type is not defined
(anonymous function)
b.template.c load-scripts.php:423
_.extend.template load-scripts.php:466
e.view.Attachment.Backbone.View.extend.render load-scripts.php:468
e.view.Attachments.Backbone.View.extend.add load-scripts.php:468
e.view.Attachments.Backbone.View.extend.initialize.list load-scripts.php:468
g.Events.trigger load-scripts.php:435
f.extend._onModelEvent load-scripts.php:450
g.Events.trigger load-scripts.php:435
f.extend.add load-scripts.php:445
media.model.Attachments.Backbone.Collection.extend._mirrorAdd load-scripts.php:466
g.Events.trigger load-scripts.php:435
f.extend._onModelEvent load-scripts.php:450
g.Events.trigger load-scripts.php:435
f.extend.add load-scripts.php:445
f.extend.fetch.a.success load-scripts.php:449
p.Callbacks.k load-scripts.php:2
p.Callbacks.l.fireWith load-scripts.php:2
_.extend.ajax load-scripts.php:466
p.Callbacks.k load-scripts.php:2
p.Callbacks.l.fireWith load-scripts.php:2
y load-scripts.php:2
p.support.ajax.p.ajaxTransport.send.d load-scripts.php:2

comment:6 dosboy19 months ago

Ignore previous error report. It seems to be resolved as of this morning.

comment:7 koopersmith19 months ago

In [22021]:

Media JS: Add support for filtering Attachment collections by mime type. see #21390, #21776, #21809.

comment:18 koopersmith19 months ago

In [22022]:

Limit the featured image workflow to images only.

Adds the ability to set the values used to instantiate both the Workflow's library and selection.
Renames the Workflows internal _pending variable to prevent conflicts with a similarly named internal Backbone.Model variable.

see #21390, #21776.

comment:19 koopersmith19 months ago

In [22044]:

Media JS: Move the modal box's title from being stored in the modal view to being stored as an attribute on the workflow. Update modal titles for both the post media and featured image workflows. see #21390, #21776.

comment:21 ocean9019 months ago

Featured images are attached to the post in 3.4, in trunk this behavior is gone.

comment:22 scribu19 months ago

If I understood it correctly, we are de-emphasising the post_parent field for attachments, in the sense that it now only keeps a record of which post you were on when you originally uploaded the image.

comment:23 nacin19 months ago

If the featured image is uploaded against that post, then it will be attached to the post. Otherwise, it won't be. Pretty sure that's the same behavior in 3.4 too.

comment:24 in reply to: ↑ 20 TomAuger19 months ago

Replying to ocean90:

See http://wordpress.org/support/topic/post-feature-image-bug-in-wordpress-35-beta-1

I can confirm this behaviour. It should be noted that selecting an _already uploaded_ image WILL correctly update the featured image.

comment:25 koopersmith19 months ago

In [22175]:

Media Modal: Only automatically select uploading attachments when in a workflow that supports multiple images.

Fixes a bug in featured images where uploading an image would force you to reopen the modal (as the modal would close on upload).

see #21390, #21776.

comment:26 follow-up: DrewAPicture18 months ago

  • Cc xoodrew@… added

Does this ticket cover actually setting the Featured image from the modal after upload? After a post in the alpha/beta forum I realized this isn't currently possible.

comment:27 koopersmith18 months ago

In 22321:

Add a sidebar to the media modal.

  • Adds wp.media.view.Sidebar, to aid in rendering the sidebar.
  • Removes the directions from the Attachments view and shifts search into a separate view (wp.mce.view.Search) that can be relocated at will. This also serves to simplify the Attachments view by removing the nested list and $list parameters.
  • Show the toolbar on the featured image workflow, effectively requiring confirmation before closing the dialog.

see #21390, #21776, #21808.

comment:28 follow-up: georgestephanis18 months ago

Current status in trunk looks like a minor regression from a couple days ago. A couple days ago (Monday?), when clicking "Choose a Featured Image" the button was initially labeled appropriately as "Set As Featured Image" -- however in current trunk, that button is no longer available -- it starts out as "Set as Featured Image".

Also -- as of Monday's trunk, when changing from "Upload Files" to "Media Library" and back, the button changed verbiage to "Insert into Post" -- rather than "Set as Featured Image".

comment:29 koopersmith18 months ago

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

In 22496:

Media: Update featured images to use the media frame. fixes #21776, see #21390.

comment:30 in reply to: ↑ 28 koopersmith18 months ago

Replying to georgestephanis:

Current status in trunk looks like a minor regression from a couple days ago. A couple days ago (Monday?), when clicking "Choose a Featured Image" the button was initially labeled appropriately as "Set As Featured Image" -- however in current trunk, that button is no longer available -- it starts out as "Set as Featured Image".

Also -- as of Monday's trunk, when changing from "Upload Files" to "Media Library" and back, the button changed verbiage to "Insert into Post" -- rather than "Set as Featured Image".

Yep, featured images got a little out of sync as we shifted around the pieces. Should be all set now.

comment:31 in reply to: ↑ 26 koopersmith18 months ago

Replying to DrewAPicture:

Does this ticket cover actually setting the Featured image from the modal after upload? After a post in the alpha/beta forum I realized this isn't currently possible.


It did, in a way — the original plan for 3.5 was to omit this feature entirely. I think 3.5 has evolved to the point where a "Featured Image" tab might feel at home the "Add Media" modal (as opposed to feeling jammed in, as it previously did). That said, this is something that will have to wait until 3.6 (and should move to a new ticket).

comment:32 koopersmith18 months ago

In 22500:

Media: Make "update featured image" button primary. see #21776, #21390.

comment:33 koopersmith18 months ago

In 22561:

Media: Activate the featured image toolbar when the media dialog is first opened. see #21390, #21776.

comment:34 nacin17 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

I think 3.5 has evolved to the point where a "Featured Image" tab might feel at home the "Add Media" modal (as opposed to feeling jammed in, as it previously did).

After quite a bit of feedback from the WordPress.com support forums, it seems the lack of a button here has put a severe cramp in many people's workflows. We should aim to work something in.

comment:35 nacin17 months ago

If there is anything we can do in the process to greatly simplify the JS in the post thumbnail meta box, that would be good, because plugins are inevitably going to copy it. Right now it has no semblance of being an API, unfortunately.

Related: #22636, restoring an old filter. Might be worth re-tying the rendering back into an ajax request like send-attachment-to-editor.

comment:36 ryan17 months ago

Based on wordpress.com feedback, it seems that almost no one notices the "Featured Image" metabox.

comment:37 bradyvercher17 months ago

  • Cc brady@… added

nacin17 months ago

nacin17 months ago

nacin17 months ago

koopersmith17 months ago

comment:38 koopersmith17 months ago

attachment:21776.6.diff enables the old featured images meta box, but rigs it up to a new featured image panel in the media modal.

It also:

  • Converts the modal view to use the view manager, which means that a call to open() will automatically call render and attach if necessary.
  • Doesn't automatically set a state in wp.media, to allow code to customize the states to be added before activation.

comment:39 koopersmith17 months ago

  • Keywords has-patch needs-testing added

comment:40 follow-up: DrewAPicture17 months ago

Testing 21776.6.diff:

Initially setting the featured image via both the main and featured image modals works as expected. Beyond that, there are a couple of problems.

  • If you click the 'Remove Featured Image' link via the metabox, the image disappears (as expected) but that leaves the Featured Image metabox empty, e.g. the 'Set Featured image' link isn't restored.
  • Once you've set the Featured image, clicking Add Media opens into the >Featured Image tab instead of >Upload Images
  • If the featured image is already set, you can't always change it. Sometimes the image gets replaced with the new one in the metabox, sometimes the image disappears and the 'set' link is restored, sometimes nothing happens at all.
Last edited 17 months ago by DrewAPicture (previous) (diff)

comment:41 koopersmith17 months ago

Note that this will also fix #22636.

comment:42 in reply to: ↑ 40 ; follow-up: koopersmith17 months ago

Thanks, DrewAPicture, this is all very helpful.

Replying to DrewAPicture:

  • If the featured image is already set, you can't always change it. Sometimes the image gets replaced with the new one in the metabox, sometimes the image disappears and the 'set' link is restored, sometimes nothing happens at all.

Can you elaborate on this point? Any JS errors? Can you isolate any actions that cause the featured image to always update successfully or always break?

comment:43 in reply to: ↑ 42 DrewAPicture17 months ago

Replying to koopersmith:

Replying to DrewAPicture:

  • If the featured image is already set, you can't always change it. Sometimes the image gets replaced with the new one in the metabox, sometimes the image disappears and the 'set' link is restored, sometimes nothing happens at all.

Can you elaborate on this point? Any JS errors? Can you isolate any actions that cause the featured image to always update successfully or always break?

Per my revelation in IRC, seems like replacing the featured image via Add Media works as expected, replacing via clicking the already-set featured image in the metabox doesn't work.

I also noticed that if I click the "Remove featured image" link and attempt to set a new one via Add Media, it doesn't load anything in the metabox, but that may be related to the first bullet point in comment:40.

koopersmith17 months ago

comment:44 follow-up: koopersmith17 months ago

This patch should fix all 3 issues.

comment:45 nacin17 months ago

#22636 was marked as a duplicate.

DrewAPicture17 months ago

refresh at r22973

comment:46 in reply to: ↑ 44 DrewAPicture17 months ago

Replying to koopersmith:

This patch should fix all 3 issues.

21776.7-refresh.diff fixes all three for me.

comment:47 koopersmith17 months ago

Thanks for the refresh. Looks good.

comment:48 DrewAPicture17 months ago

Noticed two issues testing 21776.7-refresh with QuickPress:

  • Once you've selected a featured image and clicked the 'Set Featured image' button, you're sent to wp-admin/index.php# which jumps you to the bottom of the page forcing you to scroll back up.
Last edited 17 months ago by DrewAPicture (previous) (diff)

comment:49 nacin17 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 22979:

Bring Featured Images back into the main media dialog.

Most users don't realize that the Featured Image meta box exists; if they do, few use it.

Restores the old meta box UI, including the admin_post_thumbnail_html filter. If a plugin is using _wp_post_thumbnail_html() in conjunction with Thickbox elsewhere, it will also magically still work.

Specific underlying changes:

  • Converts the modal view to use the view manager, which means that a call to open() will automatically call render and attach if necessary.
  • Doesn't automatically set a state in wp.media, to allow code to customize the states to be added before activation.

props koopersmith.
fixes #21776.

comment:50 koopersmith17 months ago

Patch updates gallery editing to work with the modal changes. Also adds nice handling for default states.

comment:52 ryan17 months ago

In 22984:

Update gallery editing to work with the modal changes. Add nice handling for default states.

Props koopersmith
see #21776

comment:53 nacin17 months ago

In 23058:

Admin ajax: Roll back new-style error sending in set-post-thumbnail. The JS handlers know to parse an unrecognized response (like -1 or 0) as a failure. see #21776. see #22750.

Note: See TracTickets for help on using tickets.