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

Allow snapshot posts to publish and be scheduled #62

Merged
merged 39 commits into from
Jul 27, 2016

Conversation

PatelUtkarsh
Copy link
Member

@PatelUtkarsh PatelUtkarsh commented Jul 20, 2016

This allows snapshot changes to be published, On publish it will save snapshot changes in database.

Fixes #15.

@PatelUtkarsh
Copy link
Member Author

Do we need to check for theme change and change theme before publishing snapshot data and revert back after done? @valendesigns

* @param int $post_id Post id.
* @param \WP_Post $post Post object.
*/
public function publish_snapshot( $post_id, $post ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PatelUtkarsh warning that when doing Publish in the Customizer, any existing snapshot will be transitioned to publish. See:

So it is important that this should short-circuit if did_action( 'customize_save' ), because this would indicate that the customize_save Ajax request is being made.

@westonruter
Copy link
Contributor

@PatelUtkarsh:

Do we need to check for theme change and change theme before publishing snapshot data and revert back after done?

I don't think we need to worry about the theme change. The publish metabox and publish actions should be disabled if the current theme doesn't match the theme associated with the snapshot.

@westonruter
Copy link
Contributor

@PatelUtkarsh the changes here will directly resolve #15. Please refer to the comments there for what other considerations will be needed.

foreach ( $snapshot_values as $setting_id => $setting_params ) {
$this->snapshot_manager->customize_manager->set_post_value( $setting_id, $setting_params );
$this->snapshot_manager->customize_manager->add_setting( $setting_id, $setting_params );
$setting = $this->snapshot_manager->customize_manager->get_setting( $setting_id );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PatelUtkarsh you'll need to make sure that $setting is not null. Also, as noted in #15, you'll need to make sure you do: $setting->capability = 'exist' to ensure that the setting save will always be allowed. This is safe because a setting only be written to the snapshot by a user who has the capability to begin with, so we know at this point it will be safe to save.

@PatelUtkarsh
Copy link
Member Author

@westonruter Which post_status transition should we allow?

any => publish or 
only draft => publish

@westonruter
Copy link
Contributor

@PatelUtkarsh any transition to publish. Particularly, this is key for scheduling snapshots (#15), as it will allow you to create update a snapshot post with a future date and it will have future status. When the future date arrives, WP Cron should transition the post from future to publish and all of the Customizer settings in that post should get saved. (If the theme associated with the snapshot doesn't match the current theme, then we should probably short-circuit and change the status back to pending.)

remove_action( 'customize_save', array( $this->snapshot_manager, 'check_customize_publish_authorization' ), 10 );
/** This action is documented in wp-includes/class-wp-customize-manager.php */
do_action( 'customize_save', $this->snapshot_manager->customize_manager );
add_action( 'customize_save', array( $this, 'check_customize_publish_authorization' ), 10, 0 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the wrong customize_save handler is being re-added. There is no check_customize_publish_authorization method on this class.

I suggest doing:

$action = 'customize_save';
$callback = array( $this->snapshot_manager, 'check_customize_publish_authorization' );
$priority = has_action( $action, $callback );
if ( false !== $priority ) {
    remove_action( $action, $callback, $priority );
}
/** This action is documented in wp-includes/class-wp-customize-manager.php */
do_action( 'customize_save', $this->snapshot_manager->customize_manager );
if ( false !== $priority ) {
    add_action( $action, $callback, $priority );
}

@westonruter
Copy link
Contributor

@PatelUtkarsh this commit may be especially relevant to you, specifically the date_gmt field: 13f8edf

See #63

if ( false !== $priority ) {
remove_action( $action, $callback, $priority );
}
$this->snapshot_manager->customize_manager->doing_ajax( 'customize_save' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doing_ajax method doesn't do anything other than return a bool to say whether this Ajax action is happening. So I don't think this block is doing anything. I'm revising.

* Remove bulk actions filter
* Replace publish filter with transition filter.
* Remove hiding of publish metabox if not current theme. Allow publishing if not current theme.
* Remove hiding of author metabox.
* Remove extraneous info now that publish metabox is restored.
* Move Post_Type logic to Customize_Snapshot_Manager
@westonruter westonruter changed the title [WIP] Allow snapshot to publish Allow snapshot posts to publish Jul 26, 2016
@PatelUtkarsh
Copy link
Member Author

@westonruter In a case of null as setting value before publishing snapshot, it is not showing setting name, and after publishing it shows setting name with an error.
Should we fix this and show null setting name before publishing?

@westonruter westonruter changed the title Allow snapshot posts to publish Allow snapshot posts to publish and be scheduled Jul 27, 2016
@westonruter westonruter merged commit 32c03e9 into feature/refactor Jul 27, 2016
@westonruter westonruter deleted the feature/publish-snapshot branch July 27, 2016 18:23
@westonruter westonruter mentioned this pull request Jul 27, 2016
3 tasks
@westonruter westonruter modified the milestone: 0.5.0 Aug 12, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants