Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save conorbarclay/ca8056d7a432c582d0c5b6d18d654794 to your computer and use it in GitHub Desktop.
Save conorbarclay/ca8056d7a432c582d0c5b6d18d654794 to your computer and use it in GitHub Desktop.
A forked and modified version of Bill Erickson's "Disable ACF Frontend" MU plugin that adds some extra checks for front-end requests.
<?php
/**
* Plugin Name: Disable ACF on Front-End
* Description: Provides a performance boost if ACF front-end functions aren't being used.
* Version: 1.0
* Author: Honeycomb Creative
* Author URI: https://www.billerickson.net/code/disable-acf-frontend/
* License: MIT
* License URI: http://www.opensource.org/licenses/mit-license.php
*/
/**
* This is a forked and modified version of Bill Erickson's
* "Disable ACF Frontend" (http://www.billerickson.net/code/disable-acf-frontend/).
*
* Adds some extra checks for front-end requests.
* For instance, plugins installed/deleted via WP CLI would (annoyingly) trigger ACF deactivation.
*
* @param array $plugins List of plugins.
*
* @return array
*/
function hny_disable_acf_on_frontend( $plugins ) {
if ( ! is_admin() && ! defined( 'WP_CLI' ) ) {
foreach ( $plugins as $i => $plugin ) {
if ( 'advanced-custom-fields-pro/acf.php' === $plugin ) {
unset( $plugins[ $i ] );
}
}
}
return $plugins;
}
add_filter( 'option_active_plugins', 'hny_disable_acf_on_frontend' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment