#55176 closed defect (bug) (fixed)
if $stickies in function stick_post is not array, it should be empty array
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.0 | Priority: | normal |
Severity: | normal | Version: | 5.7 |
Component: | Posts, Post Types | Keywords: | has-patch has-unit-tests needs-testing |
Focuses: | Cc: |
Description
<?php if ( ! is_array( $stickies ) ) { $stickies = array( $post_id ); }
should change to
<?php if ( ! is_array( $stickies ) ) { $stickies = array(); }
Because of some reason, if we delete the sticky_posts option in wp_options, then we can never sticky a post, the following code always false:
<?php if ( ! in_array( $post_id, $stickies, true ) ) { $stickies[] = $post_id; $updated = update_option( 'sticky_posts', array_values( $stickies ) ); }
so it will never execute update_option. so we can't stick post.
Attachments (5)
Change History (18)
#3
@
3 years ago
- Version set to trunk
Hello there, thanks for the report, I'm able to reproduce the issue, the patch looks good too I think.
The code was introduced here: [50380] to fix duplicated post's id in stick_post option.
pinging @peterwilsoncc as he was spearhead this part of code.
#4
@
3 years ago
@SergeyBiryukov if you confirm the ticket, I think we can move it for 6.0 milestone.
#6
@
3 years ago
- Version changed from trunk to 5.7
Thanks for reporting this @denishua and providing the patches @azouamauriac.
It would be good to get some additional tests in to account for this situation as it was something I missed in #52007.
#8
@
3 years ago
- Keywords has-unit-tests added
@peterwilsoncc I've added some units tests. let me know if you need something more.
This ticket was mentioned in PR #2353 on WordPress/wordpress-develop by peterwilsoncc.
3 years ago
#9
#10
@
3 years ago
- Owner set to peterwilsoncc
- Status changed from new to assigned
Thanks for the tests @azouamauriac.
So I could ensure the tests were passing, I've created a pull request on GitHub and linked it to this ticket. This mainly to run the test suite before committing.
It combines 55176.4.diff and the tests in 55176.6.diff with some minor modifications:
- data provider removed for deleting the option, it's not needed
- added tests for various other incorrectly formed options
- Reduced the changes in
stick_post()
to a single line -- theif ( $stickies ) {
line didn't make sense so I had to guess your intent here - fixed a couple of minor PHP coding standards issues
peterwilsoncc commented on PR #2353:
3 years ago
#11
@costdev Would you be able to take a look at this PR, for some reason I can not assign you as a reviewer.
peterwilsoncc commented on PR #2353:
3 years ago
#13
Committed in https://core.trac.wordpress.org/changeset/53238
Adding blank array for
$stickies