Home › Forums › Bug Reports › Multiple Include Conflicts
Hi Elliot,
Since themeforest now requires plugin functionality to be put in plugins (thank goodness) we would like to include ACF and all plugins in both. We would like to do this because even if the user deactivates the plugin we’d like the theme options to be available.
Since the options page plugin and the gallery plugin has functions outside the main class they are in this is causing some issues. Would it be possible to encapsulate these functions into the classes? We can check for the existence of a class before we do the include in the theme but this will fail on plugin activation because of the order in which hooks are fired.
We basically just want to do this from the theme and the plugin (the paths are different of course).
include_once('includes/acf/advanced-custom-fields/acf.php' ); include_once('includes/acf/acf-repeater/acf-repeater.php' ); include_once('includes/acf/acf-options-page/acf-options-page.php' ); include_once('includes/acf/acf-flexible-content/acf-flexible-content.php' ); include_once('includes/acf/acf-gallery/acf-gallery.php' ); include_once('includes/acf/acf-typography/acf-typography.php' );
In our specific case we can get around this easily by checking if our own plugin is active. However, as ACF begins to spread this may cause issues if others are including it as well 🙂
Thanks for the help!
Daniel
Sorry mate, I’m a bit confused abotu this one. Can you elaborate a bit more on the issue and what the solution would look like?
In the latest builds, I have re-written how ACF is instantiated to make sure that even if multiple ACF plugins are included, only 1 object is ever created.
Perhaps the solution is to simply include ACF in your theme always, and if the user has the plugin also activated, your theme include will not conflict as ACF will know not to create another ACF object
Thanks
E
Hi Elliot,
I may not have been clear on this one. The issue is not with the core plugin, it’s with the addons, specifically the gallery and the options page.
If you only include the base plugin all is well because it’s one big class and before the class you’ve added this check:
if( !class_exists('acf') ):
If I want to include the repeater field addon all is well again because I include the acf-repeater.php file which has this check:
if( !function_exists('acf_register_repeater_field') ):
However, the gallery and the options page addon does not have this check so it can not be included with a simple include.
I hope that makes it a bit clearer, let me know if I’m just being thick 🙂
Daniel
Thanks for clarifying.
The gallery field add-on, contains a function called “acfgp_register_fields” and the options page add-on contains a class called “acf_options_page_plugin”.
You can use these in if statements to check if they are included or not.
Hope that helps.
Thanks
E
Hi Elliot,
That’s fine as well, it’s not a matter of not being able to include, it’s more an issue of future-proofing things. If the check is contained within the addon then there’s no chance of getting tangled up in someone else’s sloppy coding 🙂
On our end we’re fine, as you said, checking for the class will do it 🙂
Thanks,
Daniel
The topic ‘Multiple Include Conflicts’ is closed to new replies.
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.