WordPress.org

Make WordPress Core

Ticket #38097: 38097.diff

File 38097.diff, 2.6 KB (added by kapilpaul, 5 months ago)

Created patch.

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

    diff --git a/src/wp-admin/includes/template.php b/src/wp-admin/includes/template.php
    index 8e22630d6a..9e6eacd1d8 100644
    a b function add_settings_section( $id, $title, $callback, $page ) { 
    16271627 *     @type string $class     CSS Class to be added to the `<tr>` element when the
    16281628 *                             field is output.
    16291629 * }
     1630 *
     1631 * @param int      $position   The position in the settings order this item should appear.
    16301632 */
    1631 function add_settings_field( $id, $title, $callback, $page, $section = 'default', $args = array() ) {
     1633function add_settings_field( $id, $title, $callback, $page, $section = 'default', $args = array(), $position = null ) {
    16321634        global $wp_settings_fields;
    16331635
    16341636        if ( 'misc' === $page ) {
    function add_settings_field( $id, $title, $callback, $page, $section = 'default' 
    16621664                'title'    => $title,
    16631665                'callback' => $callback,
    16641666                'args'     => $args,
     1667                'position' => $position,
    16651668        );
    16661669}
    16671670
    function do_settings_fields( $page, $section ) { 
    17241727                return;
    17251728        }
    17261729
    1727         foreach ( (array) $wp_settings_fields[ $page ][ $section ] as $field ) {
     1730        $fields = (array) $wp_settings_fields[ $page ][ $section ];
     1731
     1732        usort( $fields, function( $a, $b ) {
     1733                return $a['position'] - $b['position'];
     1734        } );
     1735
     1736        foreach ( $fields as $field ) {
    17281737                $class = '';
    17291738
    17301739                if ( ! empty( $field['args']['class'] ) ) {
  • src/wp-content/themes/twentytwentyone/functions.php

    diff --git a/src/wp-content/themes/twentytwentyone/functions.php b/src/wp-content/themes/twentytwentyone/functions.php
    index 1139c3b659..bc51fc218f 100644
    a b function twentytwentyone_add_ie_class() { 
    627627        <?php
    628628}
    629629add_action( 'wp_footer', 'twentytwentyone_add_ie_class' );
     630
     631
     632add_action( 'admin_init', 'wpse_57647_register_settings' );
     633
     634function wpse_57647_register_settings()
     635{       
     636    add_settings_field(
     637        'add_position2_in_settings_api',
     638        'How Will Position Work 2',
     639        'print_settings_text',
     640        'general',
     641                'default',
     642                array(),
     643                10
     644    );
     645
     646        add_settings_field(
     647        'add_position1_in_settings_api',
     648        'How Will Position Work 1',
     649        'print_settings_text',
     650        'general',
     651                'default',
     652                array(),
     653                9
     654    );
     655}
     656
     657function print_settings_text()
     658{
     659    echo 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Explicabo repellat dicta, natus quaerat odio facere debitis, asperiores libero quidem aut praesentium autem, inventore sequi veniam sunt totam ipsam quos facilis?';
     660}
     661 No newline at end of file