This repository has been archived by the owner on Dec 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Ensure that revisions get created when changesets are updated via explicit saves #111
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e5aea6a
Ensure that revisions get created when changesets are updated via exp…
westonruter 66b6bb0
Use add_action instead of add_filter
westonruter 00f7ad9
Toggle date control for future status
mohdsayed d62a8ae
Seperate edit control's date and title observable values
mohdsayed 6233030
Misc code improvements.
mohdsayed d4752ca
Allow title to update without date in non future status
mohdsayed 93ad522
Merge branch 'bugfix/create-revisions' of github.com:xwp/wp-customize…
mohdsayed 4b69f1f
Remove customize_changeset_status param only if auto save is triggere…
mohdsayed d3166d4
Add condition to check if original data has customize_changeset_statu…
mohdsayed 7913f93
Fix AYS showing on page load
mohdsayed a268785
Fix AYS supress condition.
mohdsayed 383787c
Prevent case of JS error on 4.6 when statusButton doesn't exist
westonruter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,8 @@ function hooks() { | |
add_action( 'admin_bar_menu', array( $this, 'remove_all_non_snapshot_admin_bar_links' ), 100000 ); | ||
add_action( 'wp_before_admin_bar_render', array( $this, 'print_admin_bar_styles' ) ); | ||
add_filter( 'removable_query_args', array( $this, 'filter_removable_query_args' ) ); | ||
add_filter( 'wp_save_post_revision_post_has_changed', array( $this, '_filter_revision_post_has_changed' ), 20, 3 ); | ||
add_filter( 'save_post_customize_changeset', array( $this, 'create_initial_changeset_revision' ) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @westonruter I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right! It should be |
||
add_filter( 'wp_insert_post_data', array( $this, 'prepare_snapshot_post_content_for_publish' ) ); | ||
} | ||
|
||
|
@@ -342,6 +344,37 @@ public function snapshot() { | |
return $this->snapshot; | ||
} | ||
|
||
/** | ||
* Create initial changeset revision. | ||
* | ||
* This should be removed once #30854 is resolved. | ||
* | ||
* @link https://core.trac.wordpress.org/ticket/30854 | ||
*/ | ||
public function create_initial_changeset_revision( $post_id ) { | ||
if ( 0 === count( wp_get_post_revisions( $post_id ) ) ) { | ||
wp_save_post_revision( $post_id ); | ||
} | ||
} | ||
|
||
/** | ||
* When a customize_save Ajax action is being made, ensure a revision is allowed if customize_snapshots_create_revision query param is present. | ||
* | ||
* @see \WP_Customize_Manager::_filter_revision_post_has_changed() | ||
* | ||
* @param bool $post_has_changed Whether the post has changed. | ||
* @param \WP_Post $last_revision The last revision post object. | ||
* @param \WP_Post $post The post object. | ||
* @return bool Whether a revision should be made. | ||
*/ | ||
public function _filter_revision_post_has_changed( $post_has_changed, $last_revision, $post ) { | ||
unset( $last_revision ); | ||
if ( 'customize_changeset' === $post->post_type && ! empty( $_POST['customize_snapshots_create_revision'] ) ) { | ||
$post_has_changed = true; | ||
} | ||
return $post_has_changed; | ||
} | ||
|
||
/** | ||
* Prepare snapshot post content for publishing. | ||
* | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the
customize_changeset_status
param getting removed, again? Is this still needed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we are checking
customize_snapshots_create_revision
customize_changeset_status
does not need to be removed now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sayedtaqui but core will (somewhat unintuitively) create a new revision every time the
customize_changeset_status
is supplied. Wasn't there a reason for the param to be removed? Did it have something to do with passing the date?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@westonruter Yes we wanted to auto save the date and title in editbox, but we could not do
wp.customize.previewer.save()
without status because the default status ispublish
, and we did not want to create revision each time it auto saves the date/title.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so then we need to still include the logic for removing the status parameter, but then an additional change is needed right? We need to omit the request for a revision when the date and title are modified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes, thats correct.