Opened 3 years ago
Last modified 3 days ago
#58223 new defect (bug)
Twenty Twenty: twentytwenty_get_post_meta needs global $has_meta
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Bundled Theme | Keywords: | has-patch |
| Focuses: | template | Cc: |
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/
Change History (5)
#2
@
3 years ago
- Keywords needs-patch added
- Summary changed from twentytwenty_end_of_post_meta_list needs global $has_meta to 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.
3 days 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
@
3 days 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.
Hi and thanks for the report!
Could you share how you added the global in your site?