WordPress.org

Make WordPress Core

Opened 9 months ago

Last modified 9 months ago

#24865 new enhancement

Allow plugins to hook into autosave and include field data from the autosave with the package.

Reported by: nerrad Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Autosave Keywords: has-patch dev-feedback
Focuses: Cc:

Description

Why?

Autosaves currently only save "blessed" data (post_title and post_description?). Plugin authors may want to add their own data in the autosave package so if they hook into save_post they can handle/save that data as needed.

How this works

Metaboxes are generated with an id already on the page. So what we do is add an extra parameter to the add_meta_box() function (do_autosave bool) so that when a plugin uses add_meta_box() they can set that flag.

We set a javascript object that contains the ids of the metaboxes that have had that flag set and then wp.autosave.getPostData in autosave.js has been modified to loop through the metaboxes matching those ids and return the fields in those metaboxes as an object attached to the data param.

Added a new jquery plugin (serializefullarray) as it will handle nested pseudo arrays set as the "name" values in inputs (i.e. somedata[one][two]) and create proper objects from them.

Attachments (3)

TestMetaBoxAutosave.zip (1.2 KB) - added by nerrad 9 months ago.
For testing plugins adding their data to autosaves
jquery.serializefullarray.js (1.5 KB) - added by nerrad 9 months ago.
serializefullarray library
24865-full.diff (4.3 KB) - added by nerrad 9 months ago.
add in functionality for plugin metaboxes to add their data to the autosave package

Download all attachments as: .zip

Change History (13)

comment:1 nerrad9 months ago

at #wcsf contributor day south-side 4th table.

nerrad9 months ago

For testing plugins adding their data to autosaves

comment:2 nerrad9 months ago

oh and this is based off of trunk

comment:3 brianhogg9 months ago

Looks pretty clean except for the console.log(), would be nice to get this included!

comment:4 nerrad9 months ago

dang of course I missed that console.log I noticed something in one of the comment docs too. Gonna put up a fix for both in a couple minutes

comment:5 nerrad9 months ago

patch updated to remove console.log() and fix comment doc

nerrad9 months ago

serializefullarray library

comment:6 nerrad9 months ago

didn't realize the patch didn't include the jquery serializefullarray library. As far as I can tell there are no restricting licenses on that library. It's very handy for parsing form data that is referenced via nested associated array into js objects.

comment:7 DrewAPicture9 months ago

  • Component changed from Administration to Autosave
  • Keywords dev-feedback added

comment:8 azaozz9 months ago

Good idea. Before that autosave would need a more general "overhaul". It should use heartbeat for transport, parts of it haven't been used in ages, other parts need updating. For example: saving tags, may need to JSON encode the form data, differences when autosaving a draft and a published post, etc.

comment:9 nerrad9 months ago

Would an overhaul be needed before this gets added though? Imo this could be added and plugins can interact now. The impact of future changes would be minimal because the object containing the metabox ids could just be carried forward...

Last edited 9 months ago by nerrad (previous) (diff)

nerrad9 months ago

add in functionality for plugin metaboxes to add their data to the autosave package

comment:10 nerrad9 months ago

just modified the patch cause I realized I got a couple var names wrong.

Note: See TracTickets for help on using tickets.