Opened 3 years ago
Closed 3 years ago
#51292 closed defect (bug) (fixed)
`wp_publish_post` does not add default category to auto-drafts
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.6 | Priority: | normal |
Severity: | normal | Version: | 2.1 |
Component: | Posts, Post Types | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
It's possible to publish a post without any categories by creating an auto-draft and then calling wp_publish_post
.
It looks like this can only happen by transitioning from an auto-draft via code. To reproduce:
<?php $post = wp_insert_post( /* status: auto-draft */ ); wp_publish_post( $post );
Expected behaviour: wp_publish_post()
should add the default category if no categories are set on the post.
Attachments (3)
Change History (11)
This ticket was mentioned in PR #527 on WordPress/wordpress-develop by peterwilsoncc.
3 years ago
#1
- Keywords has-patch has-unit-tests added
#2
@
3 years ago
- Milestone changed from Awaiting Review to 5.6
Moving the the 5.6 milestone as this will be required for #40351.
TimothyBJacobs commented on PR #527:
3 years ago
#3
Does this need to account for the new default_term
argument for custom taxonomies or are they not affected?
peterwilsoncc commented on PR #527:
3 years ago
#4
@TimothyBJacobs Nice catch, they are also affected. Further changes to come.
peterwilsoncc commented on PR #527:
3 years ago
#5
@TimothyBJacobs It does now, see 7c9a69b -- any further thought would be welcome.
#6
@
3 years ago
- Owner set to peterwilsoncc
- Status changed from new to assigned
In 51292.2.diff:
- Adds default terms for taxonomies if required in
wp_publish_post()
- Unit tests to ensure default terms are added
- Unit tests to ensure default terms do not override existing terms
- Tests to ensure term counts are modified accordingly. It could be argued that these tests do not belong on this ticket. Writing these tests for another ticket led me to discover this bug so that's why they are included.
Props due to @TimothyBlynJacobs for review on pull request.
#7
@
3 years ago
51292.3.diff incorporates final feedback from Timothy Jacobs and Fränk Klein. Committing once I can get confirmation on how to correctly props that latter.
Trac ticket: https://core.trac.wordpress.org/ticket/51292
This also includes the unit tests that will be required for scaling term counts but they probably should have existed all along and I couldn't find any that did.