AdvancedCustomFields / acf

Advanced Custom Fields
http://advancedcustomfields.com/
823 stars 168 forks source link

BUG: Adding custom field settings to specific tab is not working if no field type is defined #853

Closed CreativeDive closed 11 months ago

CreativeDive commented 11 months ago

Hey,

I've noticed it's not possible to show field settings for a specific tab in the case there is no field type defined. I want to add a custom field setting for all field types, but this is not possible. Only if a field type is defined I can see my custom field setting for the specific tab.

Is not working:

add_action( 'acf/render_field_presentation_settings', function( $field ) {
    acf_render_field_setting( $field, array(...) );
});

Is working:

add_action( 'acf/render_field_presentation_settings/type=my_field_type', function( $field ) {
    acf_render_field_setting( $field, array(...) );
});
CreativeDive commented 11 months ago

A possible workaround for me is now the following way:

function acf_add_setting_to_presentation_tab( $field ) { 

    function add_setting( $field ) { 

        acf_render_field_setting( $field, array(...) );

    }

    $field_types = acf_get_field_types();

    foreach ( $field_types as $field_type ) {
        add_action( 'acf/render_field_presentation_settings/type=' . $field_type->name, 'add_setting' );
    }

}

add_action( 'acf/init', 'acf_add_setting_to_presentation_tab' );
lgladdy commented 11 months ago

It's not possible to use the legacy action names for new functionality.

You'll need to use the new actions, such as acf/field_group/render_field_settings_tab/presentation as detailed in the release notes: https://www.advancedcustomfields.com/resources/adding-custom-settings-fields/#custom-field-setting-tab

CreativeDive commented 11 months ago

Ahhhh, my bad. Thank you for clarification.

lgladdy commented 11 months ago

All good! Re-reading our docs we're not too clear on this, so I'll request this be clarified too!