Skip to content

Commit 70682e0

Browse files
committed
fix: resolve field_ prefix mismatch in compat layer for review CPTs
Review CPTs store block data with ACF field key format (field_pc_pros_list, field_acf_accord_groups, etc.) while post CPTs use bare field names (pc_pros_list, acf_accord_groups). The compat layer fallback only looked for bare names, causing acf/pros-cons and acf/accordion blocks to render empty on all 520+ review CPTs. Added field_ prefix fallback in: - acf_blocks_get_field(): simple field lookup - acf_blocks_get_repeater(): repeater name and sub-field name lookups Bump version to 2.1.7.
1 parent 9d1aa10 commit 70682e0

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

acf-blocks.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: ACF Blocks
44
* Plugin URI: https://github.com/wpgaurav/acf-blocks-plugin
55
* Description: A collection of ACF Pro blocks for the WordPress block editor with automatic field group registration.
6-
* Version: 2.1.6
6+
* Version: 2.1.7
77
* Requires at least: 6.0
88
* Requires PHP: 7.4
99
* Author: Gaurav Tiwari
@@ -19,7 +19,7 @@
1919
}
2020

2121
// Plugin constants
22-
define( 'ACF_BLOCKS_VERSION', '2.1.6' );
22+
define( 'ACF_BLOCKS_VERSION', '2.1.7' );
2323
define( 'ACF_BLOCKS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
2424
define( 'ACF_BLOCKS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
2525
define( 'ACF_BLOCKS_PLUGIN_FILE', __FILE__ );

includes/compat.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ function acf_blocks_get_field( $name, $block = array() ) {
3131

3232
// Fallback: read directly from block data.
3333
$data = $block['data'] ?? array();
34-
return $data[ $name ] ?? null;
34+
// Try bare field name first, then field_ prefixed key.
35+
// Review CPTs store data with field_ prefix (e.g. field_pc_pros_list)
36+
// while post CPTs use bare names (e.g. pc_pros_list).
37+
return $data[ $name ] ?? $data[ 'field_' . $name ] ?? null;
3538
}
3639

3740
/**
@@ -84,15 +87,23 @@ function acf_blocks_get_repeater( $name, $sub_names, $block = array() ) {
8487
if ( $count < 1 ) {
8588
// Fallback: parse nested row format (row-0, row-1, etc.)
8689
// ACF 6.7+ may store repeater data as nested arrays in block comments.
90+
// Try bare name first, then field_ prefix (review CPTs use field_ prefix).
91+
$repeater_data = null;
8792
if ( isset( $data[ $name ] ) && is_array( $data[ $name ] ) ) {
93+
$repeater_data = $data[ $name ];
94+
} elseif ( isset( $data[ 'field_' . $name ] ) && is_array( $data[ 'field_' . $name ] ) ) {
95+
$repeater_data = $data[ 'field_' . $name ];
96+
}
97+
if ( is_array( $repeater_data ) ) {
8898
$rows = array();
89-
foreach ( $data[ $name ] as $row_key => $row_data ) {
99+
foreach ( $repeater_data as $row_key => $row_data ) {
90100
if ( ! is_array( $row_data ) ) {
91101
continue;
92102
}
93103
$row = array();
94104
foreach ( $fields as $sub_name => $type ) {
95-
$value = $row_data[ $sub_name ] ?? null;
105+
// Try bare sub-field name, then field_ prefixed.
106+
$value = $row_data[ $sub_name ] ?? $row_data[ 'field_' . $sub_name ] ?? null;
96107

97108
switch ( $type ) {
98109
case 'image':

0 commit comments

Comments
 (0)