Ticket #15865: removal_functions_2.diff

File removal_functions_2.diff, 3.2 KB (added by ctsttom, 22 months ago)

Corrections to previous patch

Line 
1Index: template.php
2===================================================================
3--- template.php        (revision 18467)
4+++ template.php        (working copy)
5@@ -1102,6 +1102,33 @@
6 }
7 
8 /**
9+ * Remove a section from a settings page.
10+ *
11+ * Part of the Settings API. Use this to remove settings sections from an admin page.
12+ *
13+ * @since 3.3
14+ *
15+ * @global $wp_settings_sections Storage array of all settings sections added to admin pages
16+ * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
17+ *
18+ * @param string $id Slug-name to identify the section.
19+ * @param string $page The slug-name of the settings page on which to remove the section.
20+ */
21+function remove_settings_section( $id, $page ) {
22+       global $wp_settings_sections, $wp_settings_fields;
23+
24+       unset( $wp_settings_sections[$page][$id] );
25+       
26+       if ( empty( $wp_settings_sections[$page] ) )
27+               unset( $wp_settings_sections[$page] );
28+               
29+       unset( $wp_settings_fields[$page][$id] );
30+       
31+       if ( empty( $wp_settings_fields[$page] )  )
32+               unset( $wp_settings_fields[$page] );
33+}
34+
35+/**
36  * Add a new field to a section of a settings page
37  *
38  * Part of the Settings API. Use this to define a settings field that will show
39@@ -1120,7 +1147,7 @@
40  * @param string $title Formatted title of the field. Shown as the label for the field during output.
41  * @param string $callback Function that fills the field with the desired form inputs. The function should echo its output.
42  * @param string $page The slug-name of the settings page on which to show the section (general, reading, writing, ...).
43- * @param string $section The slug-name of the section of the settingss page in which to show the box (default, ...).
44+ * @param string $section The slug-name of the section of the settings page in which to show the box (default, ...).
45  * @param array $args Additional arguments
46  */
47 function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) {
48@@ -1142,6 +1169,36 @@
49 }
50 
51 /**
52+ * Remove a field from a section of a settings page
53+ *
54+ * Part of the Settings API. Use this to remove a settings field from a
55+ * settings section inside a settings page.
56+ *
57+ * The $callback argument should be the name of a function that echoes out the
58+ * html input tags for this setting field. Use get_option() to retrive existing
59+ * values to show.
60+ *
61+ * @since 3.3
62+ *
63+ * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
64+ *
65+ * @param string $id Slug-name to identify the field.
66+ * @param string $page The slug-name of the settings page on which to remove the section.
67+ * @param string $section The slug-name of the section of the settings page in which to remove the box.
68+ */
69+function remove_settings_field( $id, $page, $section = 'default' ) {
70+       global $wp_settings_fields;
71+       
72+       unset( $wp_settings_fields[$page][$section][$id] );
73+       
74+       if ( empty( $wp_settings_fields[$page][$section] ) )
75+               unset( $wp_settings_fields[$page][$section] );
76+       
77+       if ( empty( $wp_settings_fields[$page] ) )
78+               unset( $wp_settings_fields[$page] );
79+}
80+
81+/**
82  * Prints out all settings sections added to a particular settings page
83  *
84  * Part of the Settings API. Use this in a settings page callback function