Repository navigation
Open
Labels
focus: blocksGutenberg editor blocks and frontend renderingtype: bugSomething is not working or broken
Description
Describe the Bug
The Dynamic Content toolbar popover (admin/dynamic-content/toolbar/dynamicContentPopover.js) and its backend AJAX handler (includes/Admin/Ajax/BlocksAjax.php) have several bugs that prevent dynamic fields from working:
- Missing JSON responses in
BlocksAjax::get_post()(includes/Admin/Ajax/BlocksAjax.php, lines 176–233):- While
post_title,post_excerpt,featured_image,post_date, andpost_timecallHelper::json_success($data), all remaining cases (post_custom_field,post_terms,post_id,comments_number,author_name,author_first_name,author_last_name,author_nickname,author_bio,author_email,author_website,author_avatar_image_url, andauthor_custom_field) usereturn ...;instead ofHelper::json_success(...). - In WordPress
admin-ajax.php, returning a value from an action callback without callingwp_send_json_*outputs0, so the frontend receives an empty/failed response.
- While
- Unsafe property access on
Helper::get_single_field()(BlocksAjax.php, lines 202, 222, 225, 229):Helper::get_single_field($post_id, 'comment_count')returns a scalar value ($post->$field_name), not an object, yet lines 202, 222, 225, and 229 access->comment_countand->post_authoron the scalar return value, causing PHP warnings (Attempt to read property on string) and returningnull.
- Typo in
hasChangescheck (admin/dynamic-content/toolbar/dynamicContentPopover.js, line 59):initialValuesstores{ dataSource, sourceField, ... }, buthasChangeschecksdataSource !== initialValues.item(initialValues.itemis alwaysundefined), causinghasChangesto always evaluate totrue.
Steps to Reproduce
- Open the Block Editor and select a block with the Frontis Dynamic Content toolbar button.
- Choose Data Source: Post Type, select a post, and select Author -> Name (or Post -> Comments Number / Post ID).
- Click Apply.
- Observe that
admin-ajax.phpreturns0(or triggers a PHP warning trying to read->post_authoron a string) and the block content is not updated.
Expected Behavior
- Every
source_fieldbranch inBlocksAjax::get_post()should return a structured JSON response viaHelper::json_success([$source_field => $value]). Helper::get_single_field($_POST['post_id'], 'post_author')and'comment_count'should be used directly as scalar values without dereferencing->post_authoror->comment_count.dynamicContentPopover.jsshould comparedataSource !== initialValues.dataSourceand handle all returned field keys when updating the block content.
Affected Block or Component
Core Plugin / General
WordPress Version
6.7
PHP Version
8.2
Metadata
Metadata
Assignees
Labels
focus: blocksGutenberg editor blocks and frontend renderingtype: bugSomething is not working or broken
Activity