The following code checks if the ACF Pro or ACF plugins are not activated.
/* Checks to see if "is_plugin_active" function exists and if not load the php file that includes that function */
if ( ! function_exists( 'is_plugin_active' ) ) {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
/* Checks to see if the acf pro plugin is not activated */
if ( !is_plugin_active('advanced-custom-fields-pro/acf.php') ) {
/* Do something when not active */
}
/* Checks to see if the acf plugin is not activated */
if ( !is_plugin_active('advanced-custom-fields/acf.php') ) {
/* Do something when not active */
}
Side Note: if you want to use my previous code with the deactivate_plugins() function you should remove the “!” from the checks for the activated plugins in my previous code. Even though the comments in my previous code says it checks for if the plugin is activated, it actually checks if the plugin isn’t activated and then does whatever is inside the if statement. So removing the “!” will cause whatever is inside the if statement to run if the plugin is active.
Haven’t tried this myself but you should be able to deactivate the activated plugin by using deactivate_plugins() wordpress function
http://codex.wordpress.org/Function_Reference/deactivate_plugins
Once the plugin is deactivated you could load the one in your plugin.
Also might try changing:
require_once('/acf-pro/acf.php');
to:
require_once( plugin_dir_path( dirname(__FILE__) ) . 'acf-pro/acf.php' );
If you haven’t already figured this out try using dirname(__FILE__) instead of only __FILE__ when using plugins_url()
so instead of this:
plugins_url( '/acf-pro/', __FILE__ )
Try this:
plugins_url( '/acf-pro/', dirname(__FILE__) )
You need to write the logic into your plugin to find out if the plugin is already activated.
This should get you started:
/* Checks to see if "is_plugin_active" function exists and if not load the php file that includes that function */
if ( ! function_exists( 'is_plugin_active' ) ) {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
/* Checks to see if the acf pro plugin is activated */
if ( !is_plugin_active('advanced-custom-fields-pro/acf.php') ) {
/* load the plugin and anything else you want to do */
}
/* Checks to see if the acf plugin is activated */
if ( !is_plugin_active('advanced-custom-fields/acf.php') ) {
/* load the plugin and anything else you want to do */
}
I have the same error messages in my error log. Not sure what is causing the problem, everything still seems to work.
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!
🤔 Curious about the ACF user experience? So are we! Help guide the evolution of ACF by taking part in our first ever Annual Survey and guarantee you’re represented in the results. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 8, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.