Support

Account

Home Forums Backend Issues (wp-admin) acf_render_field_setting() position in form

Solved

acf_render_field_setting() position in form

  • I need the ability to set READ_ONLY based on user roles/capabilities.

    I have the code working just fine. However, my field is rendered in the field options form just after the “required” button. And I want it rendered farther down the form (preferably before “Conditional Logic”).

    I tried changing the priority for my add_action() call, but that doesn’t seem to affect things.

    I am “guessing” that general/generic “acf/render_field_settings” actions are rendered before all of the individual field types are rendered. So the only way to get my item farther down the form is to create an add_action() for every single field type instead of using the “acf/render_field_settings” action.

  • Yes, this is true. The generic acf/render_field_settings hook is only fired at the beginning. I know that the developer at least knows about this because I’ve brought it up on github, but I do not know the status of this. I’ve worked out my own solution. I would suggest opening a support ticket https://support.advancedcustomfields.com/new-ticket/

    I solve it by adding the action to every field type for now…. and this is also a little dependent on the version of ACF, 5.5.* stored the fields a bit differently. this is the relevant code from one of my plugins.

    
    $function = 'name of function to call';
    $priority = 1; // change to 20 for bottom of settings
    
    $acf_version = acf_get_setting('version');
    
    $sections = acf_get_field_types();
    
    if (version_compare($acf_version, '5.5.0', '<') || 
        version_compare($acf_version, '5.6.0', '>=')) {
      foreach ($sections as $section) {
        foreach ($section as $type => $label) {
          add_action('acf/render_field_settings/type='.$type, $function, $priority);
        }
      }
    } else {
      // >= 5.5.0 || < 5.6.0
      foreach ($sections as $type => $settings) {
        add_action('acf/render_field_settings/type='.$type, , $function, $priority);
      }
    }
    

    EDIT: You’ll want to do this on ‘acf/init’ or on ‘init’ with a high priority

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.