Make WordPress Core

Ticket #53858: 53858.patch

File 53858.patch, 2.7 KB (added by ayeshrajans, 3 years ago)

Suggesting this patch. It renames readonly to wp_readonly, and conditionally includes a ./PHP_Compat/readonly.php file on PHP < 8.1, which declares a readonly func that calls wp_readonly.

  • new file src/wp-includes/PHP_Compat/readonly.php

    commit da83966fa13e866c1d00b6eec45d963948fb08b7
    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..a441f03c94
    - +  
     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 * @subpackage oEmbed
     14 */
     15
     16/**
     17 * Outputs the HTML readonly attribute.
     18 *
     19 * Compares the first two arguments and if identical marks as readonly
     20 *
     21 * This function is deprecated, and cannot be used on PHP >= 8.1.
     22 * @see wp_readonly
     23 *
     24 * @since 4.9.0
     25 * @deprecated 5.9.0
     26 *
     27 * @param mixed $readonly One of the values to compare
     28 * @param mixed $current  (true) The other value to compare if not just true
     29 * @param bool  $echo     Whether to echo or just return the string
     30 * @return string HTML attribute or empty string
     31 */
     32function readonly( $readonly, $current = true, $echo = true ) {
     33        return wp_readonly( $readonly, $current, $echo );
     34}
  • src/wp-includes/general-template.php

    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 ) { 
    48134813 *
    48144814 * Compares the first two arguments and if identical marks as readonly
    48154815 *
    4816  * @since 4.9.0
     4816 * @since 5.9.0
    48174817 *
    48184818 * @param mixed $readonly One of the values to compare
    48194819 * @param mixed $current  (true) The other value to compare if not just true
    48204820 * @param bool  $echo     Whether to echo or just return the string
    48214821 * @return string HTML attribute or empty string
    48224822 */
    4823 function readonly( $readonly, $current = true, $echo = true ) {
     4823function wp_readonly( $readonly, $current = true, $echo = true ) {
    48244824        return __checked_selected_helper( $readonly, $current, $echo, 'readonly' );
    48254825}
    48264826
     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 */
     4834if (PHP_VERSION_ID < 80100) {
     4835        require_once __DIR__ . '/PHP_Compat/readonly.php';
     4836}
     4837
     4838
    48274839/**
    48284840 * Private helper function for checked, selected, disabled and readonly.
    48294841 *