commit 5c0cef40980e721b6196f5aa776f050ca1158dc7
Author: Ayesh Karunaratne <ayesh@aye.sh>
Date: Mon Aug 2 19:51:55 2021 +0530
Extract readonly function
diff --git a/src/wp-includes/PHP_Compat/readonly.php b/src/wp-includes/PHP_Compat/readonly.php
new file mode 100644
index 0000000000..a82c0b6c11
-
|
+
|
|
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Conditionally declares a `readonly` function, which was renamed to |
| 5 | * `wp_readonly` in WordPress 5.9. |
| 6 | * |
| 7 | * In order to avoid PHP parser errors, this function was extracted to |
| 8 | * this separate file, and only included conditionally on PHP 8.1. |
| 9 | * |
| 10 | * Including this file on PHP >= 8.1 results in a fatal error. |
| 11 | * |
| 12 | * @package WordPress |
| 13 | */ |
| 14 | |
| 15 | /** |
| 16 | * Outputs the HTML readonly attribute. |
| 17 | * |
| 18 | * Compares the first two arguments and if identical marks as readonly |
| 19 | * |
| 20 | * This function is deprecated, and cannot be used on PHP >= 8.1. |
| 21 | * @see wp_readonly |
| 22 | * |
| 23 | * @since 4.9.0 |
| 24 | * @deprecated 5.9.0 |
| 25 | * |
| 26 | * @param mixed $readonly One of the values to compare |
| 27 | * @param mixed $current (true) The other value to compare if not just true |
| 28 | * @param bool $echo Whether to echo or just return the string |
| 29 | * @return string HTML attribute or empty string |
| 30 | */ |
| 31 | function readonly( $readonly, $current = true, $echo = true ) { |
| 32 | return wp_readonly( $readonly, $current, $echo ); |
| 33 | } |
diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php
index ab8877f7be..d54441cab5 100644
a
|
b
|
function disabled( $disabled, $current = true, $echo = true ) { |
4813 | 4813 | * |
4814 | 4814 | * Compares the first two arguments and if identical marks as readonly |
4815 | 4815 | * |
4816 | | * @since 4.9.0 |
| 4816 | * @since 5.9.0 |
4817 | 4817 | * |
4818 | 4818 | * @param mixed $readonly One of the values to compare |
4819 | 4819 | * @param mixed $current (true) The other value to compare if not just true |
4820 | 4820 | * @param bool $echo Whether to echo or just return the string |
4821 | 4821 | * @return string HTML attribute or empty string |
4822 | 4822 | */ |
4823 | | function readonly( $readonly, $current = true, $echo = true ) { |
| 4823 | function wp_readonly( $readonly, $current = true, $echo = true ) { |
4824 | 4824 | return __checked_selected_helper( $readonly, $current, $echo, 'readonly' ); |
4825 | 4825 | } |
4826 | 4826 | |
| 4827 | /** |
| 4828 | * Include a compat `readonly` function on PHP < 8.1. Since PHP 8.1, |
| 4829 | * `readonly` is a reserved keyword, and it is not possible to use |
| 4830 | * it as a function name. In order to maintain compatibility with |
| 4831 | * existing functions, this function was extracted to a separate file, |
| 4832 | * and included on PHP < 8.1. |
| 4833 | */ |
| 4834 | if (PHP_VERSION_ID < 80100) { |
| 4835 | require_once __DIR__ . '/PHP_Compat/readonly.php'; |
| 4836 | } |
| 4837 | |
| 4838 | |
4827 | 4839 | /** |
4828 | 4840 | * Private helper function for checked, selected, disabled and readonly. |
4829 | 4841 | * |