So I am building a plugin for a site that is already using Advanced Custom Fields (ACF). I wonder what would be the best way to include ACF in my plugin? The site is already using ACF, so is it possible to include ACF from the plugin directory or should I include ACF again?
3 comments
Comments are closed.
If ACF (or any other plugin) is active on the site you do not need to include its files as they are all being included in the wordpress initialization process. The only tricky part is that you don’t know the order in which files are included and yours might be included before the ACF files are included, therefor you should probably wait for the
init
action or even later action before using it.Side note: ACF provides GUI for custom fields, but if you just need to use the data it is better not to rely on its API and query using the
get_post_meta
API. This will result in better software modularization and hopefully a more maintainable site.This information has been updated!
Please see ACF’s website:
https://www.advancedcustomfields.com/resources/including-acf-in-a-plugin-theme/
Well you would just check by if ACF class exists
if( !class_exists('acf') )
to check if a user has ACF installed already and if not then, fall-back on your version of ACF you would included along with your plugin or theme, settingACF_LITE
to “not” show ACF menu to the user…But if a user decides to install ACF themselves, it will override your version included with you plugin or theme as expected :).
Also. After you have made your fields and field group with ACF, export them to PHP using ACF’s export feature. Then include that exported PHP into you plugin/theme.
ACF is so powerful. And I am grateful for Elliott generosity of allowing us to even use PRO into making our plugins!
Am I doing it wrong, or do others find this clunky: http://www.advancedcustomfields.com/resources/getting-started/including-acf-in-a-plugin-theme/
So in order to include ACF in my plugin and hide ACF from users in the WP admin, I need to:
Or am I missing something?