From 1d343e7deed9d24e58c5985638f4f20f6c929a79 Mon Sep 17 00:00:00 2001 From: abuoyoyo Date: Wed, 20 Jul 2022 04:59:56 +0300 Subject: [PATCH 01/13] .gitignore - node_modules/ --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a725465..ff87634 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -vendor/ \ No newline at end of file +vendor/ +node_modules/ \ No newline at end of file From 770b2cc43dbd73c9ae8131247ee2a3d92960f777 Mon Sep 17 00:00:00 2001 From: abuoyoyo Date: Sat, 16 Jul 2022 16:41:45 +0300 Subject: [PATCH 02/13] misc cleanup + notes --- js/notice_manager_panel.js | 2 +- src/NoticeManager.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/notice_manager_panel.js b/js/notice_manager_panel.js index 0a6e498..a62b19c 100644 --- a/js/notice_manager_panel.js +++ b/js/notice_manager_panel.js @@ -16,7 +16,7 @@ var NoticeManager = (function ($, document) { let button; let panel; - let haveClosed; + let haveClosed; // set to true on first close/collect let dismissNoticesButton; // bootstrap diff --git a/src/NoticeManager.php b/src/NoticeManager.php index 7a03d0c..0e84c9b 100644 --- a/src/NoticeManager.php +++ b/src/NoticeManager.php @@ -25,7 +25,7 @@ class NoticeManager{ if ( !is_admin() ) return; - $this->options = get_option( 'notice_manager'); + $this->options = get_option( 'notice_manager' ); add_action( 'admin_enqueue_scripts' , [ $this , 'admin_enqueues' ] ); From 5c5788c87d28b8efa88386dc73fb785c9be87139 Mon Sep 17 00:00:00 2001 From: abuoyoyo Date: Sat, 16 Jul 2022 16:41:11 +0300 Subject: [PATCH 03/13] misc - lint + add specificity to DOMNodeRemoved listener --- js/notice_manager_panel.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/js/notice_manager_panel.js b/js/notice_manager_panel.js index a62b19c..540b5a2 100644 --- a/js/notice_manager_panel.js +++ b/js/notice_manager_panel.js @@ -137,12 +137,16 @@ var NoticeManager = (function ($, document) { * When dismissible notices are dismissed, check if any notices are left on page. * If no notices are left - remove Notice Panel entirely */ - $(document).on("DOMNodeRemoved", ".notice.is-dismissible", (e) => { - notices = panel - .find("div.updated, div.error, div.notice, div.update-nag") - .filter(":visible"); - NoticeManager.maybeRemoveNoticesPanel(); - }); + $(document).on( + "DOMNodeRemoved", + "#meta-link-notices-wrap .notice.is-dismissible", + (e) => { + notices = panel + .find("div.updated, div.error, div.notice, div.update-nag") + .filter(":visible"); + NoticeManager.maybeRemoveNoticesPanel(); + } + ); }, /** From 51a493926bcfe52f749c0e4e4e6a3e1f7455490f Mon Sep 17 00:00:00 2001 From: abuoyoyo Date: Sat, 16 Jul 2022 23:20:04 +0300 Subject: [PATCH 04/13] css - Remove support/override of ngfb plugin --- css/admin_notices.css | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/css/admin_notices.css b/css/admin_notices.css index 9977137..96de550 100644 --- a/css/admin_notices.css +++ b/css/admin_notices.css @@ -33,28 +33,4 @@ .notice_container > div.notice, .notice_container > div.update-nag{ margin: 5px 12px 15px 12px; -} - - -/* ngfb update-nag override */ -div.ngfb-notice.update-nag { - display: none !important; /* not working - need to remove with js */ - /* restore normal formatting */ - /* margin-top: 25px; */ - border: 0px; - /* border-left: 4px solid #ffba00; */ - border-left: 4px solid #00a0d2; -} - -.ngfb-notice.update-nag .notice-message { - max-width: 100%; - padding: 0; -} - -.ngfb-notice.update-nag p, .ngfb-notice.update-nag ul, .ngfb-notice.update-nag ol { - text-align: left !important; - font-size: 13px !important; - line-height: 1.5; - margin: 1em 0 !important; - opacity: 0.5; } \ No newline at end of file From ba26708c9f845a9a93854f3ec68042d7ac644a4f Mon Sep 17 00:00:00 2001 From: abuoyoyo Date: Thu, 14 Jul 2022 01:23:47 +0300 Subject: [PATCH 05/13] css - override other plugins' custom notice padding --- css/admin_notices.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/css/admin_notices.css b/css/admin_notices.css index 96de550..a1fc27d 100644 --- a/css/admin_notices.css +++ b/css/admin_notices.css @@ -32,5 +32,5 @@ .notice_container > div.error, .notice_container > div.notice, .notice_container > div.update-nag{ - margin: 5px 12px 15px 12px; + margin: 5px 12px 15px 12px !important; /* Override plugins custom css */ } \ No newline at end of file From 57c54c756a380b695550fd189dd8d47d8b4ac154 Mon Sep 17 00:00:00 2001 From: abuoyoyo Date: Sat, 16 Jul 2022 18:21:08 +0300 Subject: [PATCH 06/13] js - re-factor/improve functionality --- js/notice_manager_panel.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/js/notice_manager_panel.js b/js/notice_manager_panel.js index 540b5a2..3fe847f 100644 --- a/js/notice_manager_panel.js +++ b/js/notice_manager_panel.js @@ -28,7 +28,9 @@ var NoticeManager = (function ($, document) { dismissNoticesButton.on("click", () => { screenMeta.close(panel, button); - NoticeManager.collectNotices(); + if (! haveClosed){ + NoticeManager.collectNotices(); + } }); //original wp focus on click function @@ -40,7 +42,6 @@ var NoticeManager = (function ($, document) { // cannot convert to arrow function - uses this // could use event.target instead button.on("click", function () { - haveClosed = true; if ($(this).hasClass("screen-meta-active")) { // $(window).scrollTop(true); } else { @@ -69,9 +70,11 @@ var NoticeManager = (function ($, document) { /** * Remove panel if there are no notices on this page */ - NoticeManager.maybeRemoveNoticesPanel(); + if (options.screen_panel) { + NoticeManager.maybeRemoveNoticesPanel(); + } - if (options.auto_collect) { + if (options.screen_panel && options.auto_collect) { NoticeManager.collectNotices(); } else { /** @@ -95,11 +98,11 @@ var NoticeManager = (function ($, document) { /** * auto-close notices panel after short delay - * only auto-close if we have not interacted (opened/closed) with panel previously + * only auto-close if we have collected notices previously */ if (options.auto_collapse) { wait(4000).then(() => { - if (!haveClosed) { + if (haveClosed) { screenMeta.close(panel, button); } }); @@ -133,6 +136,8 @@ var NoticeManager = (function ($, document) { notices.appendTo(".notice_container").eq(0); $(".notice_container").removeClass("empty"); // .empty removes padding + haveClosed = true; // initial collection has occured. + /** * When dismissible notices are dismissed, check if any notices are left on page. * If no notices are left - remove Notice Panel entirely From a2c3e60f87eb6485ce4160d7eaef9035e5af06d7 Mon Sep 17 00:00:00 2001 From: abuoyoyo Date: Sat, 16 Jul 2022 20:10:00 +0300 Subject: [PATCH 07/13] NoticeManager.moveAboveTitle + above_title option --- js/notice_manager_panel.js | 20 ++++++++++++-------- notice-manager.php | 6 ++++++ src/NoticeManager.php | 2 +- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/js/notice_manager_panel.js b/js/notice_manager_panel.js index 3fe847f..00ac49a 100644 --- a/js/notice_manager_panel.js +++ b/js/notice_manager_panel.js @@ -77,14 +77,9 @@ var NoticeManager = (function ($, document) { if (options.screen_panel && options.auto_collect) { NoticeManager.collectNotices(); } else { - /** - * Move ALL notices above page title. - * Default no-panel action - override WordPress moving notices BELOW title. - * I HATE it when WordPress moves notices below title. - * - * comment this line out to completely restore WordPress functionality when auto_collect is off - */ - notices.insertBefore(".wrap:first"); + if (options.above_title) { + NoticeManager.moveAboveTitle(); + } } /** @@ -169,5 +164,14 @@ var NoticeManager = (function ($, document) { $("#screen-meta-links").detach(); } }, + + /** + * Move ALL notices above page title. + * Default no-panel action - override WordPress moving notices BELOW title. + * I HATE it when WordPress moves notices below title. + */ + moveAboveTitle: () => { + notices.insertBefore(".wrap:first"); + }, }; }(jQuery,document) ) \ No newline at end of file diff --git a/notice-manager.php b/notice-manager.php index e79dd0d..478f390 100644 --- a/notice-manager.php +++ b/notice-manager.php @@ -30,6 +30,12 @@ new PluginCore( // 'title' => 'N', 'description' => 'Setup How notice manager functions.', 'fields' => [ + [ + 'id' => 'above_title', + 'title' => 'Above Title', + 'type' => 'checkbox', + 'description' => 'Move all notices above title. (WordPress core moves notices below title using script.)', + ], [ 'id' => 'screen_panel', 'title' => 'Notices Panel', diff --git a/src/NoticeManager.php b/src/NoticeManager.php index 0e84c9b..0dc97d9 100644 --- a/src/NoticeManager.php +++ b/src/NoticeManager.php @@ -32,7 +32,7 @@ class NoticeManager{ if ( ! empty( $this->options['screen_panel'] ) ){ add_action( 'admin_init' , [ $this , 'register_notice_manager_panel' ] ); }else{ - array_walk($this->options,function(&$item){$item=0;}); + // array_walk($this->options,function(&$item){$item=0;}); } } From 2362cb37df53833c046e73e37a16e0ee12d78e43 Mon Sep 17 00:00:00 2001 From: abuoyoyo Date: Sun, 17 Jul 2022 18:18:45 +0300 Subject: [PATCH 08/13] FOUC - add body class .notices-above-title Do not display notices before they are moved to new position. --- css/admin_notices.css | 8 ++++++++ src/NoticeManager.php | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/css/admin_notices.css b/css/admin_notices.css index a1fc27d..fb0c429 100644 --- a/css/admin_notices.css +++ b/css/admin_notices.css @@ -33,4 +33,12 @@ .notice_container > div.notice, .notice_container > div.update-nag{ margin: 5px 12px 15px 12px !important; /* Override plugins custom css */ +} + +/* This should only be used if auto-collect/above-title is enabled */ +.notices-above-title .wrap > div.updated, +.notices-above-title .wrap > div.error, +.notices-above-title .wrap > div.notice, +.notices-above-title .wrap > div.update-nag{ + display: none; } \ No newline at end of file diff --git a/src/NoticeManager.php b/src/NoticeManager.php index 0dc97d9..52300d6 100644 --- a/src/NoticeManager.php +++ b/src/NoticeManager.php @@ -35,6 +35,10 @@ class NoticeManager{ // array_walk($this->options,function(&$item){$item=0;}); } + if ( ! empty( $this->options['above_title'] ) ){ + add_filter( 'admin_body_class', fn($classes) => $classes . ' notices-above-title' ); + } + } function admin_enqueues(){ From d48631c4f64a802b5e8f0098ec3663005137f0c1 Mon Sep 17 00:00:00 2001 From: abuoyoyo Date: Sat, 16 Jul 2022 21:42:51 +0300 Subject: [PATCH 09/13] FOUC - add body class .notices-auto-collect Do not display notices before they are moved to panel. --- css/admin_notices.css | 8 ++++++++ src/NoticeManager.php | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/css/admin_notices.css b/css/admin_notices.css index fb0c429..cc182c5 100644 --- a/css/admin_notices.css +++ b/css/admin_notices.css @@ -36,6 +36,14 @@ } /* This should only be used if auto-collect/above-title is enabled */ +.notices-auto-collect #wpbody-content > div.updated, +.notices-auto-collect #wpbody-content > div.error, +.notices-auto-collect #wpbody-content > div.notice, +.notices-auto-collect #wpbody-content > div.update-nag, +.notices-auto-collect .wrap > div.updated, +.notices-auto-collect .wrap > div.error, +.notices-auto-collect .wrap > div.notice, +.notices-auto-collect .wrap > div.update-nag, .notices-above-title .wrap > div.updated, .notices-above-title .wrap > div.error, .notices-above-title .wrap > div.notice, diff --git a/src/NoticeManager.php b/src/NoticeManager.php index 52300d6..6e79dca 100644 --- a/src/NoticeManager.php +++ b/src/NoticeManager.php @@ -31,6 +31,10 @@ class NoticeManager{ if ( ! empty( $this->options['screen_panel'] ) ){ add_action( 'admin_init' , [ $this , 'register_notice_manager_panel' ] ); + + 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;}); } From eabafb460fd6cf07348fb98a77d6718a7f7f265f Mon Sep 17 00:00:00 2001 From: abuoyoyo Date: Sat, 16 Jul 2022 22:30:41 +0300 Subject: [PATCH 10/13] js - NoticeManager.getNoticesTopPriority() --- js/notice_manager_panel.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/js/notice_manager_panel.js b/js/notice_manager_panel.js index 00ac49a..3198b1a 100644 --- a/js/notice_manager_panel.js +++ b/js/notice_manager_panel.js @@ -123,6 +123,14 @@ var NoticeManager = (function ($, document) { return { getNotices: () => notices, + getNoticesTopPriority: () => { + if ( notices.filter('.error').length ) + return 'error'; + if ( notices.filter('.notice-warning, .update-nag').length ) + return 'warning'; + return 'notice'; + }, + /** * Collect notices into panel. * Remove dismiss-notices button. From 28ac8f941bf26282dc416f00d4fa5d2bbcc37ed6 Mon Sep 17 00:00:00 2001 From: abuoyoyo Date: Sat, 16 Jul 2022 22:37:57 +0300 Subject: [PATCH 11/13] Do not auto-collapse when error notice is shown --- js/notice_manager_panel.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/notice_manager_panel.js b/js/notice_manager_panel.js index 3198b1a..e074dba 100644 --- a/js/notice_manager_panel.js +++ b/js/notice_manager_panel.js @@ -94,10 +94,11 @@ var NoticeManager = (function ($, document) { /** * auto-close notices panel after short delay * only auto-close if we have collected notices previously + * only auto-close if no error messages */ if (options.auto_collapse) { wait(4000).then(() => { - if (haveClosed) { + if (haveClosed && NoticeManager.getNoticesTopPriority() != 'error') { screenMeta.close(panel, button); } }); From 296051fac182e92f8d3461ce1dede6ae8b315f06 Mon Sep 17 00:00:00 2001 From: abuoyoyo Date: Sat, 16 Jul 2022 22:44:03 +0300 Subject: [PATCH 12/13] Add ".plugin-count" counter to notice panel tag when closed --- css/admin_notices.css | 25 +++++++++++++++++++++++++ js/notice_manager_panel.js | 22 ++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/css/admin_notices.css b/css/admin_notices.css index cc182c5..4fab8f7 100644 --- a/css/admin_notices.css +++ b/css/admin_notices.css @@ -49,4 +49,29 @@ .notices-above-title .wrap > div.notice, .notices-above-title .wrap > div.update-nag{ display: none; +} + +#meta-link-notices .plugin-count { + display: inline-block; + /* vertical-align: top; */ + box-sizing: border-box; + margin: 1px 0 -1px 2px; + padding: 0 5px; + min-width: 18px; + height: 18px; + border-radius: 9px; + background-color: #72aee6; + color: #fff; + font-size: 11px; + line-height: 1.6; + text-align: center; + z-index: 26; +} + +#meta-link-notices .plugin-count.warning { + background-color: #dba617; +} + +#meta-link-notices .plugin-count.error { + background-color: #d63638; } \ No newline at end of file diff --git a/js/notice_manager_panel.js b/js/notice_manager_panel.js index e074dba..f5d01d5 100644 --- a/js/notice_manager_panel.js +++ b/js/notice_manager_panel.js @@ -31,6 +31,7 @@ var NoticeManager = (function ($, document) { if (! haveClosed){ NoticeManager.collectNotices(); } + NoticeManager.addCounter(); }); //original wp focus on click function @@ -43,8 +44,14 @@ var NoticeManager = (function ($, document) { // could use event.target instead button.on("click", function () { if ($(this).hasClass("screen-meta-active")) { + if (haveClosed) { + NoticeManager.addCounter(); + } + // $(window).scrollTop(true); } else { + NoticeManager.removeCounter(); + // wait (500).then(function(){ //still jumpy sometimes - but scrolls to correct position 400 ~ 600 // $(window).scrollTop(true); // }); @@ -100,6 +107,7 @@ var NoticeManager = (function ($, document) { wait(4000).then(() => { if (haveClosed && NoticeManager.getNoticesTopPriority() != 'error') { screenMeta.close(panel, button); + NoticeManager.addCounter(); } }); } @@ -158,6 +166,20 @@ var NoticeManager = (function ($, document) { ); }, + addCounter: () => { + if (!button.children('.plugin-count').length){ + button.append( + $("").text(notices.length).attr({ + class: "plugin-count", + }).addClass(NoticeManager.getNoticesTopPriority()) + ); + } + }, + + removeCounter: () => { + button.children(".plugin-count").remove(); + }, + /** * Remove meta-links-notices if no notices on page * Remove screen-meta-links wrapper if no panels on page From 36a79a5f5e355bd853fc61704ed2973fd5195678 Mon Sep 17 00:00:00 2001 From: abuoyoyo Date: Fri, 22 Jul 2022 19:18:08 +0300 Subject: [PATCH 13/13] 0.14 - version bump + changelog --- CHANGELOG.md | 11 +++++++++++ notice-manager.php | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e9de1e..ee2694c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Notice Manager Changelog +## 0.14 + +### Added +- Added `above_title` setting - move all scripts above title. +- Added `.plugin_count` bullet to panel tab - showing number of notices in panel and priority. + +### Changed +- Improve "jumpy" notices when page is loaded with certain setting combinations by selectively setting css `display: none` to notices not in their expected location. +- Improve integration between different options (eg. `above_title` with `auto-collect`). +- Option `auto-collapse` will not automatically collapse panel if an error notice is showing. + ## 0.13 ### Changed diff --git a/notice-manager.php b/notice-manager.php index 478f390..fef8224 100644 --- a/notice-manager.php +++ b/notice-manager.php @@ -2,7 +2,7 @@ /** * Plugin Name: Notice Manager * Description: Manage notices on WordPress admin pages. Adds 'Notices' screen-meta-link. - * Version: 0.13 + * Version: 0.14 * Author: abuyoyo * Author URI: https://github.com/abuyoyo/ * Plugin URI: https://github.com/abuyoyo/notice-manager