Programmatically setting ACF license key

EDIT – 2022-04-12

This code doesn’t actually work. I think it did while I was testing because of some glitches elsewhere. Instead, you can now just set the constant ACF_PRO_LICENSE.

You can use the following code to inject the Advanced Custom Fields Pro license key automatically:

add_filter(
    'pre_option_acf_pro_license',
    function ($value, $option, $default) {
        return base64_encode(
                serialize(
                    [
                        'key' => '...',
                        'url' =>  home_url(),
                    ]
                )
        );
    },
    10,
    3
);

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.