Make WordPress Core

Ticket #38097: 38097.2.diff

File 38097.2.diff, 1.8 KB (added by kapilpaul, 4 years ago)

Updated patch.

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

    From 2a660d36d75c81d0c5e942f03f0feec50688a5a8 Mon Sep 17 00:00:00 2001
    From: Kapil Paul <kapilpaul007@gmail.com>
    Date: Sat, 29 May 2021 02:48:14 +0600
    Subject: [PATCH] add: ability to assign position in settings API
    
    ---
     src/wp-admin/includes/template.php | 13 +++++++++++--
     1 file changed, 11 insertions(+), 2 deletions(-)
    
    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'] ) ) {