Skip to content

Global admin exclusion is causing issues #98

@jerome-rdlv

Description

@jerome-rdlv

I’m using an ACF repeater field (A) from an option page, to dynamically populate an ACF field (B) on a post edit page.

In that configuration, I’m not able to get default values from field A when on a post edit page, because \BEA\ACF_Options_For_Polylang\Main::get_default_value always excludes admin pages from default values fallback.

I remember having suggested to test for ajax years ago because front-end can do such calls that were excluded because being treated as admin one (the handler being wp-admin/admin-ajax.php) and that change had been adopted. But I now think that’s not proper.

I may be wrong, but I think that exclusion should only happen when editing values on an option page and nowhere else, because it’s the only place where default values don’t make sense, and where we need localized values to possibly be empty.

I’m having trouble interpreting that part of the code, and anticipating consequences of the change, but at least, it would be useful to have a filter here, for those adventurous like me, to be able to override the behavior.

I’m creating a pull request for that. And for information, here is the overriding logic I’m testing (with success):

add_filter('bea.aofp.get_default_enable', function ($enable) {
    if (array_key_exists($_REQUEST['page'] ?? null, acf_get_options_pages())) {
        // we are on an options page, do not get default values
        return false;
    }
    return true;
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions