From eaa7c652636ea55f36ea61f18691a19bbc689f33 Mon Sep 17 00:00:00 2001 From: Helen Hou-Sandi Date: Thu, 28 Nov 2013 05:09:06 +0000 Subject: [PATCH] Add remove_option(), remove_options(), and get_options() methods to WP_Screen, along with unit tests. props ocean90, DrewAPicture. fixes #25799. git-svn-id: https://develop.svn.wordpress.org/trunk@26456 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/screen.php | 31 ++++++++++++++++++++ tests/phpunit/tests/admin/includesScreen.php | 26 ++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/src/wp-admin/includes/screen.php b/src/wp-admin/includes/screen.php index 2ab5161bff..33f91fea63 100644 --- a/src/wp-admin/includes/screen.php +++ b/src/wp-admin/includes/screen.php @@ -618,6 +618,37 @@ final class WP_Screen { $this->_options[ $option ] = $args; } + /** + * Remove an option from the screen. + * + * @since 3.8.0 + * + * @param string $option Option ID. + */ + public function remove_option( $option ) { + unset( $this->_options[ $option ] ); + } + + /** + * Remove all options from the screen. + * + * @since 3.8.0 + */ + public function remove_options() { + $this->_options = array(); + } + + /** + * Get the options registered for the screen. + * + * @since 3.8.0 + * + * @return array Options with arguments. + */ + public function get_options() { + return $this->_options; + } + /** * Gets the arguments for an option for the screen. * diff --git a/tests/phpunit/tests/admin/includesScreen.php b/tests/phpunit/tests/admin/includesScreen.php index 7952e3f0e2..704dc50a75 100644 --- a/tests/phpunit/tests/admin/includesScreen.php +++ b/tests/phpunit/tests/admin/includesScreen.php @@ -175,6 +175,32 @@ class Tests_Admin_includesScreen extends WP_UnitTestCase { $this->assertEquals( $screen->get_help_tabs(), array() ); } + /** + * @ticket 25799 + */ + function test_options() { + $option = rand_str(); + $option_args = array( + 'label' => 'Option', + 'default' => 10, + 'option' => $option + ); + + $screen = get_current_screen(); + + $screen->add_option( $option, $option_args ); + $this->assertEquals( $screen->get_option( $option ), $option_args ); + + $options = $screen->get_options(); + $this->assertArrayHasKey( $option, $options ); + + $screen->remove_option( $option ); + $this->assertNull( $screen->get_option( $option ) ); + + $screen->remove_options(); + $this->assertEquals( $screen->get_options(), array() ); + } + function test_in_admin() { $screen = get_current_screen();