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

Commit

Permalink
Merge pull request #138 from xwp/fix/publishing-settings-from-admin
Browse files Browse the repository at this point in the history
Account for action=editpost in workaround to set customize_save action during changeset publishing
  • Loading branch information
westonruter authored Jul 16, 2017
2 parents dc978f9 + 15f0a13 commit 0f92f0d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
15 changes: 13 additions & 2 deletions php/class-post-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,15 @@ public function save( array $args ) {
*/
protected $is_pretending_customize_save_ajax_action = false;

/**
* Previous value for $_REQUEST['action'].
*
* @link https://core.trac.wordpress.org/ticket/39221#comment:14
*
* @var string
*/
protected $previous_request_action_param;

/**
* Start pretending customize_save Ajax action.
*
Expand All @@ -618,10 +627,12 @@ public function save( array $args ) {
*/
function start_pretending_customize_save_ajax_action( $new_status, $old_status, $changeset_post ) {
$is_publishing_changeset = ( 'customize_changeset' === $changeset_post->post_type && 'publish' === $new_status && 'publish' !== $old_status );
if ( ! $is_publishing_changeset || isset( $_REQUEST['action'] ) ) {
$is_customize_save_action = ( isset( $_REQUEST['action'] ) && 'customize_save' === $_REQUEST['action'] );
if ( ! $is_publishing_changeset || $is_customize_save_action ) {
return;
}
$this->is_pretending_customize_save_ajax_action = true;
$this->previous_request_action_param = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : null;
add_filter( 'wp_doing_ajax', '__return_true' );
$_REQUEST['action'] = 'customize_save';
}
Expand All @@ -644,7 +655,7 @@ function finish_pretending_customize_save_ajax_action( $new_status, $old_status,
return;
}
remove_filter( 'wp_doing_ajax', '__return_true' );
unset( $_REQUEST['action'] );
$_REQUEST['action'] = $this->previous_request_action_param;
$this->is_pretending_customize_save_ajax_action = false;
}

Expand Down
1 change: 1 addition & 0 deletions tests/php/test-class-post-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ function test_pretending_customize_save_ajax_action() {
$this->markTestSkipped( 'Only relevant to WordPress 4.7 and greater.' );
}

$_REQUEST['action'] = 'editpost';
set_current_screen( 'edit' );
$this->assertTrue( is_admin() );
$post_type = $this->get_new_post_type_instance( $this->plugin->customize_snapshot_manager );
Expand Down

0 comments on commit 0f92f0d

Please sign in to comment.