WordPress.org

Make WordPress Core

Ticket #17851: template.php.patch

File template.php.patch, 2.2 KB (added by ross_ritchey, 4 years ago)

Add new $args to add_settings_section. Update add_settings_section to include new $args in array. Add wrapper around printout in do_settings_section.

  • template.php

     
    11901190 * @param string $title    Formatted title of the section. Shown as the heading for the section.
    11911191 * @param string $callback Function that echos out any content at the top of the section (between heading and fields).
    11921192 * @param string $page     The slug-name of the settings page on which to show the section. Built-in pages include 'general', 'reading', 'writing', 'discussion', 'media', etc. Create your own using add_options_page();
     1193 * @param array $args      An array of 3 arguments ('before_section', 'after_section', 'section_class') that allows for adding content and a custom class around the new settings section.
    11931194 */
    1194 function add_settings_section($id, $title, $callback, $page) {
     1195function add_settings_section($id, $title, $callback, $page, $args = array()) {
    11951196        global $wp_settings_sections;
    11961197
     1198        $defaults = array(
     1199                'id' => $id,
     1200                'title' => $title,
     1201                'callback' => $callback,
     1202                'before_section' => "",
     1203                'after_section' => "",
     1204                'section_class' => "",
     1205        );
     1206
     1207        $section = wp_parse_args( $args, $defaults );
     1208
    11971209        if ( 'misc' == $page ) {
    11981210                _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) );
    11991211                $page = 'general';
     
    12041216                $page = 'reading';
    12051217        }
    12061218
    1207         $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
     1219        // $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
     1220        $wp_settings_sections[$page][$id] = $section;
    12081221}
    12091222
    12101223/**
     
    12781291                return;
    12791292
    12801293        foreach ( (array) $wp_settings_sections[$page] as $section ) {
     1294                if ( $section['before_section'] != "" ) {
     1295                        echo sprintf($section['before_section'], $section['section_class']);
     1296                }
    12811297                if ( $section['title'] )
    12821298                        echo "<h2>{$section['title']}</h2>\n";
    12831299
     
    12891305                echo '<table class="form-table">';
    12901306                do_settings_fields( $page, $section['id'] );
    12911307                echo '</table>';
     1308
     1309                if ( $section['after_section'] != "" ) {
     1310                        echo $section['after_section'];
     1311                }
    12921312        }
    12931313}
    12941314