Sam
Sam

Reputation: 356

Difference between class_exists and function_exists?

When using plugin functions in themes, is it best practice to use class_exists or function_exists?

Example :

If i'm using ACF functions in my theme, should i use :

if ( class_exists('acf') )

or

if function_exists('the_field') )

Upvotes: 0

Views: 283

Answers (2)

kenvilar
kenvilar

Reputation: 21

Using class_exists is enough to check if the ACF plugin is active. It is also better to use namespaces.

Upvotes: 0

Tigran Babajanyan
Tigran Babajanyan

Reputation: 2025

For check if function exists you must use function_exists() exactly, class_exists() checks if class exists.

http://php.net/manual/en/function.function-exists.php

Upvotes: 2

Related Questions