Make WordPress Core

Ticket #28672: 28672.diff

File 28672.diff, 2.0 KB (added by GunGeekATX, 10 years ago)

Proposed patch

  • src/wp-admin/includes/template.php

     
    12171217 * @param string $page The slug-name of the settings page on which to show the section (general, reading, writing, ...).
    12181218 * @param string $section The slug-name of the section of the settings page in which to show the box (default, ...).
    12191219 * @param array $args Additional arguments
     1220 * @return true|WP_Error Will return WP_Error if the page and section have not been defined, true otherwise.
    12201221 */
    12211222function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) {
    1222         global $wp_settings_fields;
     1223        global $wp_settings_fields, $wp_settings_sections;
    12231224
    12241225        if ( 'misc' == $page ) {
    12251226                _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
     
    12311232                $page = 'reading';
    12321233        }
    12331234
     1235        $built_in_pages_and_sections = array(
     1236                'discussion' => array( 'default', 'avatars' ),
     1237                'general' => array( 'default' ),
     1238                'media' => array( 'default', 'embeds', 'uploads' ),
     1239                'permalink' => array( 'optional' ),
     1240                'reading' => array( 'default' ),
     1241                'writing' => array( 'default', 'remote_publishing' ),
     1242        );
     1243
     1244        // check the built-in pages and sections
     1245        $section_check = ! empty( $built_in_pages_and_sections[$page] ) && in_array( $section, $built_in_pages_and_sections[$page] );
     1246
     1247        if ( ! $section_check ) {
     1248                // check any sections added by add_settings_section
     1249                $section_check = ! empty( $wp_settings_sections[$page][$section] );
     1250        }
     1251
    12341252        $wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args);
     1253
     1254        return ! $section_check ? new WP_Error( 'invalid_settings_section', sprintf( __('Settings page \'%s\', section \'%s\' does not exist.'), $page, $section ) ) : $section_check;
    12351255}
    12361256
    12371257/**