Last active
December 28, 2020 15:43
-
-
Save gregoirenoyelle/beff0f3733ac06ce326cfca04050450c to your computer and use it in GitHub Desktop.
ACF check
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 | |
// A placer dans le fichier functions.php de votre thème | |
//* Contrôle si Advanced Custom Field est actif sur le site | |
if ( ! function_exists( 'get_field' ) ) { | |
// Variable pour URL de la page Extension | |
function page_plugin_redirect() { | |
return get_bloginfo('url') . '/wp-admin/plugins.php'; | |
} | |
// Notice dans le back-office au moment de la désactivation | |
add_action('admin_notices','gn_warning_admin_missing_acf'); | |
function gn_warning_admin_missing_acf() { | |
$output = '<div id="my-custom-warning" class="error fade">'; | |
$output .= sprintf('<p><strong>Attention</strong>, ce site ne fonctionne pas sans l\'extension <strong>Advanced Custom Fields</strong>. Merci <a href="%s">d\'activer l\'extension</a>.</p>', page_plugin_redirect()); | |
$output .= '</div>'; | |
echo $output; | |
} | |
// Notice dans le front qui masque tout le contenu et affiche le lien pour ce connecter | |
add_action( 'template_redirect', 'gn_template_redirect_warning_missing_acf', 0 ); | |
function gn_template_redirect_warning_missing_acf() { | |
wp_die( sprintf( 'Ce site ne fonctionne pas sans l\'extension <strong>Advanced Custom Fields</strong>. Merci <a href="%s">d\'activer l\'extension</a>.', page_plugin_redirect() ) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment