-
-
Save devkabir/724033e4405403f1a58a806d3f96dc11 to your computer and use it in GitHub Desktop.
Admin Notices
This file contains hidden or 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
| 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 | |
| } |
This file contains hidden or 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
| add_action( 'wp_ajax_my_dismiss_acf_notice', 'my_dismiss_acf_notice' ); | |
| function my_dismiss_acf_notice() { | |
| update_option( 'my-acf-notice-dismissed', 1 ); | |
| } |
This file contains hidden or 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
| 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 | |
| } |
This file contains hidden or 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
| jQuery(document).on( 'click', '.my-acf-notice .notice-dismiss', function() { | |
| jQuery.ajax({ | |
| url: ajaxurl, | |
| data: { | |
| action: 'my_dismiss_acf_notice' | |
| } | |
| }) | |
| }) |
This file contains hidden or 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
| 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 ); | |
| } |
This file contains hidden or 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
| <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> |
This file contains hidden or 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
| add_action( 'admin_init', 'my_detect_acf' ); | |
| function my_detect_acf() { | |
| if( !function_exists( 'the_field' )) { | |
| delete_option( 'my-acf-notice-dismissed' ); | |
| } | |
| } |
This file contains hidden or 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
| 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' ); |
This file contains hidden or 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
| 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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment