Ticket #37355: remove-settings-section.diff
File remove-settings-section.diff, 2.6 KB (added by , 8 years ago) |
---|
-
src/wp-admin/includes/template.php
diff --git src/wp-admin/includes/template.php src/wp-admin/includes/template.php index 0de80e7..bff0c51 100644
function add_settings_section($id, $title, $callback, $page) { 1217 1217 } 1218 1218 1219 1219 /** 1220 * Remove a section from a settings page. 1221 * 1222 * @since 4.7.0 1223 * 1224 * @global $wp_settings_sections Storage array of all settings sections added to admin pages 1225 * 1226 * @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags. 1227 * @param string $page The slug-name of the settings page on which the section has been added. 1228 * Built-in pages include 1229 * 'general', 'reading', 'writing', 'discussion', 'media', etc. Create your own using 1230 * add_options_page(); 1231 */ 1232 function remove_settings_section( $id, $page ) { 1233 global $wp_settings_sections; 1234 unset( $wp_settings_sections[ $page ][ $id ] ); 1235 } 1236 1237 /** 1220 1238 * Add a new field to a section of a settings page 1221 1239 * 1222 1240 * Part of the Settings API. Use this to define a settings field that will show -
new file tests/phpunit/tests/settings-api.php
diff --git tests/phpunit/tests/settings-api.php tests/phpunit/tests/settings-api.php new file mode 100644 index 0000000..5a00d9d
- + 1 <?php 2 3 /** 4 * @group settings-api 5 */ 6 class Tests_Settings_API extends WP_UnitTestCase { 7 8 9 function assertHasSettingsSection( $id, $page ) { 10 global $wp_settings_sections; 11 $this->assertArrayHasKey( 12 $page, 13 $wp_settings_sections, 14 sprintf( 'Settings page "%s" not registered', $page ) 15 ); 16 $this->assertArrayHasKey( 17 $id, 18 $wp_settings_sections[$page], 19 sprintf( 'Settings section "%s" not registered for page "%s"', $id, $page ) 20 ); 21 } 22 23 function assertNotHasSettingsSection( $id, $page ) { 24 global $wp_settings_sections; 25 $this->assertArrayNotHasKey( 26 $id, 27 $wp_settings_sections[$page], 28 sprintf( 'Settings section "%s" is registered for page "%s"', $id, $page ) 29 ); 30 } 31 32 function test_add_settings_section() { 33 add_settings_section( 34 'custom_settings_section', 35 __( 'Custom Settings Section', 'textdomain' ), 36 '__return_false', 37 'reading' 38 ); 39 $this->assertHasSettingsSection( 'custom_settings_section', 'reading' ); 40 } 41 42 function test_remove_settings_section() { 43 add_settings_section( 44 'custom_settings_section', 45 __( 'Custom Settings Section', 'textdomain' ), 46 '__return_false', 47 'reading' 48 ); 49 remove_settings_section( 'custom_settings_section', 'reading' ); 50 $this->assertNotHasSettingsSection( 'custom_settings_section', 'reading' ); 51 } 52 53 }