Support

Account

Home Forums General Issues Include ACF Pro in premium theme

Solving

Include ACF Pro in premium theme

  • I would like to include ACF Pro into my premium theme. Is the Developer license required or can I include the plugin with a personal license?

  • The following page goes over the details of what you have to do to include it into your theme. You do not have to use the licensing system as it will not be installed through the plugins system but rather hard coded into your theme.

    The page also includes sample code to show you how to install it.

    I also have some sample code if you need it that will disable any existing copies of pro and make yours the highest priority preventing theirs from loading.

    https://www.advancedcustomfields.com/resources/including-acf-in-a-plugin-theme/

  • I have a follow-up question on this, as I’m currently developing a premium plugin that will include ACF PRO. I need to include PRO because one of my admin screens relies on a Repeater field.

    I started from the code sample in the link you provided, which I’m running in the plugins_loaded action.

    The problem is, if the site has ACF (the free version) installed and active, that takes precedence, my embedded version of PRO doesn’t load, and my Repeater field doesn’t appear on the admin screen.

    The only way I’ve been able to find to prevent free ACF from loading is to create a plugin in wp-content/mu-plugins containing:

    add_filter('option_active_plugins', function($plugins) {
    	$key = array_search('advanced-custom-fields/acf.php',$plugins);
    	if ($key !== false) {
    		unset($plugins[$key]);
    	}
    	return $plugins;
    });

    That’s a really ugly solution. I either have to ask users to put this file into their mu-plugins folder (which probably doesn’t exist), or I need to have my plugin write it to their file system itself (eek… I don’t want to do that).

    Is there another way to handle this that I’m missing?

  • I have a follow-up question on this, as I’m currently developing a premium plugin that will include ACF PRO. I need to include PRO because one of my admin screens relies on a Repeater field.

    I started from the code sample in the link you provided, which I’m running in the plugins_loaded action.

    The problem is, if the site has ACF (the free version) installed and active, that takes precedence, my embedded version of PRO doesn’t load, and my Repeater field doesn’t appear on the admin screen.

    The only way I’ve been able to find to prevent free ACF from loading is to create a plugin in wp-content/mu-plugins containing:

    add_filter('option_active_plugins', function($plugins) {
    	$key = array_search('advanced-custom-fields/acf.php',$plugins);
    	if ($key !== false) {
    		unset($plugins[$key]);
    	}
    	return $plugins;
    });

    That’s a really ugly solution. I either have to ask users to put this file into their mu-plugins folder (which probably doesn’t exist), or I need to have my plugin write it to their file system itself (eek… I don’t want to do that).

    Is there another way that I’m missing?

  • I have a follow-up question on this, as I’m currently developing a premium plugin that will include ACF PRO. I need to include PRO because one of my admin screens relies on a Repeater field.

    I started from the code sample in the link you provided, which I’m running in the plugins_loaded action.

    The problem is, if the site has ACF (the free version) installed and active, that takes precedence, my embedded version of PRO doesn’t load, and my Repeater field doesn’t appear on the admin screen.

    The only way I’ve been able to find to prevent free ACF from loading is to create a plugin in wp-content/mu-plugins containing:

    add_filter('option_active_plugins', function($plugins) {
    	$key = array_search('advanced-custom-fields/acf.php',$plugins);
    	if ($key !== false) {
    		unset($plugins[$key]);
    	}
    	return $plugins;
    });

    That’s a really ugly solution. I either have to ask users to put this file into their mu-plugins folder (which probably doesn’t exist), or I need to have my plugin write it to their file system itself (eek… I don’t want to do that).

    Is there another way to handle this that I’m missing?

    You mention “I also have some sample code if you need it that will disable any existing copies of pro and make yours the highest priority preventing theirs from loading”… is there any way you could share that here?

    Thank you!

  • I would probably handle this by showing an error message “notification” that the my plugin requires ACF Pro which is included with the plugin and ask them to deactivate the free version of ACF. I might also provide a link to allow the to deactivate the plugin in the notification. If I did this I would also build in some type of detection on my admin pages to reduce the functionality because some field types are missing.

    Alternately, if you want to be more forceful you could automatically deactivate the free version when your plugin is activated and then if your plugin is deactivated and the free version of ACF is available to activate it again.

  • Thanks… I tested out a variation on your “more forceful” idea after I posted this. I think mine is a bit too forceful at the moment though.

    Seems like it would be a good idea to add something about this to the documentation page linked above… especially since so many sites use ACF nowadays!

  • I generally don’t include ACF in anything I build, plugins or themes, and instead state that ACF Pro is required. Since I’m usually the one installing these plugins or themes then I just make sure what’s needed is there. But other times, for example my medium editor field plugin, I reduce the functionality of the plugin if the needed field types do not exists, for example in this plugin you can’t add custom buttons if the repeater field is not available. But I also don’t generally sell plugins or themes and only work for clients. If a client leaves I just deactivate the license and updates are up to them from that point on. Overall I’m not a big fan of plugins installed in/by themes or other plugins unless they are installed in a way that they can be updated independently.

    As far as adding to the documentation, you’d need to talk to the developer.

  • Sorry… I misinterpreted the “beaker” icon on your avatar and assumed you were an ACF representative.

    A little more detail for what it’s worth…

    This is my first commercial plugin; I mostly do client work, although I do have about a dozen free plugins in the WP Plugin Directory.

    I have to include ACF PRO in this plugin, at least at this point, because I have a custom post type with a bunch of custom fields, and building my own admin editing screens for those, vs. just including ACF PRO, was going to be prohibitively time-consuming. I don’t really like the idea of embedding another plugin in mine (as much as I like ACF!), but I verified my use of it conforms to ACF’s licensing requirements.

    I can’t really ask people who are buying my plugin to also buy another plugin in order to actually use it. Like I said… not my ideal arrangement but it will have to do for 1.0. If this thing really takes off and I can invest more time in it, I’ll probably build my own custom admin screens and remove ACF PRO from it.

  • 🙂 I just answer a lot of questions.

    I completely understand why you’re including ACF. I would have a hard time telling people that they need to buy another plugin as well if I were in your shoes.

  • Hey @room34, same problem here. Did you come up with a good solution?

  • Hey @room34, same problem here. Did you come up with a good solution?

  • Ha… well I came up with a solution.

    Let’s see… I kind of have to piece it back together. I got it working nearly a year ago and haven’t given it much thought since then.

    First, I’m using register_activation_hook() to check if ACF (free) is active. If it is, I’m copying a file into mu-plugins that contains the following, to deactivate ACF (free):

    
    add_filter('option_active_plugins', function($plugins) {
    	$key = array_search('advanced-custom-fields/acf.php',$plugins);
    	if ($key !== false) {
    		unset($plugins[$key]);
    	}
    	return $plugins;
    });
    

    That register_activation_hook() also generates an admin notice explaining that ACF (free) has been deactivated because my plugin includes ACF PRO. I also have a “Bypass ACF Check” option I created in my plugin’s settings, that will prevent this from running, so they can keep ACF (free) active if they really want to — but explaining this means they lose the ACF PRO features my plugin depends on.

    There’s a corresponding register_deactivation_hook() to delete my file from mu-plugins and re-activate ACF (free), although honestly I don’t think it’s working properly. (I haven’t prioritized fixing it because none of my users has yet complained about it!)

    So, that’s the first step, getting ACF (free) out of the way. Next we have to actually load the PRO version. I’m doing that with the plugins_loaded action, calling this function. (Actually it’s a method in my main class.)

    Note right away here that I’m checking to make sure the site doesn’t already have ACF PRO installed, because if it does I just use that and don’t load my own copy.

    
    		public function acf_init() {
    			// Only load our version of ACF PRO if the full version is not already installed on the site
    			if (!is_plugin_active('advanced-custom-fields-pro/acf.php')) {
    				include_once(plugin_dir_path(__FILE__) . 'vendors/acf/acf.php');
    				add_filter('acf/settings/url', function($url) {
    					return plugin_dir_url(__FILE__) . '/vendors/acf/';
    				});
    				// Hide ACF editing screens (EXCEPT if the site also has ACF free installed)
    				if (!file_exists(WPMU_PLUGIN_DIR . '/r34icspro-no-acf.php')) {
    					add_filter('acf/settings/show_admin', function($show_admin) {
    						return false;
    					});
    				}
    			}
    			// Add our ACF JSON loading path
    			add_filter('acf/settings/load_json', function($paths) {
    				$paths[] = plugin_dir_path(__FILE__) . 'assets/acf-json';
    				return $paths;
    			});
    		}
    

    Some of this may require some modifications (e.g. you may not have the assets/acf-json folder in your plugin, or you may have acf-json somewhere else, and your file in mu-plugins definitely won’t be called r34icspro-no-acf.php); I also stripped out some code that exists for a “dev mode” I have in my plugin.

    I think that’s the heart of it. Then the other big thing I would just recommend is that you should definitely stay on top of keeping your embedded ACF PRO version up-to-date! It isn’t critical for users who have their own version of ACF PRO, but if you’re knocking out their copy of ACF (free), then it’s on you to make sure they’re getting ACF updates. (Of course, some sites might be deliberately holding their versions back, and that’s not something I’ve accounted for here.)

  • Thank @room34, actually yours seems to be the most logical way to accomplish this task. But honestly this all sounds to me very, very “forceful” and doesn’t make me feel safe.
    So basically i’m rewriting everything by my own. It’s gonna take a while but my plugin will be totally indepenent.

    Thank you.

  • @Avamposto Yeah, I’m not totally happy with this as a solution but it’s only significant in situations where a site has both the free version of ACF and the paid version of my plugin. I’m not sure how often that happens. (I suspect most site owners who are paying for my plugin either have already paid for ACF PRO, or they don’t use ACF at all, but I don’t have any data to back that up.)

    Ultimately I want to do what you’re talking about — I plan to get my admin screens entirely self-contained so I don’t need to include ACF PRO with my plugin. It’s mostly just been a matter of time. This is a side project for me and since I’m still refining some elements of the editing screen, it’s faster for me to use ACF for that than to “roll my own” editor layout. But I feel like I will be ready to make that break sometime in the next few months.

    Good luck with your project!

Viewing 16 posts - 1 through 16 (of 16 total)

The topic ‘Include ACF Pro in premium theme’ is closed to new replies.