diff --git a/notice-manager.php b/notice-manager.php index 0db4aaf..169bc42 100644 --- a/notice-manager.php +++ b/notice-manager.php @@ -7,10 +7,13 @@ * Author URI: https://github.com/abuyoyo/ * Plugin URI: https://github.com/abuyoyo/notice-manager */ -if ( ! defined('ABSPATH') ) wp_die( 'No soup for you!' ); +defined( 'ABSPATH' ) || die( 'No soup for you!' ); use WPHelper\PluginCore; +/** + * Print setting page + */ new PluginCore( __FILE__, [ @@ -31,7 +34,7 @@ new PluginCore( 'id' => 'screen_panel', 'title' => 'Notices Panel', 'type' => 'checkbox', - 'description' => 'Enable screen-meta-links \'Notices\' panel.', + 'description' => 'Enable\disable screen-meta-links \'Notices\' panel.', ], [ 'id' => 'auto_collect', diff --git a/src/NoticeManager.php b/src/NoticeManager.php index 40fe81d..811e6df 100644 --- a/src/NoticeManager.php +++ b/src/NoticeManager.php @@ -1,18 +1,22 @@ options = get_option( 'notice_manager'); - add_action( 'admin_enqueue_scripts' , [ $this , 'admin_enqueues' ] ); - if ( empty( $this->options['screen_panel'] ) ){ - array_walk($this->options,function(&$item){$item=0;}); - }else{ + if ( ! empty( $this->options['screen_panel'] ) ){ add_action( 'admin_init' , [ $this , 'register_notice_manager_panel' ] ); + }else{ + array_walk($this->options,function(&$item){$item=0;}); } } @@ -39,7 +42,15 @@ class NoticeManager{ wp_localize_script( 'notice_manager_panel', 'noticeManager', camelCaseKeys($this->options) ); wp_enqueue_style( 'admin_notices', NOTICE_MANAGER_URL . 'css/admin_notices.css' ); } - + + + /** + * Register screen-meta-links panel on all pages + * + * @hook admin_init + * + * @uses screen-meta-links-api library + */ function register_notice_manager_panel(){ if ( ! function_exists( 'add_screen_meta_link' ) ) return; @@ -53,7 +64,6 @@ class NoticeManager{ [ $this , 'print_notice_manager_panel' ] // $panel callback - cb echoes its output ); - } /* not JSON-safe - unescaped quotes */