Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
Merge 66b6bb0 into 7910d6b
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Feb 10, 2017
2 parents 7910d6b + 66b6bb0 commit f6d2281
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion js/customize-snapshots.js
Expand Up @@ -1083,7 +1083,7 @@
},

/**
* Remove 'customize_changeset_status' if its already set.
* Remove 'customize_changeset_status' if its already set; replace with customize_snapshots_create_revision param.
*
* @return {void}
*/
Expand Down Expand Up @@ -1113,6 +1113,7 @@
isSameStatus = api.state( 'changesetStatus' ).get() === originalOptions.data.customize_changeset_status;
if ( 'customize_save' === originalOptions.data.action && isSameStatus && options.data ) {
options.data = removeParam( options.data, 'customize_changeset_status' );
options.data += '&customize_snapshots_create_revision=1';
}
} );
}
Expand Down
33 changes: 33 additions & 0 deletions php/class-customize-snapshot-manager.php
Expand Up @@ -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_action( 'save_post_customize_changeset', array( $this, 'create_initial_changeset_revision' ) );
add_filter( 'wp_insert_post_data', array( $this, 'prepare_snapshot_post_content_for_publish' ) );
}

Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit f6d2281

Please sign in to comment.