Make WordPress Core

Opened 7 months ago

Last modified 4 days ago

#64882 new defect (bug)

Twenty Fourteen's "featured" tag is being removed from posts

Reported by: poena Owned by:
Priority: normal Milestone: Awaiting Review
Component: Bundled Theme Version:
Severity: normal Keywords: good-first-bug has-patch
Cc: Focuses:

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 (3)

T14-Customize-Featured-Content-Tag.png​ (14.3 KB ) - added by sabernhardt 7 months ago.
The tag name also can be set to something other than "featured"
64882-editor-tags-before.png​ (19.7 KB ) - added by binsaifullah 4 days ago.
Block editor Tags panel on trunk: featured tag hidden
64882-editor-tags-after.png​ (15.1 KB ) - added by binsaifullah 4 days ago.
Block editor Tags panel with PR 13794: featured tag shown and kept on save

Download all attachments as: .zip

Change History (15)

#1 @poena
7 months ago

  • Keywords good-first-bug added

#2 @sabernhardt
7 months ago

The wp_is_serving_rest_request() function was not available until 6.5, so calling it would require a function_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() ) ) {

#3 @sabernhardt
7 months ago

The hide_featured_term() method also has an is_admin() check, but editing only hide_the_featured_term() seems sufficient.

Last edited 6 months ago by sabernhardt (previous) (diff)

@sabernhardt
7 months ago

The tag name also can be set to something other than "featured"

This ticket was mentioned in ​PR #11372 on ​WordPress/wordpress-develop by ​@roshniahuja14.


6 months 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 alongside is_admin() in both hide_featured_term() and hide_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

  1. Activate Twenty Fourteen theme
  2. Go to Appearance → Customize → Featured Content, set tag to "featured", enable "Hide tag"
  3. Create a post with the "featured" tag
  4. Open the post in block editor — the tag should be visible
  5. Save the post — the "featured" tag should be preserved
  6. Visit /wp-json/wp/v2/posts/{id} — tags array should include the featured tag ID

#5 follow-up: @roshniahuja14
6 months 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:

  1. Activate Twenty Fourteen theme
  2. Go to Appearance → Customize → Featured Content, set tag to "featured", enable "Hide tag from displaying in post details"
  3. Create a post with the "featured" tag
  4. Open the post in the block editor — the tag is missing from the Tags panel
  5. 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:


6 months 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.

​Test this pull request with WordPress Playground.

Tested in Playground and working fine.

#7 in reply to: ↑ 5 @hasnainashfaq
3 months ago

Replying to roshniahuja14:

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:

  1. Activate Twenty Fourteen theme
  2. Go to Appearance → Customize → Featured Content, set tag to "featured", enable "Hide tag from displaying in post details"
  3. Create a post with the "featured" tag
  4. Open the post in the block editor — the tag is missing from the Tags panel
  5. 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

Tested on trunk, patch works as expected.

​Syed-Ateeb-Raza commented on ​PR #11372:


8 weeks ago
#8

Hey! Tried testing this via Playground but the build artifact seems to have expired. Any chance you could rerun the CI job so we can get a fresh build? Want to test and submit a report on Trac.

#9 @karmatosed
3 weeks ago

  • Keywords needs-refresh added

#10 @devang100
9 days ago

Test Report

Description

This report validates whether the indicated patch works as expected.

Patch tested: ​https://github.com/WordPress/wordpress-develop/pull/11372

Environment

  • WordPress: 7.2-alpha-63166-src
  • PHP: 8.3.33
  • Server: nginx (wordpress-develop local Docker environment)
  • Browser: Chrome
  • OS: Windows 11
  • Theme: Twenty Fourteen
  • Plugins: None activated

Steps to Reproduce

  1. Activate Twenty Fourteen.
  2. Appearance > Customize > Featured Content: tag name featured, "Don't display tag on front end" enabled.
  3. Create a post in the block editor, add the featured tag, publish.
  4. Reload the editor.

Actual Results

  • Before patch: 🐞 The featured tag is removed from the post when it is saved in the block editor (bug reproduced).
  • After patch: ✅ The featured tag is kept after saving and reloading. /wp-json/wp/v2/posts/{id} includes the tag ID in tags.

Additional Notes

  • The PR branch is based on an older trunk, so I applied the PR's diff on top of current trunk (3e9e9d9cd1). It applied cleanly.
  • Separate issue found while testing (happens on trunk with and without this patch): with "Don't display tag on front end" enabled, the featured tag is still shown in the post's tag list on the front end.
    • Cause: Featured_Content::hide_the_featured_term() removes the term with unset( $terms[ $term->term_id ] );, but the array from get_the_terms() is indexed from 0, not by term ID, so nothing is removed.
    • hide_featured_term() already does this correctly with unset( $terms[ $order ] );.
    • Changing hide_the_featured_term() to unset( $terms[ $order ] ); hides the tag on the front end as expected (tested locally).
    • Happy to open a new ticket for this, or include it here if preferred.

This ticket was mentioned in ​PR #13794 on ​WordPress/wordpress-develop by ​@rishabhwp.


7 days ago
#11

  • Keywords needs-refresh removed

When "Don't display tag on front end" is enabled in Twenty Fourteen's Featured Content settings, the block editor can't see the featured tag. Saving a post removes the tag, and re-adding it creates a duplicate such as featured-2. The tag-hiding filters check is_admin(), which is false during the REST API requests the editor makes.

This PR:

  • Skips both filters (hide_featured_term() and hide_the_featured_term()) during REST API requests, using wp_is_serving_rest_request() when available (WordPress 6.5+).
  • Fixes hide_the_featured_term() unsetting terms by term ID instead of array index.

Trac ticket: https://core.trac.wordpress.org/ticket/64882

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Code Review

@binsaifullah
4 days ago

Block editor Tags panel on trunk: featured tag hidden

@binsaifullah
4 days ago

Block editor Tags panel with PR 13794: featured tag shown and kept on save

#12 @binsaifullah
4 days ago

Test Report

Patch tested: ​PR 13794

Environment

  • WordPress: 7.2-alpha (trunk)
  • PHP: 8.3 (local Playground-based server)
  • Theme: Twenty Fourteen 4.6 (Featured Content defaults: tag name featured, "Don't display tag on front end" enabled)
  • Browser: Chrome
  • OS: macOS
  • Plugins: none

Steps

  1. Create a published post with the tags featured and news-64882.
  2. Open it in the block editor, check the Tags panel, and save.
  3. Check the stored tags (Posts list table), the REST API, the homepage Featured Content area, and the single post's tag list.

Results

Check Trunk PR 13794
Tags panel in the block editor only news-64882 ❌ featured, news-64882 ✅
GET /wp/v2/posts/<id>?context=edit tags [4] (featured missing) ❌ [3, 4] ✅
GET /wp/v2/tags?search=featured [] ❌ returns featured (id 3) ✅
Stored tags after saving in the editor news-64882 (featured removed) ❌ featured, news-64882 ✅
Post in homepage Featured Content yes yes ✅
Single post tag list (hide tag enabled) shows featured ❌ only news-64882 ✅
Tag archive tag list — only news-64882 ✅

Both issues are fixed: the editor keeps the featured tag (original report), and unset( $terms[ $order ] ) in hide_the_featured_term() now hides the tag on the front end (the second issue found in comment:10).

Screenshots

Block editor Tags panel, trunk: Block editor Tags panel on trunk: featured tag hidden
Block editor Tags panel, PR 13794: Block editor Tags panel with PR 13794: featured tag shown and kept on save

Note

Because both filters now skip all REST requests, the featured tag is also returned to logged-out REST requests (/wp/v2/posts/<id> tags [3, 4], and /wp/v2/tags?search=featured), where trunk hid it. That seems fine, since the setting is about displaying the tag on the front end and the term isn't private. I'm mentioning it in case the maintainers want to keep it hidden for public REST requests (e.g. by limiting the skip to edit context).

Note: See TracTickets for help on using tickets.