acf-extended / ACF-Extended

🚀 All-in-one enhancement suite that improves WordPress & Advanced Custom Fields
https://www.acf-extended.com
238 stars 27 forks source link

Repeaters are forced to use stylized button when created with acf-builder #128

Open mindfullsilence opened 1 month ago

mindfullsilence commented 1 month ago

Describe the bug Repeater fields show the "Stylized Button" described here when created with acf-builder, regardless of setting true, false, or not setting at all.

To Reproduce Create a repeater via acf-builder programmatically:

$builder = new FieldsBuilder('some-group');
$builder
  ->addRepeater('my_repeater');
  // ->setConfig('acfe_repeater_stylised_button', 0) has no effect

$builder->addLocation('post_type', '==', 'page');

acf_add_local_field_group($builder->build());

Expected behavior Should be able to turn on/off this configuration per repeater field by setting its value to true or false.

WordPress & ACF WordPress version: 6.5.5 ACF Pro version: 6.3.3 ACF add-ons:

Related file (I think this is where the issue is): field-repeater.php#L61-63

// Currently this
if(isset($field['acfe_repeater_stylised_button'])){
    $wrapper['data-acfe-repeater-stylised-button'] = 1;
}

// Should probably be this
if(isset($field['acfe_repeater_stylised_button'])){
    $wrapper['data-acfe-repeater-stylised-button'] = $field['acfe_repeater_stylised_button'];
}

Current workaround I'm using in theme functions.php:

add_filter('acf/load_field/type=repeater', function($field) {
    unset($field['acfe_repeater_stylised_button']);

    return $field;
}, 10, 1);
acf-extended commented 1 month ago

Hello,

Thanks for the feedback!

In fact, good catch. The setting should respect the defined value. I'm adding it to the next patch.

Thanks again for the report, and sorry for the inconvenience.

Regards.

mindfullsilence commented 1 month ago

Thanks! Excellent plugin, btw. My admin is just so dang clean now :D

acf-extended commented 1 month ago

Hello,

Just a heads up to let you I think there was a misunderstanding.

I checked the code, and it is actually correct. There is no reason for the Stylised Button to show unless you specifically set acfe_repeater_stylised_button = true. By default it is set to false, so it won't show up.

The code is pretty straight forward:

if($field['acfe_repeater_stylised_button']){
    $wrapper['data-acfe-repeater-stylised-button'] = 1;
}

Which means: if acfe_repeater_stylised_button is true or has any value other than false, then display the Sylised Button.

I'm not sure if the issue come from acf-builder (which might automatically set it to true), or if you have a custom code/hook somewhere which does that.

This code also disable it, but it is not needed, since it's the default behavior:

add_filter('acf/load_field/type=repeater', function($field){

    $field['acfe_repeater_stylised_button'] = false;

    return $field;

});

Regards.