Opened 2 weeks ago
Last modified 9 days ago
#64882 new defect (bug)
Twenty Fourteen's "featured" tag is being removed from posts
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Bundled Theme | Keywords: | good-first-bug has-patch |
| Focuses: | Cc: |
Description
Original issue: https://github.com/WordPress/gutenberg/issues/8544
Reported in 2018:
When used with the Twenty Fourteen theme, Gutenberg removes the featured tag that makes posts show up in the home page's Featured Content section. Attempts to re-add the featured tag result in new tags called featured, but with slugs such as featured-2 and featured-3, so that the posts still do not appear in Featured Content.
A workaround would appear to be to change the featured content tag name (in Customizer/Featured Content/Tag Name) to anything else and then to change it back to featured.
To Reproduce
Steps to reproduce the behavior:
Install WordPress 4.9.8 on development server.
Install and activate Twenty Fourteen theme (v2.2).
Create three posts, each with several tags, among which is featured.
The posts will now be visible in Featured Content on the Home Page.
Install the Gutenberg plugin.
In the Gutenberg editor, the featured tag will now be invisible. If each post is saved, it will lose its featured tag and status, disappearing from Featured Content.
If one attempts to re-add the featured tag inside the Gutenberg editor, a new tag named featured will be created with the slug featured-2, so that the post will not appear in Featured Content. Further attempts will result in featured-3, featured-4, etc.
Expected behavior
From the point of view of the Gutenberg editor, featured should just be a tag like any other. As far as I know, it's Twenty Fourteen that treats it as being special, and even that can be adjusted.
Additional context
Gutenberg v3.4.0
Today, Gutenberg does not have to be active for this problem to appear.
Testing instructions:
Install and activate Twenty Fourteen theme.
Create a post and add a tag called featured. See how when you save, this tag is not visible in the field in the block editor.
Save the post and view the homepage. Confirm that the post does not show at the top of the page, just below the header, with a black background (or featured image). Instead, it shows among the other posts in the blog.
Suggested solution:
In twentyfourteen\inc\featured-content.php, inside public static function hide_the_featured_term
locate:
// This filter is only appropriate on the front end.
if ( is_admin() ) {
return $terms;
}
And change it to
// This filter is only appropriate on the front end.
if ( is_admin() || wp_is_serving_rest_request() ) {
return $terms;
}
Test again and confirm that the post is now featured.
Attachments (1)
Change History (7)
#3
@
2 weeks ago
The hide_featured_term() method also has an is_admin() check, but editing only hide_the_featured_term() seems sufficient.
This ticket was mentioned in PR #11372 on WordPress/wordpress-develop by @roshniahuja14.
9 days ago
#4
- Keywords has-patch added; needs-patch removed
## Summary
- Fixes the "featured" tag being stripped from posts when saved in the block editor with Twenty Fourteen theme
- Added
wp_is_serving_rest_request()check alongsideis_admin()in bothhide_featured_term()andhide_the_featured_term()methods - Uses
function_exists()guard for backward compatibility with WordPress < 6.5
## Trac Ticket
https://core.trac.wordpress.org/ticket/64882
## Test Plan
- Activate Twenty Fourteen theme
- Go to Appearance → Customize → Featured Content, set tag to "featured", enable "Hide tag"
- Create a post with the "featured" tag
- Open the post in block editor — the tag should be visible
- Save the post — the "featured" tag should be preserved
- Visit
/wp-json/wp/v2/posts/{id}— tags array should include the featured tag ID
#5
@
9 days ago
I've submitted a pull request for this issue: https://github.com/WordPress/wordpress-develop/pull/11372
Changes:
- Added wp_is_serving_rest_request() check alongside is_admin() in both hide_featured_term() and hide_the_featured_term() methods in twentyfourteen/inc/featured-content.php
- Used function_exists() guard for backward compatibility with WordPress < 6.5
How to reproduce:
- Activate Twenty Fourteen theme
- Go to Appearance → Customize → Featured Content, set tag to "featured", enable "Hide tag from displaying in post details"
- Create a post with the "featured" tag
- Open the post in the block editor — the tag is missing from the Tags panel
- Save the post — the "featured" tag gets permanently removed
After the fix:
- The "featured" tag is visible in the block editor and preserved on save
- The REST API (/wp-json/wp/v2/posts/{id}) correctly returns the tag
- The tag remains hidden on the front end as intended
@roshniahuja14 commented on PR #11372:
9 days ago
#6
## Test using WordPress Playground
The changes in this pull request can previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.
### Some things to be aware of
- All changes will be lost when closing a tab with a Playground instance.
- All changes will be lost when refreshing the page.
- A fresh instance is created each time the link below is clicked.
- Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance, it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.
Tested in Playground and working fine.
The
wp_is_serving_rest_request()function was not available until 6.5, so calling it would require afunction_exists()check first. (The bug would remain with the older WordPress versions.)if ( is_admin() || ( function_exists( 'wp_is_serving_rest_request' ) && wp_is_serving_rest_request() ) ) {