bobbingwide / field-block-for-acf-pro

Field block for ACF PRO
https://www.oik-plugins.com/oik-plugins/field-block-for-acf-pro/
GNU General Public License v2.0
3 stars 0 forks source link

Teething problems with v1.3.0 on s.b/cwiccer #24

Open bobbingwide opened 7 months ago

bobbingwide commented 7 months ago

field-block-for-acf-pro is now available from wordpress.org/plugins/field-block-for-acf-pro. It's the first version but I'm having problems with both ACF Pro and the block in s.b/cwiccer

ACF Pro version: 6.2.5 WordPress version: 6.4.1 PHP: 8.3

ACF Pro problem

ACF Pro is only displaying one Field group, which is currently the Testimonials group, and it's associated with Posts BUT when you edit a Post the other field groups are being displayed as well.

image

Note: When you hover over the Testimonials field group the settings icon is displayed. It's not available for the other field groups.

Block problem

The Display label field is not taking effect.

In s.b/cwiccer the HTML for the block is

Originally posted by @bobbingwide in https://github.com/bobbingwide/bobbingwide/issues/95#issuecomment-1999352950

bobbingwide commented 7 months ago

The "other" field groups are those with Sync available. There are twelve of them. Checkbox select, Choice and Clone Me show as being associated with Location Posts. The others are marked as Various

image

bobbingwide commented 7 months ago

Updating to ACF Pro v6.2.7 didn't resolve the issue. Nor did updating to WordPres 6.5-RC2

bobbingwide commented 7 months ago

The field problem could be that there's a field group called labelled_acf_field which contains a field Named display_label with Key field_65c0af48ebef0 and label Display label. This is used in preference to the display-label field which is defined using the code. It's a problem even when the field group is marked as Inactive.

I'll try deleting this Field group.

That worked.

With the label displayed:

image

Without the label:

image

bobbingwide commented 7 months ago

After Syncing the Advanced field group and toggling the value of Settings > Group Settings > Show in REST API the Location has changed to Posts. Toggling off the Show in REST API field doesn't stop the Meta box from being displayed.

I haven't yet worked out what causes the Location to display as Various. Marking the field group as Deactivated only works for Field groups that have been Synced.

I raised a ticket with WP Engine.

bobbingwide commented 7 months ago

OK, looking at the Field group .json files I've got a fairly good idea why some Groups are marked Post and others Various.

Field group Group last 3 digits Location Post type(s)
Advanced 969 Posts now contains post only
Basic b84 Various test-acf-fields
Content 558 Various block_example, test-acf-fields
Checkbox select e11 Posts post
Choice 183 Posts block_example, post

The group is shown as Various when the location only contains unknown post types. ie when none of the post types are registered.

"location": [
        [
            {
                "param": "post_type",
                "operator": "==",
                "value": "test-acf-fields"
            }
        ]
    ],

Obviously, since none of the post types are registered, the meta boxes aren't displayed.

bobbingwide commented 7 months ago

There's another problem with the field labelled Cycle Transition Effect, name fx, key field_645e28e9f47da

I don't know how this happens. There's something going haywire that's for sure.

bobbingwide commented 7 months ago

I don't know how this happens. There's something going haywire that's for sure.

In field_block_for_acf_pro_get_possible_field_names() the call to find the fields associated with each field group

$raw_fields=acf_get_fields( $field_group['ID'] );

was passing the ID of the field group. In some instances the ID of the field group was 0. The function was erroneously returning the fx field labelled Cycle Transition Effect.

I couldn't reproduce the problem just now. It would seem that having imported all the unsynched Field groups the IDs are all set.

I was able to reproduce the problem by deleting a row for post type acf-field-group from the wp_posts table. This then caused the Field group to require Syncing again. Since there was no post for the Field group the ID was 0

   [0] => Array

        [ID] => (integer) 0
        [key] => (string) "group_64abd48c9b969"
        [title] => (string) "Advanced"
        [fields] => Array
        [location] => Array

            [0] => Array

                [0] => Array

                    [param] => (string) "post_type"
                    [operator] => (string) "=="
                    [value] => (string) "post"

        [menu_order] => (integer) 0
        [position] => (string) "normal"
        [style] => (string) "default"
        [label_placement] => (string) "top"
        [instruction_placement] => (string) "label"
        [hide_on_screen] => (string) ""
        [active] => (boolean) 1
        [description] => (string) "Advanced type fields: 4 pickers, Date, Date-Time, Time, Color"
        [show_in_rest] => (integer) 0
        [local] => (string) "json"
        [modified] => (integer) 1710586908
        [local_file] => (string) "C:\apache\htdocs\cwiccer/wp-content/themes/fizzie/acf-json/group_64abd48c9b969.json"
        [_valid] => (boolean) 1

The logic failed when processing the acf/prepare_field/name=acf-field-name filter, within the_content,acf/prepare_field

It worked fine when called for acf/include_fields within init.

bobbingwide commented 7 months ago

The fx field labelled "Cycle Transition Effect" is created by the oik-testimonials plugin for the oik-testimonials/acf-cycler block.

    [0] => Array

        [ID] => (integer) 0
        [key] => (string) "field_645e28e9f47da"
        [label] => (string) "Cycle Transition Effect"
        [name] => (string) "fx"
        [aria-label] => (string) ""
        [prefix] => (string) "acf"
        [type] => (string) "select"
        [value] => (NULL) 
        [menu_order] => (integer) 0
        [instructions] => (string) ""
        [required] => (integer) 0
        [id] => (string) ""
        [class] => (string) ""
        [conditional_logic] => (integer) 0
        [parent] => (string) "group_645e28e943198"
        [wrapper] => Array

            [width] => (string) ""
            [class] => (string) ""
            [id] => (string) ""

        [choices] => Array

            [fade] => (string) "fade"
            [blindX] => (string) "blindX"
            [blindY] => (string) "blindY"
            [blindZ] => (string) "blindZ"
            [cover] => (string) "cover"
            [curtainX] => (string) "curtainX"
            [curtainY] => (string) "curtainY"
            [fadeZoom] => (string) "fadeZoom"
            [growX] => (string) "growX"
            [growY] => (string) "growY"
            [none] => (string) "none"
            [scrollUp] => (string) "scrollUp"
            [scrollDown] => (string) "scrollDown"
            [scrollLeft] => (string) "scrollLeft"
            [scrollRight] => (string) "scrollRight"
            [scrollHorz] => (string) "scrollHorz"
            [scrollVert] => (string) "scrollVert"
            [shuffle] => (string) "shuffle"
            [slideX] => (string) "slideX"
            [slideY] => (string) "slideY"
            [toss] => (string) "toss"
            [turnUp] => (string) "turnUp"
            [turnDown] => (string) "turnDown"
            [turnLeft] => (string) "turnLeft"
            [turnRight] => (string) "turnRight"
            [uncover] => (string) "uncover"
            [wipe] => (string) "wipe"
            [zoom] => (string) "zoom"

        [default_value] => (string) "fade"
        [return_format] => (string) "value"
        [multiple] => (integer) 0
        [allow_null] => (integer) 0
        [ui] => (integer) 0
        [ajax] => (integer) 0
        [placeholder] => (string) ""
        [_name] => (string) "fx"
        [_valid] => (integer) 1

The fix is to pass the $field_group structure to the call, not just the ID.

$raw_fields=acf_get_fields( $field_group );