123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- if ( ! defined( 'ABSPATH' ) ) {
- exit;
- }
- acf_register_store( 'notices' );
- if ( ! class_exists( 'ACF_Admin_Notice' ) ) :
- class ACF_Admin_Notice extends ACF_Data {
-
- var $data = array(
-
- 'text' => '',
-
- 'type' => 'info',
-
- 'dismissible' => true,
- );
-
- function render() {
- $notice_text = $this->get( 'text' );
- $notice_type = $this->get( 'type' );
- $is_dismissible = $this->get( 'dismissible' );
- printf(
- '<div class="acf-admin-notice notice notice-%s %s">%s</div>',
- esc_attr( $notice_type ),
- $is_dismissible ? 'is-dismissible' : '',
- acf_esc_html( wpautop( acf_punctify( $notice_text ) ) )
- );
- }
- }
- endif;
- function acf_new_admin_notice( $data = false ) {
-
- $instance = new ACF_Admin_Notice( $data );
-
- acf_get_store( 'notices' )->set( $instance->cid, $instance );
-
- return $instance;
- }
- function acf_render_admin_notices() {
-
- $notices = acf_get_store( 'notices' )->get_data();
-
- if ( $notices ) {
- foreach ( $notices as $notice ) {
- $notice->render();
- }
- }
- }
- add_action( 'admin_notices', 'acf_render_admin_notices', 99 );
- function acf_add_admin_notice( $text = '', $type = 'info', $dismissible = true ) {
- return acf_new_admin_notice(
- array(
- 'text' => $text,
- 'type' => $type,
- 'dismissible' => $dismissible,
- )
- );
- }
|