Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions php/context/class-fieldmanager-context-submenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ public function save_submenu_data( $data = null ) {
$current = get_option( $this->fm->name, null );
$data = $this->prepare_data( $current, $data );
$data = apply_filters( 'fm_submenu_presave_data', $data, $this );
if ( $this->fm->skip_save ) {
return true;
}

if ( isset( $current ) ) {
update_option( $this->fm->name, $data );
Expand Down
31 changes: 30 additions & 1 deletion tests/php/test-fieldmanager-context-submenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,35 @@ public function test_urls() {
$this->assertEquals( admin_url( 'admin.php?page=' . $name_4 ), $context_4->url() );
}

public function test_skip_save() {
$name = 'skip_save';
fm_register_submenu_page( $name, 'tools.php', 'Skip Save Fields' );
// Should save the first time
$context = $this->get_context( 'skip_save' );
$data = array(
'name' => 'Foo',
'email' => 'foo@alleyinteractive.com',
'remember' => true,
'number' => 11,
'group' => array( 'preferences' => '' ),
);
$this->assertTrue( $context->save_submenu_data( $data ) );
$this->assertEquals( $data, get_option( 'skip_save' ) );
// Shouldn't save the second time
$context->fm->skip_save = true;
delete_option( 'skip_save' );
$this->assertFalse( get_option( 'skip_save' ) );
$this->assertTrue( $context->save_submenu_data( $data ) );
$this->assertFalse( get_option( 'skip_save' ) );
// Permit saving the group, but not an individual field
$context->fm->skip_save = false;
$context->fm->children['name']->skip_save = true;
$this->assertTrue( $context->save_submenu_data( $data ) );
$option = get_option( 'skip_save' );
$this->assertFalse( isset( $option['name'] ) );
$this->assertEquals( 'foo@alleyinteractive.com', $option['email'] );
}

/**
* Build a html from the default context and fields.
*
Expand Down Expand Up @@ -235,4 +264,4 @@ public function test_updated_message() {
$this->assertContains( "<div class=\"updated success\"><p>{$updated_message}</p></div>", $this->get_html( $context, $name ) );
}

}
}