misc - cleanup + notes + typos + lint + modernize code

This commit is contained in:
abuyoyo 2022-07-31 01:07:09 +03:00
parent 1d813a48c9
commit f01cdbf2b0
3 changed files with 10 additions and 14 deletions

View File

@ -40,10 +40,11 @@ var NoticeManager = (function ($, document) {
}); });
// scroll page to top when closing notice panel // scroll page to top when closing notice panel
// cannot convert to arrow function - uses this // function used to work with $(this)
// could use event.target instead // using e.target instead
button.on("click", function () { // not sure if this should perhaps be e.currentTarget
if ($(this).hasClass("screen-meta-active")) { button.on("click", (e) => {
if ($(e.target).hasClass("screen-meta-active")) {
if (haveClosed) { if (haveClosed) {
NoticeManager.addCounter(); NoticeManager.addCounter();
} }
@ -68,7 +69,7 @@ var NoticeManager = (function ($, document) {
console.log(options); console.log(options);
// bootstrap notices // 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 // we add .update-nag.inline for WordPress Update notice
notices = $("div.updated, div.error, div.notice") notices = $("div.updated, div.error, div.notice")
.not(".inline, .below-h2") .not(".inline, .below-h2")
@ -148,7 +149,7 @@ var NoticeManager = (function ($, document) {
notices.appendTo(".notice_container").eq(0); notices.appendTo(".notice_container").eq(0);
$(".notice_container").removeClass("empty"); // .empty removes padding $(".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. * When dismissible notices are dismissed, check if any notices are left on page.

View File

@ -13,7 +13,7 @@ defined( 'ABSPATH' ) || die( 'No soup for you!' );
use WPHelper\PluginCore; use WPHelper\PluginCore;
/** /**
* Print setting page * Bootstrap plugin and admin page (Tools > Notice Manager)
*/ */
new PluginCore( new PluginCore(
__FILE__, __FILE__,
@ -28,7 +28,6 @@ new PluginCore(
'sections' => [ 'sections' => [
[ [
'id' => 'notice_manager', 'id' => 'notice_manager',
// 'title' => 'N',
'description' => 'Setup How notice manager functions.', 'description' => 'Setup How notice manager functions.',
'fields' => [ 'fields' => [
[ [
@ -66,6 +65,4 @@ new PluginCore(
require_once 'src/NoticeManager.php'; require_once 'src/NoticeManager.php';
add_action('plugins_loaded', function(){ add_action( 'plugins_loaded', fn() => new NoticeManager() );
new NoticeManager();
});

View File

@ -22,7 +22,7 @@ class NoticeManager{
function __construct(){ function __construct(){
// exit early if not admin page // exit early if not admin page
if ( !is_admin() ) if ( ! is_admin() )
return; return;
$this->options = get_option( 'notice_manager' ); $this->options = get_option( 'notice_manager' );
@ -35,8 +35,6 @@ class NoticeManager{
if ( ! empty( $this->options['auto_collect'] ) ){ if ( ! empty( $this->options['auto_collect'] ) ){
add_filter( 'admin_body_class', fn($classes) => $classes . ' notices-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'] ) ){ if ( ! empty( $this->options['above_title'] ) ){