Make WordPress Core


Ignore:
Timestamp:
08/28/2024 04:39:30 PM (19 months ago)
Author:
flixos90
Message:

Options, Meta APIs: Stop using 'yes' and 'no' for autoload parameter in favor of recommended boolean.

This changeset does not modify any behavior, it only updates the code to use the recommended type for the $autoload parameter as of WordPress 6.6. The old values 'yes' and 'no' are only maintained in certain tests that are explicitly about these backward compatibility values.

Props flixos90, joemcgill, mukesh27.
Fixes #61939.
See #61103, #61929.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/option/wpSetOptionAutoloadValues.php

    r57920 r58945  
    1212     * Tests setting options' autoload to 'yes' where for some options this is already the case.
    1313     *
     14     * The values 'yes' and 'no' are only supported for backward compatibility.
     15     *
    1416     * @ticket 58964
    1517     */
     
    2123            'test_option2' => 'yes',
    2224        );
    23         add_option( 'test_option1', 'value1', '', 'yes' );
    24         add_option( 'test_option2', 'value2', '', 'no' );
     25        add_option( 'test_option1', 'value1', '', true );
     26        add_option( 'test_option2', 'value2', '', false );
    2527        $expected = array(
    2628            'test_option1' => false,
     
    4345     * In this case, the 'alloptions' cache should not be cleared, but only its options set to 'no' should be deleted.
    4446     *
     47     * The values 'yes' and 'no' are only supported for backward compatibility.
     48     *
    4549     * @ticket 58964
    4650     */
     
    5256            'test_option2' => 'no',
    5357        );
    54         add_option( 'test_option1', 'value1', '', 'yes' );
    55         add_option( 'test_option2', 'value2', '', 'no' );
     58        add_option( 'test_option1', 'value1', '', true );
     59        add_option( 'test_option2', 'value2', '', false );
    5660        $expected = array(
    5761            'test_option1' => true,
     
    7175     * Tests setting options' autoload to 'yes' where for all of them this is already the case.
    7276     *
     77     * The values 'yes' and 'no' are only supported for backward compatibility.
     78     *
    7379     * @ticket 58964
    7480     */
     
    8086            'test_option2' => 'yes',
    8187        );
    82         add_option( 'test_option1', 'value1', '', 'yes' );
    83         add_option( 'test_option2', 'value2', '', 'yes' );
     88        add_option( 'test_option1', 'value1', '', true );
     89        add_option( 'test_option2', 'value2', '', true );
    8490        $expected = array(
    8591            'test_option1' => false,
     
    97103
    98104    /**
    99      * Tests setting options' autoload to either 'yes' or 'no' where for some options this is already the case.
     105     * Tests setting options' autoload to either true or false where for some options this is already the case.
    100106     *
    101107     * The test also covers one option that is entirely missing.
     
    107113
    108114        $options = array(
    109             'test_option1' => 'yes',
    110             'test_option2' => 'no',
    111             'test_option3' => 'yes',
    112             'missing_opt'  => 'yes',
    113         );
    114         add_option( 'test_option1', 'value1', '', 'no' );
    115         add_option( 'test_option2', 'value2', '', 'yes' );
    116         add_option( 'test_option3', 'value3', '', 'yes' );
     115            'test_option1' => true,
     116            'test_option2' => false,
     117            'test_option3' => true,
     118            'missing_opt'  => true,
     119        );
     120        add_option( 'test_option1', 'value1', '', false );
     121        add_option( 'test_option2', 'value2', '', true );
     122        add_option( 'test_option3', 'value3', '', true );
    117123        $expected = array(
    118124            'test_option1' => true,
     
    133139
    134140    /**
    135      * Tests setting options' autoload to either 'yes' or 'no' while only the 'no' options actually need to be updated.
     141     * Tests setting options' autoload to either true or false while only the false options actually need to be updated.
    136142     *
    137143     * In this case, the 'alloptions' cache should not be cleared, but only its options set to 'no' should be deleted.
     
    143149
    144150        $options = array(
    145             'test_option1' => 'yes',
    146             'test_option2' => 'no',
    147             'test_option3' => 'yes',
    148         );
    149         add_option( 'test_option1', 'value1', '', 'yes' );
    150         add_option( 'test_option2', 'value2', '', 'yes' );
    151         add_option( 'test_option3', 'value3', '', 'yes' );
     151            'test_option1' => true,
     152            'test_option2' => false,
     153            'test_option3' => true,
     154        );
     155        add_option( 'test_option1', 'value1', '', true );
     156        add_option( 'test_option2', 'value2', '', true );
     157        add_option( 'test_option3', 'value3', '', true );
    152158        $expected = array(
    153159            'test_option1' => false,
     
    161167        $this->assertSameSets( array( 'on', 'off', 'on' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );
    162168        foreach ( $options as $option => $autoload ) {
    163             if ( 'no' === $autoload ) {
     169            if ( false === $autoload ) {
    164170                $this->assertArrayNotHasKey( $option, wp_cache_get( 'alloptions', 'options' ), sprintf( 'Option %s not deleted from alloptions cache', $option ) );
    165171            } else {
     
    178184
    179185        $options = array(
    180             'test_option1' => 'yes',
    181             'test_option2' => 'yes',
    182         );
    183         add_option( 'test_option1', 'value1', '', 'no' );
    184         add_option( 'test_option2', 'value2', '', 'no' );
     186            'test_option1' => true,
     187            'test_option2' => true,
     188        );
     189        add_option( 'test_option1', 'value1', '', false );
     190        add_option( 'test_option2', 'value2', '', false );
    185191
    186192        // Force UPDATE queries to fail, leading to no autoload values being updated.
     
    204210
    205211    /**
    206      * Tests setting options' autoload with boolean values.
     212     * Tests setting options' autoload with now encouraged boolean values.
    207213     *
    208214     * @ticket 58964
Note: See TracChangeset for help on using the changeset viewer.