Make WordPress Core

Ticket #28672: 28672.2.diff

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

Refreshed patch

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

     
    12761276 *     @type string $class     CSS Class to be added to the `<tr>` element when the
    12771277 *                             field is output.
    12781278 * }
     1279 * @return true|WP_Error    Will return WP_Error if the page and section have not been defined, true otherwise.
    12791280 */
    12801281function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) {
    1281         global $wp_settings_fields;
     1282        global $wp_settings_fields, $wp_settings_sections;
    12821283
    12831284        if ( 'misc' == $page ) {
    12841285                _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
     
    12901291                $page = 'reading';
    12911292        }
    12921293
    1293         $wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args);
     1294        $built_in_pages_and_sections = array(
     1295                'discussion' => array( 'default', 'avatars' ),
     1296                'general'    => array( 'default' ),
     1297                'media'      => array( 'default', 'embeds', 'uploads' ),
     1298                'permalink'  => array( 'optional' ),
     1299                'reading'    => array( 'default' ),
     1300                'writing'    => array( 'default', 'remote_publishing', 'post_via_email' ),
     1301        );
     1302
     1303        // check the built-in pages and sections
     1304        $section_check = ! empty( $built_in_pages_and_sections[ $page ] ) && in_array( $section, $built_in_pages_and_sections[ $page ] );
     1305
     1306        if ( ! $section_check ) {
     1307                // check any sections added by add_settings_section
     1308                $section_check = ! empty( $wp_settings_sections[ $page ][ $section ] );
     1309        }
     1310
     1311        $wp_settings_fields[ $page ][ $section ][ $id ] = array( 'id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args );
     1312
     1313        return ! $section_check ? new WP_Error( 'invalid_settings_section', sprintf( __('Settings page \'%s\', section \'%s\' does not exist.'), $page, $section ) ) : $section_check;
    12941314}
    12951315
    12961316/**