-
-
Save mattradford/6d5b8f3cd11ce1f62480 to your computer and use it in GitHub Desktop.
// 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' ); |
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.
Tried it but does not seems to work?
This is my version using @elliotcondon original code. It fires only on backend.
Please add it to your functions.php on your needs.
<?php
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() &&
!acf_pro_get_license_key()
) {
acf_pro_update_license(self::ACTIVATION_KEY);
}
}
}
new AutoActivator();
?>
My version, filtering on the get_option function for that specific option_name https://gist.github.com/polevaultweb/9cdf1b3bfeb054f13f221d4612bd8901
My version, filtering on the get_option function for that specific option_name https://gist.github.com/polevaultweb/9cdf1b3bfeb054f13f221d4612bd8901
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' );
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.