Last active
September 3, 2024 14:58
-
-
Save broskees/c6b418a502228ee45f7e917a5972698c to your computer and use it in GitHub Desktop.
Force Site to use ACF to Function (MU-Plugin)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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', fn () => printf( | |
'<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