WordPress: Check if plugin is installed (ACF)

Joe

I want to prevent fatal error in my theme if the ACF plugin is deactivated or not installed.

The main function of the plugin is get_field(). I wrote this code in my functions.php to check:

if ( !function_exists('get_field') ) {
  function get_field() {
    echo '<span>plugin ACF is not installed</span>';
  }
}

Please tell me this is acceptable practice?

Ihor Vorotnov

First of all, this is not the main plugin function, just one of them. Probably, most commonly used by a plugin user in a theme. Another one is the_field(), which actually prints value (get_field() returns it).

Regarding practice of defining your custom function - it's fine. However, I would not print that long message in every place where ACF field is expected - some of them may be short (numbers), and this message will break the layout. Printing something shorter is better, imo.

Also, function_exists is proper check, not is_plugin_active, because ACF can also be shipped as a library with a theme framework or other plugin.

Another option is to remove ACF dependency on the frontend completely. You can output the contents of the fields with get_post_meta() and prevent ACF plugin from loading on the frontend entirely. See these two posts for details:

http://www.billerickson.net/code/disable-acf-frontend/

http://www.billerickson.net/advanced-custom-fields-frontend-dependency/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

WordPress' ACF plugin: break at instructions field

ACF no rows found using wordpress advanced custom field plugin

Create a simple plugin to show ACF in wordpress posts (if they exists)

Wordpress: How to check is plugin active?

Plugin not working in Wordpress installed via Docker

Create a WordPress plugin that runs when another plugin is installed

Wordpress - First check page.php in plugin

wordpress pmpro plugin register field error check

How to Edit the Styles For an Installed WordPress Slider Plugin With CSS?

Wordpress - Display "Custom Author Role Name" - WP Members Plugin Installed

Gatsby: How do you get ACF (Advanced Custom Fields) to work with "gatsby-source-wordpress" plugin?

How do you style the admin/backend of the ACF (Advanced Custom Fields) Wordpress plugin?

ACF plugin - Wordpress: Not saving sets of sub fields in a repeater when I have several sets (about >150)

Wordpress ACF - Date format

WordPress query posts by ACF

WordPress ACF Checkbox loop

Horizontal scroll to, with wordpress acf

Wordpress - CPT and ACF Plugins

ACF and sidebar(WordPress)

Disable Wordpress HTTP request for theme and plugin check update

How to check a Wordpress plugin is activated in a Codeception acceptance test

How to check if the current page is a plugin admin panel in wordpress

How to check if wordpress W3 Total Cache plugin is active?

Repeater inside Group ACF Wordpress

Translate date (output ACF , wordpress)

Wordpress ACF Repeater Image resize

ACF not displaying in Wordpress Template Parts

ACF - Options page Hook (Wordpress)

Add /n to text in Wordpress (ACF)