It’s no secret that adding in custom fields functionality to a premium theme (if you’re a premium theme developer) is sometimes a pain in the ass, especially if you’re not using some kind of third party custom fields framework.
The Advanced Custom Fields plugin for WordPress gives you unrivalled custom fields functionality for an alarmingly low price of $0. There is also the option of buying addons for the plugin which cost $25 each and allow for unlimited use/bundling with a plugin.
The plugins I strongly advise you buy are the Repeater Field and Flexible Content Field. I own all of the additional addons, at $25 they’re a steal but these are the two that you definitely need to buy (or if you’re on a budget the repeater field at the very least).
While ACF doesn’t support bundling out-of-the-box, the author Elliot Condon allows for the plugin to be embedded as well as your purchased premium addons without buying additional licences. Please note that you are not allowed to bundle premium plugins within a free theme or plugin, however if you are selling a theme or plugin, you are allowed as long as you stipulate to the end user that distributing the premium plugins is not allowed in any way.
So lets get too it.
You will want to visit the TGM Plugin Activation site and follow the prompts to download their handy and essential activation class, here. This class will allow us to bundle the ACF plugin in our premium theme.
Extract the file, “class-tgm-plugin-activation.php” and place it into the root directory of your theme: wp-content/themes/theme-name/
At the top of your functions.php file (located in the root directory of your theme) add this to the very top below the opening PHP tags:
This will include the activation class and lead us onto step #3.
At the bottom of your functions.php add in the following code (before the closing PHP tag, if you have one). This code does not factor in using premium functionality like the Repeater Field, Flexible Content Field or Options Field, but the code is essentially the same, just add however many additional array entries below to bundle. ACF 4 removed the functionality from the plugin and broke it out into separate plugins to comply with WordPress plugin repository rules.
After you’ve added in all required fields locally or on your staging environment, export them as PHP and paste in the exported code where the plugin tells you too. Voila, you’ve just bundled ACF with your theme and added in the needed fields.