Opened 4 years ago
Last modified 28 hours ago
#58223 new defect (bug)
Twenty Twenty: Fix post meta wrapper not rendering when action hooks add custom content without the default meta
| Reported by: | chiefastro | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.3 |
| Component: | Bundled Theme | Version: | |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: | template |
Description (last modified by )
There’s a bug in the Twenty Twenty theme in twentytwenty_get_post_meta. The bug prevents the action hooks twentytwenty_start_of_post_meta_list and twentytwenty_end_of_post_meta_list from displaying additional meta data when the default meta data fields are not populated.
The variable $has_meta must be true for any meta to be displayed. It is set to false initially and is only set to true if one of the default meta are provided. For single-bottom, if no tags are in the post, $has_meta will be false regardless of additional meta attempting to be displayed by the action hooks.
I solved the bug by defining $has_meta as a global inside twentytwenty_get_post_meta. From there, I was able to modify its value to true within my action hook function.
Hope this can be fixed in the published version of the theme so I don’t have to use a hacked version.
I posted on the theme support page and was asked to post a bug in this forum instead. Link to my theme support post: https://wordpress.org/support/topic/twentytwenty_end_of_post_meta_list-needs-global-has_meta/
Attachments (2)
Change History (16)
#2
@
3 years ago
- Keywords needs-patch added
- Summary twentytwenty_end_of_post_meta_list needs global $has_meta → Twenty Twenty: twentytwenty_get_post_meta needs global $has_meta
#3
@
3 years ago
I believe I just declared $has_meta as a global here:
<?php // If the post meta setting has the value 'empty', it's explicitly empty and the default post meta shouldn't be output. if ( $post_meta && ! in_array( 'empty', $post_meta, true ) ) { // Make sure we don't output an empty container. global $has_meta; $has_meta = false;
Then in my function that runs on the twentytwenty_end_of_post_meta_list action, I set it to True like this:
<?php $GLOBALS['has_meta'] = true;
This ticket was mentioned in PR #11769 on WordPress/wordpress-develop by @shreya0shrivastava.
6 months ago
#4
- Keywords has-patch added; needs-patch removed
twentytwenty_get_post_meta() uses a $has_meta flag to decide whether to return the meta wrapper HTML. This flag is only set to true when default meta fields (author, date, tags, etc.) are present. As a result, content added via thetwentytwenty_start_of_post_meta_list and twentytwenty_end_of_post_meta_list action hooks is silently discarded when no default meta exists — for example, on a post with no tags in the single-bottom location.
This fix checks whether the output buffer contains any content after stripping tags. The meta wrapper is now returned if either default meta or hook content is present.
Trac ticket: https://core.trac.wordpress.org/ticket/58223
## Use of AI Tools
Example disclosure:
AI assistance: Yes
Tool(s): Claude
Model(s): Opus 4.6
Used for: Initial code skeleton and PR description; final implementation and tests were reviewed and edited by me.
#5
@
6 months ago
Hi, I've submitted a patch for this issue.
The root cause is that $has_meta is a local flag that only flips to true when default meta fields are present, meaning the output buffer from the action hooks gets discarded when no default meta exists.
Rather than using a global (which would pollute the global namespace and create implicit coupling), the fix checks whether the output buffer contains any content after stripping tags, and returns the meta wrapper if either default meta or hook content is present.
Happy to make any changes based on feedback.
#6
@
3 months ago
- Milestone Awaiting Review → 7.2
- Summary Twenty Twenty: twentytwenty_get_post_meta needs global $has_meta → Twenty Twenty: Fix post meta wrapper not rendering when action hooks add custom content without the default meta
I think that PR 11769 would solve the issue without making $has_meta a global variable.
@chiefastro Could you confirm whether it fixes the theme for your site?
This ticket was mentioned in Slack in #core-test by huzaifaalmesbah. View the logs.
2 months ago
#10
@
6 weeks ago
Test Report
Patch tested: https://github.com/WordPress/wordpress-develop/pull/11769
Environment
- WordPress: 7.2-alpha-63166-src
- Subdirectory: No
- PHP: 8.3.35
- Server: nginx/1.31.6
- Database: mysqli (Server: 9.7.2 / Client: mysqlnd 8.3.33)
- Browser: Chrome 154.0.8037.58
- OS: macOS
- Theme: Twenty Twenty 3.2
- MU Plugins:
- Test Trac 58223 Repro
- Plugins: None activated
Steps taken
- Activate Twenty Twenty theme.
- Add hook to twentytwenty_end_of_post_meta_list echoing custom meta markup.
- Open single post without tags (e.g. /?p=1).
- Check the bottom of post content for the post meta wrapper and custom meta.
- ✅ Patch is solving the problem
Expected result
- Custom meta and wrapper are rendered at bottom of single post even without default post tags.
Screenshots/Screencast with results
- Before: before.png
- After: after.png
Support Content
- Reproduction mu-plugin (wp-content/mu-plugins/test-trac-58223.php):
<?php add_action( 'twentytwenty_end_of_post_meta_list', function( $post_id, $post_meta, $location ) { if ( 'single-bottom' === $location ) { echo '<li class="post-custom-meta meta-wrapper"><span class="meta-icon">📌</span> <span class="meta-text">Custom Hook Meta</span></li>'; } }, 10, 3 );
@karmatosed commented on PR #11769:
3 weeks ago
#11
This branch needs a refresh, if we can get that we can consider it.
@sabernhardt commented on PR #11769:
12 days ago
#12
The patch was refreshed.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Hi and thanks for the report!
Could you share how you added the global in your site?