0

First question on Stack.

I made a wordpress theme for a school project and I have a problem that I can't resolve alone.

I made a theme that needs ACF (there are some call get_field() and the_field() inside. But when I activate my theme I got some errors if acf is not enable. So I decide to find a solution and made a condition inside my functions.php

    if (!function_exists('get_field')) {
    function get_field()
    {
        return;
    }
}

if (!function_exists('the_field')) {
    function the_field()
    {
        return;
    }
}

So I add http://tgmpluginactivation.com/ inside my theme too to tell users that ACF is required with the possibility to install from my theme.

All is right for installation but when I want to activate the plugin :

Fatal error: Cannot redeclare get_field() (previously declared....)

I know that I previously declared get_field() and the_field() in my functions. But now, is it possible to erase my previous declaration with new ACF functions ?

I check before on stack board but I didn't find anything :(

Thanks a lot !

1
  • And I forgot to say "Hello" :(
    – Thibault
    Mar 2, 2020 at 11:48

1 Answer 1

1

Ok with helps it's working. So theme was ok in front of wordpress but wasn't able to load in the admin so we changed the previous condition by :

if (!function_exists('get_field') && !is_admin()) {
    function get_field()
    {
        return;
    }
    function the_field()
    {
        return;
    }
}

but same problem with activation in the admin and it was because I use acf in my functions.php too.

if (!empty(get_post(get_field('login', 'options')))) {

changed in :

if( get_option('login') ) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.