Ticket #22487: section-priority.patch

File section-priority.patch, 1.9 KB (added by alexmansfield, 6 months ago)

Adds priority option to settings sections

  • wp-admin/includes/template.php

     
    988988 * @param string $callback Function that echos out any content at the top of the section (between heading and fields). 
    989989 * @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(); 
    990990 */ 
    991 function add_settings_section($id, $title, $callback, $page) { 
     991function add_settings_section($id, $title, $callback, $page, $priority = 10) { 
    992992        global $wp_settings_sections; 
    993993 
    994994        if ( 'misc' == $page ) { 
     
    10081008        if ( !isset($wp_settings_sections[$page][$id]) ) 
    10091009                $wp_settings_sections[$page][$id] = array(); 
    10101010 
    1011         $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback); 
     1011        $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'priority' => $priority); 
    10121012} 
    10131013 
    10141014/** 
     
    10751075        if ( ! isset( $wp_settings_sections ) || !isset( $wp_settings_sections[$page] ) ) 
    10761076                return; 
    10771077 
     1078        uasort($wp_settings_sections[$page], 'compare_priority'); 
     1079 
    10781080        foreach ( (array) $wp_settings_sections[$page] as $section ) { 
    10791081                if ( $section['title'] ) 
    10801082                        echo "<h3>{$section['title']}</h3>\n"; 
     
    10911093} 
    10921094 
    10931095/** 
     1096 * Helper function to compare two objects by priority. 
     1097 * 
     1098 * @since 3.4.0 
     1099 * 
     1100 * @param object $a Object A. 
     1101 * @param object $b Object B. 
     1102 */ 
     1103function compare_priority( $a, $b ) { 
     1104        $ap = $a['priority']; 
     1105        $bp = $b['priority']; 
     1106 
     1107        if ( $ap == $bp ) 
     1108                return 0; 
     1109        return ( $ap > $bp ) ? 1 : -1; 
     1110} 
     1111 
     1112/** 
    10941113 * Print out the settings fields for a particular settings section 
    10951114 * 
    10961115 * Part of the Settings API. Use this in a settings page to output