Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
ACF5 Pro licence activation. Could be adapted for any other plugin that requires a licence key, but doesn't yet support defining it in wp-config. Fires on theme activation.
// Place this in wp-config
define( 'ACF_5_KEY', 'yourkeyhere' );
// Set ACF 5 license key on theme activation. Stick in your functions.php or equivalent.
function auto_set_license_keys() {
if ( ! get_option( 'acf_pro_license' ) && defined( 'ACF_5_KEY' ) ) {
$save = array(
'key' => ACF_5_KEY,
'url' => home_url()
$save = maybe_serialize($save);
$save = base64_encode($save);
update_option( 'acf_pro_license', $save );
add_action( 'after_switch_theme', 'auto_set_license_keys' );
Copy link

elliotcondon commented Nov 8, 2015

Will work for any plugin that requires a licence key?

If this is being used on premium themes or plugins, this is a major violation of the ACF terms and conditions.

Copy link

mattradford commented Nov 9, 2015

I agree, it would be a violation of the Ts & Cs if I was bundling ACF in a premium theme or plugin. But I would never do that; I respect your work and the licence under which it is offered, and only include ACF in bespoke WordPress builds for individual clients.

Will work for any plugin that requires a licence key?

Not in the sense of ACF being bundled in a plugin, but that the function could be adapted for AN Other plugin to add support for defining a licence key in wp-config.

This function was written in response to this thread requesting support for adding a licence key to wp-config. Gravity Forms and other plugins have this ability, which is a time saver when setting up lots of different environments.

Copy link

nlenkowski commented Mar 17, 2016

Several folks have posted on the thread @mattradford mentioned regarding this issue. @elliotcondon, any possibility of adding the ability to activate ACF Pro via config without using Matt's workaround? Thanks a ton for developing ACF by the way, it's made working with custom post types in WordPress a real pleasure.

Copy link

jordanmaslyn commented Oct 6, 2016

Have you ran into any issues with this when switching domains (e.g. local > staging > prod)?

It seems ACF checks to make sure the home_url that you saved is still the same as the current home_url, and so functionality to check for that and fix it if it's different is required.

Copy link

filipvanreeth commented Oct 13, 2016

Tried it but does not seems to work?

Copy link

teolaz commented Nov 29, 2016

This is my version using @elliotcondon original code. It fires only on backend.
Please add it to your functions.php on your needs.

class AutoActivator {
		const ACTIVATION_KEY = 'youractivationkeyhere';
		 * AutoActivator constructor.
		 * This will update the license field option on acf
		 * Works only on backend to not attack performance on frontend
		public function __construct() {
			if (
				function_exists( 'acf' ) &&
			    is_admin() &&
			) {
       new AutoActivator();

Copy link

polevaultweb commented Dec 17, 2018

My version, filtering on the get_option function for that specific option_name

Copy link

sasqik commented Mar 14, 2020

My version, filtering on the get_option function for that specific option_name

You should remember to give everybody know to add this in wp-config.php. Then it will work correctly.

// Place this in wp-config
define('ACF_PRO_LICENSE', 'yourkeyhere' );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment