[wp-trac] [WordPress Trac] #60276: Fatal error with unexpected string value for sticky_posts option
WordPress Trac
noreply at wordpress.org
Wed Jan 17 17:28:39 UTC 2024
#60276: Fatal error with unexpected string value for sticky_posts option
--------------------------+-----------------------------
Reporter: mreishus | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
== Summary:
Code in wp-include/blocks.php pulls out the option on line 1708:
{{{
$sticky = get_option( 'sticky_posts' );
}}}
Then assumes it is an array, when passing it into array_merge on line
1720:
{{{
$query['post__not_in'] = array_merge( $query['post__not_in'], $sticky );
}}}
This can cause a fatal error if the option is not set to an array:
{{{
Fatal error: Uncaught TypeError: array_merge(): Argument #2 must be of
type array, string given
}}}
Other parts of the code are defensive about the data coming from {{{
get_option( 'sticky_posts' ); }}} , but this part is not.
== Steps to Reproduce:
* Use WP 6.4.2 and theme Twenty Twenty-Four Version: 1.0
* Set your sticky_posts option to an empty string (an unexpected type)
{{{
MariaDB [wordpress]> select * from wp_options where
option_name='sticky_posts';
+-----------+--------------+--------------+----------+
| option_id | option_name | option_value | autoload |
+-----------+--------------+--------------+----------+
| 75 | sticky_posts | a:0:{} | yes |
+-----------+--------------+--------------+----------+
1 row in set (0.000 sec)
MariaDB [wordpress]> update wp_options set option_value='' where
option_id=75;
Query OK, 1 row affected (0.012 sec)
Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [wordpress]> select * from wp_options where
option_name='sticky_posts';
+-----------+--------------+--------------+----------+
| option_id | option_name | option_value | autoload |
+-----------+--------------+--------------+----------+
| 75 | sticky_posts | | yes |
+-----------+--------------+--------------+----------+
1 row in set (0.000 sec)
}}}
* Go to site editor, patterns, "List of posts without images, 1 column"
and duplicate it
* Edit the duplicate
* Navigate to the query loop block
* On the right sidebar, turn off "Inherit query from template"
* Change "Sticky Posts" from "Include" to "Exclude"
* Attempt to save
* A fatal error is triggered
* Changing the "Sticky Posts" back to "Include" or changing the option
value to a serialized array allows saving again
--
Ticket URL: <https://core.trac.wordpress.org/ticket/60276>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list