Make WordPress Core


Ignore:
Timestamp:
08/01/2021 02:54:52 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Themes: Make sure get_theme_mods() always returns an array.

This avoids a "Cannot access offset of type string on string" fatal error in set_theme_mod() on PHP 8 if the theme_mods_$theme_slug option has an incorrect value, e.g. an empty string instead of an array.

With this change, set_theme_mod() should be able to resolve the issue by saving a correct value.

Follow-up to [15736], [15739], [30672], [32629], [32632].

Props xknown.
See #51423.

File:
1 edited

Legend:

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

    r48937 r51524  
    1818        set_theme_mod( 'test_name', $expected );
    1919        $this->assertSame( $expected, get_theme_mod( 'test_name' ) );
     20    }
     21
     22    /**
     23     * @ticket 51423
     24     */
     25    function test_theme_mod_set_with_invalid_theme_mods_option() {
     26        $theme_slug = get_option( 'stylesheet' );
     27        update_option( 'theme_mods_' . $theme_slug, '' );
     28        self::test_theme_mod_set();
    2029    }
    2130
Note: See TracChangeset for help on using the changeset viewer.