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

Commit

Permalink
Merge 17b82dd into 856d135
Browse files Browse the repository at this point in the history
  • Loading branch information
lgedeon committed Aug 22, 2016
2 parents 856d135 + 17b82dd commit a3876ea
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
7 changes: 4 additions & 3 deletions php/class-customize-snapshot.php
Expand Up @@ -294,10 +294,11 @@ public function save( array $args ) {
/**
* Filter the snapshot's data before it's saved to 'post_content'.
*
* @param array $data Customizer snapshot data, with setting IDs mapped to an array
* containing a `value` array item and potentially other metadata.
* @param array $data Customizer snapshot data, with setting IDs mapped to an array
* containing a `value` array item and potentially other metadata.
* @param Customize_Snapshot $this Snapshot object.
*/
$this->data = apply_filters( 'customize_snapshot_save', $this->data );
$this->data = apply_filters( 'customize_snapshot_save', $this->data, $this );

$result = $this->snapshot_manager->post_type->save( array_merge(
$args,
Expand Down
34 changes: 34 additions & 0 deletions tests/php/test-class-customize-snapshot.php
Expand Up @@ -114,6 +114,7 @@ function tearDown() {
$this->wp_customize = null;
unset( $GLOBALS['wp_customize'] );
unset( $GLOBALS['wp_scripts'] );
$this->filtered_snapshot = null;
parent::tearDown();
}

Expand Down Expand Up @@ -323,4 +324,37 @@ function test_saved() {
'data' => array( 'foo' => array( 'value' => 'bar' ) ),
) );
}

/**
* Snapshot object passed in customize_snapshot_save filter.
*
* @var Customize_Snapshot
*/
public $filtered_snapshot;

/**
* Test that the snapshot object is passed as the second filter param.
*
* @see Customize_Snapshot::save()
*/
function test_filter_customize_snapshot_save() {
$manager = new Customize_Snapshot_Manager( $this->plugin );
$manager->ensure_customize_manager();
$manager->init();

$snapshot = new Customize_Snapshot( $manager, self::UUID );

$that = $this; // For PHP 5.3.
add_filter( 'customize_snapshot_save', function( $data, $test_snapshot ) use ( $that ) {
$that->filtered_snapshot = $test_snapshot;
return $data;
}, 10, 2 );

$snapshot->save( array(
'uuid' => self::UUID,
'data' => array( 'foo' => array( 'value' => 'bar' ) ),
) );

$this->assertEquals( $snapshot, $this->filtered_snapshot );
}
}

0 comments on commit a3876ea

Please sign in to comment.