Skip to content

Instantly share code, notes, and snippets.

@broskees
Last active August 24, 2023 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save broskees/c6b418a502228ee45f7e917a5972698c to your computer and use it in GitHub Desktop.
Save broskees/c6b418a502228ee45f7e917a5972698c to your computer and use it in GitHub Desktop.
Force Site to use ACF to Function (MU-Plugin)
<?php
! defined('ABSPATH') && exit;
add_action('plugins_loaded', function () {
if (// is network install and main site is not set up
(is_multisite() && ! get_blog_option(1, 'siteurl'))
// is single site install and site is not set up
|| (! is_multisite() && ! is_blog_installed())
// ACF is already installed
|| class_exists('ACF')
// is WP CLI
|| (defined('WP_CLI') && WP_CLI)
) {
return;
}
$notice = 'ACF is required for this site to function properly. Please install and activate the plugin.';
// should die unless user is admin or on login page
if (! current_user_can('install_plugins') && ! is_login()) {
wp_die($notice);
}
add_action('admin_notices', function () {
echo sprintf(
'<div class="notice notice-error"><p>%s</p></div>',
$notice
);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment