During the process of supporting a Meta Box user, we were taught a way to help manage license keys more optimally and intelligently, especially when managing multiple client sites. It’s using the MainWP Code Snippets Extension. I will share that in this article. You can refer and apply it to your work, for Meta Box, and other plugins as well. Everything will be automatic.
Traditional Method to Add/Remove a License Key
Normally, when you want to add a license key to a site, you need to go to your account page on metabox.io, copy the license key, then enter it in Meta Box > License page on your site.
Then, if you want to remove the key, just delete it on the managing licenses page on metabox.io only. All steps are done manually.
This might seem normal, but imagine you're an agency and you manage dozens, hundreds, or even thousands of sites. Adding and removing licenses like that would need to be repeated many times. This is time-consuming and not optimal.
So, what can we do?
Using Code Snippets to Manage Keys
To not be affected when changing the theme, we’ll use a third-party plugin which is MainWP Code Snippets Extension. It’s available in the Pro Bundle of MainWP ($199/year).
This extension allows you to add code snippets to your child sites from one centralized location. You can add, manage, and especially, execute PHP code snippets from a single location – your MainWP Dashboard. It brings a tool to manage child sites via PHP code like synchronizing plugin settings, updating widgets, or retrieving posts. But, in this blog, we will focus on only the license key management.
In essence, MainWP provides a central place which helps us synchronize code between the server and child sites. Then, you can control everything remotely.
So, how to use MainWP to add a license key of Meta Box to a child site?
You might know that Meta Box allows you to define the license key via a constant in wp-config.php
. Actually, the constant can be defined elsewhere, not necessary in wp-config.php
. You can use a code snippet plugin to define it. That's where the magic of MainWP Code Snippets!
Follow the steps below to add a license key of Meta Box right on the server and sync it to all your child sites:
- Step 1: Go to Extensions > Code Snippets, or Sites > Developments > Code Snippets. Then, there is an area to input a snippet.
- Step 2: Add the following snippet:
<?php /** * Set the license key for Meta Box AIO. */ define('META_BOX_KEY', 'your_license_key');
- Step 3: Choose the site you want to apply this code by checking
- Step 4: Select the first option in the Snippet Type section, then, save and execute the snippet.
That’s all.
Then, check your site, you can see the Meta Box plugin work well with the active license.
Benefits
With this method, you can automatically install or update license keys for client websites quickly and simultaneously.
When a client stops collaborating or transfers website management to another party, you also can remotely remove the license keys, ensuring that the client no longer has access to the services or plugins provided by the license keys.
The management is also more flexible. When you have a large number of websites, using Code Snippets via MainWP to add or remove license keys across multiple sites without having to log in to each site and perform manual operations.
In addition, it offers high customizability for managing code. It means that you can add conditions to the code to control how the license keys are used. As well as, define constants or integrate with other code snippets to easily add/remove license keys without needing to change many configurations on the website.
We think that this feature is a strong point of MainWP.
Notes
Before considering whether to use it, I have three notes to remind you about this method.
First, Code Snippet may store constants in its options, which can be cached. So if you use an object cache for your site like Redis or Memcached, it's recommended to clear the cache.
Using Code Snippet also can lead to conflicts with other code or plugins, especially if the code interacts in complex ways. This could result in unexpected errors or impact the functionality of the website.
Last but not least, this tool is recommended for advanced users only. We only recommend utilizing it if you are an experienced PHP coder.
Conclusion
In summary, using MainWP Code Snippets Extension to manage license keys can be convenient in some cases, but there are technical and security limitations that you should carefully consider. Just choose the method that fits you.
What do you think about this tip, and do you want to share any tips for our user community? Leave them in the comment below.