misc - cleanup + notes

misc - cleanup + notes
This commit is contained in:
abuoyoyo 2022-05-31 02:01:32 +03:00
parent 7ca0ba6ed2
commit 1e08767b87
2 changed files with 24 additions and 11 deletions

View File

@ -7,10 +7,13 @@
* Author URI: https://github.com/abuyoyo/ * Author URI: https://github.com/abuyoyo/
* Plugin URI: https://github.com/abuyoyo/notice-manager * 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; use WPHelper\PluginCore;
/**
* Print setting page
*/
new PluginCore( new PluginCore(
__FILE__, __FILE__,
[ [
@ -31,7 +34,7 @@ new PluginCore(
'id' => 'screen_panel', 'id' => 'screen_panel',
'title' => 'Notices Panel', 'title' => 'Notices Panel',
'type' => 'checkbox', 'type' => 'checkbox',
'description' => 'Enable screen-meta-links \'Notices\' panel.', 'description' => 'Enable\disable screen-meta-links \'Notices\' panel.',
], ],
[ [
'id' => 'auto_collect', 'id' => 'auto_collect',

View File

@ -1,18 +1,22 @@
<?php <?php
/** /**
* NoticeManager class * NoticeManager class
*
* @todo Maybe rename plugin and class to Notice-Collector
* @todo Fix regression - notice tab click not closing on first click (next time - backup first!)
* @todo Maybe make separate wp-admin-notice-register class (core API demo plugin)
*/ */
if ( ! defined('ABSPATH') ) wp_die( 'No soup for you!' ); if ( ! defined('ABSPATH') ) wp_die( 'No soup for you!' );
/** /**
* @todo If no notices on page - don't show Notice Manager panel * NoticeManager class
*/ */
class NoticeManager{ class NoticeManager{
/** /**
* Options * Options
* *
* @var Array $options * @var array $options
*/ */
private $options; private $options;
@ -23,13 +27,12 @@ class NoticeManager{
$this->options = get_option( 'notice_manager'); $this->options = get_option( 'notice_manager');
add_action( 'admin_enqueue_scripts' , [ $this , 'admin_enqueues' ] ); add_action( 'admin_enqueue_scripts' , [ $this , 'admin_enqueues' ] );
if ( empty( $this->options['screen_panel'] ) ){ if ( ! empty( $this->options['screen_panel'] ) ){
array_walk($this->options,function(&$item){$item=0;});
}else{
add_action( 'admin_init' , [ $this , 'register_notice_manager_panel' ] ); add_action( 'admin_init' , [ $this , 'register_notice_manager_panel' ] );
}else{
array_walk($this->options,function(&$item){$item=0;});
} }
} }
@ -40,6 +43,14 @@ class NoticeManager{
wp_enqueue_style( 'admin_notices', NOTICE_MANAGER_URL . 'css/admin_notices.css' ); 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(){ function register_notice_manager_panel(){
if ( ! function_exists( 'add_screen_meta_link' ) ) if ( ! function_exists( 'add_screen_meta_link' ) )
return; return;
@ -53,7 +64,6 @@ class NoticeManager{
[ $this , 'print_notice_manager_panel' ] // $panel callback - cb echoes its output [ $this , 'print_notice_manager_panel' ] // $panel callback - cb echoes its output
); );
} }
/* not JSON-safe - unescaped quotes */ /* not JSON-safe - unescaped quotes */