Skip to content

Instantly share code, notes, and snippets.

@freezvd
Forked from thierrypigot/acf-missing.php
Created September 21, 2017 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save freezvd/d1604623431f3efc9c078f5700ff76df to your computer and use it in GitHub Desktop.
Save freezvd/d1604623431f3efc9c078f5700ff76df to your computer and use it in GitHub Desktop.
WordPress mu plugins to check if "Advanced Custom Fields Pro" is active.
<?php
if( !class_exists('acf') )
{
$tp_acf_notice_msg = __( 'This website needs "Advanced Custom Fields Pro" to run. Please download and activate it', 'tp-notice-acf' );
/*
* Admin notice
*/
add_action( 'admin_notices', 'tp_notice_missing_acf' );
function tp_notice_missing_acf()
{
global $tp_acf_notice_msg;
echo '<div class="notice notice-error notice-large"><div class="notice-title">'. $tp_acf_notice_msg .'</div></div>';
}
/*
* Frontend notice
*/
add_action( 'template_redirect', 'tp_notice_frontend_missing_acf', 0 );
function tp_notice_frontend_missing_acf()
{
global $tp_acf_notice_msg;
wp_die( $tp_acf_notice_msg );
}
}
else
{
/*
* Mask ACF in WordPress Admin Menu
* /!\ Change 'MY_USER_LOGIN_ON_THIS_WEBSITE' to your login
*/
add_action( 'plugins_loaded', 'tp_mask_acf' );
function tp_mask_acf()
{
$current_user = wp_get_current_user();
if( 'MY_USER_LOGIN_ON_THIS_WEBSITE' != $current_user->user_login )
{
define( 'ACF_LITE' , true );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment