WordPress.org

Make WordPress Core

Ticket #15865: removal_functions_2.diff

File removal_functions_2.diff, 3.2 KB (added by ctsttom, 7 years ago)

Corrections to previous patch

  • template.php

     
    11021102}
    11031103
    11041104/**
     1105 * Remove a section from a settings page.
     1106 *
     1107 * Part of the Settings API. Use this to remove settings sections from an admin page.
     1108 *
     1109 * @since 3.3
     1110 *
     1111 * @global $wp_settings_sections Storage array of all settings sections added to admin pages
     1112 * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
     1113 *
     1114 * @param string $id Slug-name to identify the section.
     1115 * @param string $page The slug-name of the settings page on which to remove the section.
     1116 */
     1117function remove_settings_section( $id, $page ) {
     1118        global $wp_settings_sections, $wp_settings_fields;
     1119
     1120        unset( $wp_settings_sections[$page][$id] );
     1121       
     1122        if ( empty( $wp_settings_sections[$page] ) )
     1123                unset( $wp_settings_sections[$page] );
     1124               
     1125        unset( $wp_settings_fields[$page][$id] );
     1126       
     1127        if ( empty( $wp_settings_fields[$page] )  )
     1128                unset( $wp_settings_fields[$page] );
     1129}
     1130
     1131/**
    11051132 * Add a new field to a section of a settings page
    11061133 *
    11071134 * Part of the Settings API. Use this to define a settings field that will show
     
    11201147 * @param string $title Formatted title of the field. Shown as the label for the field during output.
    11211148 * @param string $callback Function that fills the field with the desired form inputs. The function should echo its output.
    11221149 * @param string $page The slug-name of the settings page on which to show the section (general, reading, writing, ...).
    1123  * @param string $section The slug-name of the section of the settingss page in which to show the box (default, ...).
     1150 * @param string $section The slug-name of the section of the settings page in which to show the box (default, ...).
    11241151 * @param array $args Additional arguments
    11251152 */
    11261153function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) {
     
    11421169}
    11431170
    11441171/**
     1172 * Remove a field from a section of a settings page
     1173 *
     1174 * Part of the Settings API. Use this to remove a settings field from a
     1175 * settings section inside a settings page.
     1176 *
     1177 * The $callback argument should be the name of a function that echoes out the
     1178 * html input tags for this setting field. Use get_option() to retrive existing
     1179 * values to show.
     1180 *
     1181 * @since 3.3
     1182 *
     1183 * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
     1184 *
     1185 * @param string $id Slug-name to identify the field.
     1186 * @param string $page The slug-name of the settings page on which to remove the section.
     1187 * @param string $section The slug-name of the section of the settings page in which to remove the box.
     1188 */
     1189function remove_settings_field( $id, $page, $section = 'default' ) {
     1190        global $wp_settings_fields;
     1191       
     1192        unset( $wp_settings_fields[$page][$section][$id] );
     1193       
     1194        if ( empty( $wp_settings_fields[$page][$section] ) )
     1195                unset( $wp_settings_fields[$page][$section] );
     1196       
     1197        if ( empty( $wp_settings_fields[$page] ) )
     1198                unset( $wp_settings_fields[$page] );
     1199}
     1200
     1201/**
    11451202 * Prints out all settings sections added to a particular settings page
    11461203 *
    11471204 * Part of the Settings API. Use this in a settings page callback function