Support

Account

Home Forums General Issues ACF Lite & ACF Plugin

Solving

ACF Lite & ACF Plugin

  • Similar to this problem I’m having problems including ACF lite in a plugin & activating ACF plugin.

    When I try activate the plugin I get the error…
    Fatal error: Cannot redeclare acf_filter_post_id() (previously declared in [..]/inc/advanced-custom-fields/core/api.php:21) in [..]/wp-content/plugins/advanced-custom-fields/core/api.php on line 65

    I’m using the !class_exists() function and it’s still throwing this error.

    WordPress & ACF are both up to date with the latest stable version.

    Thanks.

  • Hi @John Wilson

    Can you please elaborate more on what you mean by ‘ACF lite’?

    Thanks
    E

  • Hi,

    I’m trying to include ACF in a custom post type plugin. Which works fine, as does the location add-on.

    I’ve added to my code a ‘is_plugin_active’ check to not include the location add-on if the client has the plugin already installed which works fine.

    However, I’m trying to do the the same for ACF but it’s not working and throwing error above. I’ve tried plugin active & class exists checks but the issue remains.

    Regards,
    John

  • Hi @John Wilson

    Can you confirm that the if statement is working?
    I would assume that if it was working, there would be no PHP error as no file would be included.

    Thanks
    E

  • Hi Elliot,

    Yeah, the easiest was I could think to test it was working…

    if ( ! class_exists( 'Acf' ) ) {
    	//define( 'ACF_LITE' , true );
    	//include_once MY_PLUGIN_PATH . 'inc/advanced-custom-fields/acf.php';
    
    	echo "<p>This Works</p>";
    }

    Responds as it should. When the plugin is active, the echo doesn’t display. When it’s not active, the echo is displayed at the top of the screen.

    The same happens when I use the is_plugin_inactive() function. This function does work as it should the for the add-ons.

    Cheers,
    John

  • Hmmm.. I can’t explain it!

    Your code seems to be working, so your include_once should not be running.
    Is it possible that the function include_once can ignore any logic around it? Perhaps you should use just include?

    I would do some debugging in the included ACF file to see if it is being included. You can then work backwards from there

  • Another twist in the tale.

    This issue only happens when my plugin is activated first and then we try activate ACF.

    If we activate ACF, then try activate our plugin, everything works fine.

    How bizarre!

  • Hi @John Wilson

    So I think the issue is that you plugin is running first BEFORE the real ACF plugin.

    What you need to do is hook into the plugins_loaded action, and there you can include your ACF plugin. This will make sure any real ACF plugins are already initiated.

    I will do some work to make sure these issues do not happen in the future with better validation in the core for duplicate files.

    For now, however, this is your best bet.

    Cheers
    E

  • Same issue here 🙁

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

The topic ‘ACF Lite & ACF Plugin’ is closed to new replies.