WordPress.org

Make WordPress Core

Opened 5 years ago

Last modified 12 months ago

#29276 new enhancement

Ability to edit and preview any revision, not just autosaves

Reported by: coolmann Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.9.2
Component: Revisions Keywords: needs-patch
Focuses: ui, administration Cc:
PR Number:

Description (last modified by SergeyBiryukov)

It would be great if the revision management functionality could include a way to preview any revision. From a quick look at the source code, wp-includes/revision.php declares a function called

_set_preview($post)

By default it loads the most recent autosave with:

$preview = wp_get_post_autosave($post->ID);

I would like to propose that that line be changed into:

$preview = !empty($_GET['preview_id'])?get_post($_GET['preview_id']):wp_get_post_autosave($post->ID);

The nonce has already been verified in _show_post_preview(), so there should be no security implications of this change.

With this change, the Revisions meta box (Edit Post screen) could display a "preview" icon/link that includes the appropriate nonce and does the same thing as the main "Preview" button.

Attachments (1)

revision.diff (164 bytes) - added by coolmann 5 years ago.
Updated code to preview ANY revision, not just autosaves.

Download all attachments as: .zip

Change History (9)

@coolmann
5 years ago

Updated code to preview ANY revision, not just autosaves.

#1 follow-up: @adamsilverstein
5 years ago

  • Keywords needs-patch added

Coolman,

This is a great idea and something I agree we need to implement in core - the ability to preview any revision.

Your patch does indeed allow the preview_id to be used to pull the proper revision record for previewing (and seemed so hopefully simple), unfortunately this isn't a complete solution for several reasons and will need more work before it can actually be implemented:

  • the preview nonce is id based, it can only be used to preview the specific post id for whcich it was created - see the nonce check in _show_post_preview. see source
  • post meta is currently not revisioned, so if the post display is tied in any way to a post meta value, the preview will be incorrect - for example changing the template (see #20564)
  • even after adding your change and bypassing the nonce for testing, the is_preview test fails in get_posts see source

I didn't dig deeper yet to investigate why is_preview isn't set (bypassing that DID allow me to preview a revision), however the nonce and meta issues need to resolved before we can consider even allowing users to preview revisions: consider the case where a post was private for several revisions, then made public, or where some meta value changes what is visible on the page.

Thanks for bringing up the point and creating a patch! I welcome your further contributions and would love to see this feature make it into the next WordPress release! A good start would be figuring out how to pass nonces for all revision ids, and how to have is_preview set properly when previewing a revision.

Related: #11049, #20299, #20564

#2 in reply to: ↑ 1 ; follow-up: @coolmann
5 years ago

I figured that it was too good to be true. Calculating the nonce for each revision is not that complicated, though. All the postmeta stuff, however, is indeed a big deal. My main purpose was to see if WP was interested in moving forward with this feature. If this is the case, I can continue my research and see what can be done. Thank you!

#3 in reply to: ↑ 2 ; follow-up: @adamsilverstein
5 years ago

coolman,

Check the latest patch on #20299 - it may help move towards a more complete solution here... it allows previewing of the autosaved meta, allowing you to preview a post without publishing the post meta.

Any help testing or your feedback appreciated!

Replying to coolmann:

I figured that it was too good to be true. Calculating the nonce for each revision is not that complicated, though. All the postmeta stuff, however, is indeed a big deal. My main purpose was to see if WP was interested in moving forward with this feature. If this is the case, I can continue my research and see what can be done. Thank you!

Last edited 5 years ago by SergeyBiryukov (previous) (diff)

#4 in reply to: ↑ 3 ; follow-up: @coolmann
5 years ago

Adam, this is great news. Our goal would be to implement a workflow where editors can create a new revision of an existing published post, and then edit it and preview it (and allow other editors to preview it, if needed) without affecting what's currently live on the site. Then, once they're ready to go live with the new version of that page, they just hit "Publish" on that Edit Revision screen and... voilà ;) The workaround we currently use is to "clone" a published post and its postmeta and then "merge" (overwrite) all the fields, when the editor is ready to publish the new version. If this was available in core, WordPress would be one step closer to become a full-fledged CMS.

Replying to adamsilverstein:

coolman,

Check the latest patch on https://core.trac.wordpress.org/ticket/20299 - it may help move towards a more complete solution here... it allows previewing of the autosaved meta, allowing you to preview a post without publishing the post meta.

Any help testing or your feedback appreciated!

Last edited 5 years ago by coolmann (previous) (diff)

#5 in reply to: ↑ 4 ; follow-up: @adamsilverstein
5 years ago

coolman - you may want to try the latest patch on #23314 "Allow published posts to be revised without being updated immediately", this may fill your needs and testing it out and giving your feedback would help get this make progress.

Replying to coolmann:

Adam, this is great news. Our goal would be to implement a workflow where editors can create a new revision of an existing published post, and then edit it and preview it (and allow other editors to preview it, if needed) without affecting what's currently live on the site. Then, once they're ready to go live with the new version of that page, they just hit "Publish" on that Edit Revision screen and... voilà ;) The workaround we currently use is to "clone" a published post and its postmeta and then "merge" (overwrite) all the fields, when the editor is ready to publish the new version. If this was available in core, WordPress would be one step closer to become a full-fledged CMS.

Replying to adamsilverstein:

coolman,

Check the latest patch on https://core.trac.wordpress.org/ticket/20299 - it may help move towards a more complete solution here... it allows previewing of the autosaved meta, allowing you to preview a post without publishing the post meta.

Any help testing or your feedback appreciated!

#6 in reply to: ↑ 5 @coolmann
5 years ago

Thank you, Adam, much appreciated. I'll be experimenting with it in the next few days and report back!

Replying to adamsilverstein:

coolman - you may want to try the latest patch on #23314 "Allow published posts to be revised without being updated immediately", this may fill your needs and testing it out and giving your feedback would help get this make progress.

#7 @SergeyBiryukov
5 years ago

  • Description modified (diff)

This ticket was mentioned in Slack in #core by coolmann. View the logs.


12 months ago

Note: See TracTickets for help on using tickets.