Skip to content

Instantly share code, notes, and snippets.

@danielpataki
Last active November 1, 2022 07:35
Show Gist options
  • Save danielpataki/dbb390434e184e8e3753 to your computer and use it in GitHub Desktop.
Save danielpataki/dbb390434e184e8e3753 to your computer and use it in GitHub Desktop.
Admin Notices
if( !function_exists( 'the_field' ) && empty( get_option( 'my-acf-notice-dismissed' ) ) ) {
add_action( 'admin_notices', 'my_acf_admin_notice' );
}
function my_acf_admin_notice() {
?>
<div class="notice error my-acf-notice is-dismissible" >
<p><?php _e( 'ACF is not necessary for this plugin, but it will make your experience better, install it now!', 'my-text-domain' ); ?></p>
</div>
<?php
}
add_action( 'wp_ajax_my_dismiss_acf_notice', 'my_dismiss_acf_notice' );
function my_dismiss_acf_notice() {
update_option( 'my-acf-notice-dismissed', 1 );
}
if( !function_exists( 'the_field' ) ) {
add_action( 'admin_notices', 'my_acf_notice' );
}
function my_acf_notice() {
?>
<div class="update-nag notice">
<p><?php _e( 'Please install Advanced Custom Fields, it is required for this plugin to work properly!', 'my_plugin_textdomain' ); ?></p>
</div>
<?php
}
jQuery(document).on( 'click', '.my-acf-notice .notice-dismiss', function() {
jQuery.ajax({
url: ajaxurl,
data: {
action: 'my_dismiss_acf_notice'
}
})
})
add_action( 'wp_enqueue_scripts', 'my_plugin_assets' );
function my_plugin_assets() {
wp_enqueue_script( 'my-notice-update', plugins_url( '/js/notice-update.js', __FILE__ ), array( 'jquery' ), '1.0', true );
}
<div class="updated notice">
<p>Something has been updated, awesome</p>
</div>
<div class="error notice">
<p>There has been an error. Bummer</p>
</div>
<div class="update-nag notice">
<p>You should really update to achieve some awesome instad of bummer</p>
</div>
add_action( 'admin_init', 'my_detect_acf' );
function my_detect_acf() {
if( !function_exists( 'the_field' )) {
delete_option( 'my-acf-notice-dismissed' );
}
}
function my_error_notice() {
?>
<div class="error notice">
<p><?php _e( 'There has been an error. Bummer!', 'my_plugin_textdomain' ); ?></p>
</div>
<?php
}
add_action( 'admin_notices', 'my_error_notice' );
function my_error_notice() {
?>
<div class="error notice">
<p><?php _e( 'There has been an error. Bummer!', 'my_plugin_textdomain' ); ?></p>
</div>
<?php
}
add_action( 'admin_notices', 'my_error_notice' );
function my_update_notice() {
?>
<div class="updated notice">
<p><?php _e( 'The plugin has been updated, excellent!', 'my_plugin_textdomain' ); ?></p>
</div>
<?php
}
add_action( 'admin_notices', 'my_update_notice' );
@allysonsouza
Copy link

There's a small typo in acf-notice.php line 7, "dismissible"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment