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 ) { |
1627 | 1627 | * @type string $class CSS Class to be added to the `<tr>` element when the |
1628 | 1628 | * field is output. |
1629 | 1629 | * } |
| 1630 | * |
| 1631 | * @param int $position The position in the settings order this item should appear. |
1630 | 1632 | */ |
1631 | | function add_settings_field( $id, $title, $callback, $page, $section = 'default', $args = array() ) { |
| 1633 | function add_settings_field( $id, $title, $callback, $page, $section = 'default', $args = array(), $position = null ) { |
1632 | 1634 | global $wp_settings_fields; |
1633 | 1635 | |
1634 | 1636 | if ( 'misc' === $page ) { |
… |
… |
function add_settings_field( $id, $title, $callback, $page, $section = 'default' |
1662 | 1664 | 'title' => $title, |
1663 | 1665 | 'callback' => $callback, |
1664 | 1666 | 'args' => $args, |
| 1667 | 'position' => $position, |
1665 | 1668 | ); |
1666 | 1669 | } |
1667 | 1670 | |
… |
… |
function do_settings_fields( $page, $section ) { |
1724 | 1727 | return; |
1725 | 1728 | } |
1726 | 1729 | |
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 ) { |
1728 | 1737 | $class = ''; |
1729 | 1738 | |
1730 | 1739 | if ( ! empty( $field['args']['class'] ) ) { |