From f01cdbf2b0bc084bddcc05dc7d23be1f7765c769 Mon Sep 17 00:00:00 2001 From: abuyoyo Date: Sun, 31 Jul 2022 01:07:09 +0300 Subject: [PATCH] misc - cleanup + notes + typos + lint + modernize code --- js/notice_manager_panel.js | 13 +++++++------ notice-manager.php | 7 ++----- src/NoticeManager.php | 4 +--- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/js/notice_manager_panel.js b/js/notice_manager_panel.js index f5d01d5..6bea709 100644 --- a/js/notice_manager_panel.js +++ b/js/notice_manager_panel.js @@ -40,10 +40,11 @@ var NoticeManager = (function ($, document) { }); // scroll page to top when closing notice panel - // cannot convert to arrow function - uses this - // could use event.target instead - button.on("click", function () { - if ($(this).hasClass("screen-meta-active")) { + // function used to work with $(this) + // using e.target instead + // not sure if this should perhaps be e.currentTarget + button.on("click", (e) => { + if ($(e.target).hasClass("screen-meta-active")) { if (haveClosed) { NoticeManager.addCounter(); } @@ -68,7 +69,7 @@ var NoticeManager = (function ($, document) { console.log(options); // bootstrap notices - // get all notices that are not explicily marked as `.inline` or `.below-h2` + // get all notices that are not explicitly marked as `.inline` or `.below-h2` // we add .update-nag.inline for WordPress Update notice notices = $("div.updated, div.error, div.notice") .not(".inline, .below-h2") @@ -148,7 +149,7 @@ var NoticeManager = (function ($, document) { notices.appendTo(".notice_container").eq(0); $(".notice_container").removeClass("empty"); // .empty removes padding - haveClosed = true; // initial collection has occured. + haveClosed = true; // initial collection has occurred. /** * When dismissible notices are dismissed, check if any notices are left on page. diff --git a/notice-manager.php b/notice-manager.php index 844ee81..5fca799 100644 --- a/notice-manager.php +++ b/notice-manager.php @@ -13,7 +13,7 @@ defined( 'ABSPATH' ) || die( 'No soup for you!' ); use WPHelper\PluginCore; /** - * Print setting page + * Bootstrap plugin and admin page (Tools > Notice Manager) */ new PluginCore( __FILE__, @@ -28,7 +28,6 @@ new PluginCore( 'sections' => [ [ 'id' => 'notice_manager', - // 'title' => 'N', 'description' => 'Setup How notice manager functions.', 'fields' => [ [ @@ -66,6 +65,4 @@ new PluginCore( require_once 'src/NoticeManager.php'; -add_action('plugins_loaded', function(){ - new NoticeManager(); -}); +add_action( 'plugins_loaded', fn() => new NoticeManager() ); \ No newline at end of file diff --git a/src/NoticeManager.php b/src/NoticeManager.php index 6e79dca..3225b5a 100644 --- a/src/NoticeManager.php +++ b/src/NoticeManager.php @@ -22,7 +22,7 @@ class NoticeManager{ function __construct(){ // exit early if not admin page - if ( !is_admin() ) + if ( ! is_admin() ) return; $this->options = get_option( 'notice_manager' ); @@ -35,8 +35,6 @@ class NoticeManager{ if ( ! empty( $this->options['auto_collect'] ) ){ add_filter( 'admin_body_class', fn($classes) => $classes . ' notices-auto-collect' ); } - }else{ - // array_walk($this->options,function(&$item){$item=0;}); } if ( ! empty( $this->options['above_title'] ) ){