0

Is it possible to add a function in functions.php like this:

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

and then let plugins that creates that function override my theme function? In this case I'm using Advanced Custom Fields, and id like to have a fail-safe, that won't create "function does not exist" errors, in case the plugin gets deactivated. So i'd like my theme to have a fallback for that same function.

Im assuming i might need to hook in somewhere, but I'm don't really know when.

If i do what i've done above then it won't allow me to activate Advanced Custom Fields, because now the functions already exists (in my theme).

Thanks

1 Answer 1

0

Try something like this:

if ( !function_exists('get_field') && $_REQUEST['action'] != 'activate' )

This will prevent your function being defined for the run where a plugin is actually being activated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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