Make WordPress Core


Ignore:
Timestamp:
08/28/2024 04:39:30 PM (20 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/wpSetOptionsAutoload.php

    r57920 r58945  
    1212     * Tests that setting options' autoload value to 'yes' works as expected.
    1313     *
     14     * The values 'yes' and 'no' are only supported for backward compatibility.
     15     *
    1416     * @ticket 58964
    1517     */
     
    2426        $expected = array();
    2527        foreach ( $options as $option => $value ) {
    26             add_option( $option, $value, '', 'no' );
     28            add_option( $option, $value, '', false );
    2729            $expected[ $option ] = true;
    2830        }
     
    4143     * Tests that setting options' autoload value to 'no' works as expected.
    4244     *
     45     * The values 'yes' and 'no' are only supported for backward compatibility.
     46     *
    4347     * @ticket 58964
    4448     */
     
    5357        $expected = array();
    5458        foreach ( $options as $option => $value ) {
    55             add_option( $option, $value, '', 'yes' );
     59            add_option( $option, $value, '', true );
    5660            $expected[ $option ] = true;
    5761        }
     
    8185        $expected = array();
    8286        foreach ( $options as $option => $value ) {
    83             add_option( $option, $value, '', 'yes' );
     87            add_option( $option, $value, '', true );
    8488            $expected[ $option ] = false;
    8589        }
    8690
    8791        $num_queries = get_num_queries();
    88         $this->assertSame( $expected, wp_set_options_autoload( array_keys( $options ), 'yes' ), 'Function did unexpectedly succeed' );
     92        $this->assertSame( $expected, wp_set_options_autoload( array_keys( $options ), true ), 'Function did unexpectedly succeed' );
    8993        $this->assertSame( $num_queries + 1, get_num_queries(), 'Function attempted to update options autoload value in database' );
    9094        $this->assertSame( array( 'on', '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 ) ) ), 'Options autoload value unexpectedly updated in database' );
     
    109113        }
    110114
    111         $this->assertSame( $expected, wp_set_options_autoload( $options, 'yes' ), 'Function did unexpectedly succeed' );
     115        $this->assertSame( $expected, wp_set_options_autoload( $options, true ), 'Function did unexpectedly succeed' );
    112116        $this->assertSame( array(), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Missing options autoload value was set in database' );
    113117    }
     
    126130        );
    127131
    128         add_option( 'test_option1', $options['test_option1'], '', 'yes' );
    129         add_option( 'test_option2', $options['test_option2'], '', 'no' );
     132        add_option( 'test_option1', $options['test_option1'], '', true );
     133        add_option( 'test_option2', $options['test_option2'], '', false );
    130134        $expected = array(
    131135            'test_option1' => false,
     
    133137        );
    134138
    135         $this->assertSame( $expected, wp_set_options_autoload( array_keys( $options ), 'yes' ), 'Function produced unexpected result' );
     139        $this->assertSame( $expected, wp_set_options_autoload( array_keys( $options ), true ), 'Function produced unexpected result' );
    136140        $this->assertSame( array( 'on', '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' );
    137141        foreach ( $options as $option => $value ) {
Note: See TracChangeset for help on using the changeset viewer.