Ticket #23387: setting-priority.patch
| File setting-priority.patch, 1.8 KB (added by alexmansfield, 4 months ago) |
|---|
-
wp-admin/includes/template.php
1029 1029 * @param string $section The slug-name of the section of the settings page in which to show the box (default, ...). 1030 1030 * @param array $args Additional arguments 1031 1031 */ 1032 function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array() ) {1032 function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array(), $priority = 10) { 1033 1033 global $wp_settings_fields; 1034 1034 1035 1035 if ( 'misc' == $page ) { … … 1049 1049 if ( !isset($wp_settings_fields[$page][$section]) ) 1050 1050 $wp_settings_fields[$page][$section] = array(); 1051 1051 1052 $wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args );1052 $wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args, 'priority' => $priority); 1053 1053 } 1054 1054 1055 1055 /** … … 1105 1105 1106 1106 if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section]) ) 1107 1107 return; 1108 1109 uasort($wp_settings_fields[$page][$section], 'compare_priority'); 1108 1110 1109 1111 foreach ( (array) $wp_settings_fields[$page][$section] as $field ) { 1110 1112 echo '<tr valign="top">'; … … 1119 1121 } 1120 1122 } 1121 1123 1124 /** 1125 * Helper function to compare two objects by priority. 1126 * 1127 * @since 3.4.0 1128 * 1129 * @param object $a Object A. 1130 * @param object $b Object B. 1131 */ 1132 function compare_priority( $a, $b ) { 1133 $ap = $a['priority']; 1134 $bp = $b['priority']; 1135 1136 if ( $ap == $bp ) 1137 return 0; 1138 return ( $ap > $bp ) ? 1 : -1; 1139 } 1140 1122 1141 /** 1123 1142 * Register a settings error to be displayed to the user 1124 1143 *
