Here’s how I do it: https://gist.github.com/jacobdubail/d5b5e76e6daca8a3258518fe710ed102
I just define my license key in my wp-config. You may want to add/tweak the action hooks this is added to so it runs in your situation.
That gist actually doesn’t solve the problem for me. For example, ACF is already licensed on my staging site, but when I do a database pull from the production site, the URL no longer matches and the license is invalidated.
A simple DEFINE in wp-config would be a better option in my case, I think!
+1 for being able to just set a config constant for the license key.
I have a shell script that uses wp cli to setup (or tear down) my development environments quickly and efficiently. ACF is one of the standard plugins I include in that process. WP Migrate DB Pro as well. DelicousBrains allows you to simply define a constant in the config file for the plugin license key. This allows me to easily add that constant via wp cli when creating the environment.
Needing to manually add the key for ACF is a step that would be nice to eliminate.
+1 for way to autosave the license key. It’s frustrating I need to constantly re-enter. Also, this means my ManageWP plugin update service does not work via ManageWP, so I need to log into ACF sites and manually do the plugin update, which negates the benefit of a service like ManageWP.
I agree but until then the following code snippet can be applied to a batch of sites via ManageWP’s code snippet feature. Just add in your key and bulk apply to all sites.
<?php $save = array( 'key' => "ACF_LICENSE_GOES_HERE", 'url' => home_url() ); $save = maybe_serialize($save); $save = base64_encode($save); update_option('acf_pro_license', $save); ?>
No it’s a one time run code which I deploy using: https://managewp.com/guide/manage/code-snippets. It has to be manually reapplied anytime the URLs change or the key get’s dropped for any other reason. Check out @jacobdubail comment for an example of how he uses it with an action hook. I got the idea from his code.
By the way, if this is being triggered by a WP Migrate DB Pro migration (as is the case for me), the following should prevent the key from being overwritten during a migration: https://gist.github.com/daltonrooney/470619cca87a6c29cb84f92d856b9ec1
Nice! That wpmdb_preserved_options gist should do the trick for me 90% of the time, and that ManageWP snippet looks handy… and like @daltonmadebyraygun-com , I gotta explore that feature more.
Still, placing the license key in the wp-config would be a nice way to set it and forget it at installation time.
+1000 for this feature. This is a regular source of frustration since I cannot automate my ManageWP updates until there is a solution for defining the ACF license key in code. This is the only plugin that gives me problems, and I need to constantly go and manually update. Thanks for your consideration. 🙂
Also, it seems like @elliot changed something because that snippet from @jacobdubail stopped working for me. It still populates the field for me but ACF still acts like the key isn’t entered when I go to update. I then have to deactivate the license key and activate all over again. Then ACF will update.
It’s like Elliot added a second value that the manual activation process creates in the DB and the plugin checks for before updating. Elliot, is there any possible way to do this and not violate what you’re trying to do with your plugin, business-wise? Or is that not an issue and I am just doing it wrong?
Any one else run into this?
FWIW, my answer that’s marked as the solution (even though it’s a workaround) has been fine deploying across multiple environments, including management with ManageWP, since ACF Pro 5 came out. There have been no issues.
Hey peeps, here’s a quick fix to add a licence key on theme activation: https://gist.github.com/mattradford/6d5b8f3cd11ce1f62480
It would be nice to have an official solution though.
@mattrad-8q962886d4 I’m pretty sure that’s the same snippet I’m using. It does work in the sense that the activation key is activated in the ACF backend, but ACF continues to act like it’s not when I update. I have to deactivate the key and reactivate it manually. It’s happening on all of my and my clients’ sites.
It was working for a while though. Not sure what changed.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2022 Advanced Custom Fields.