v0.9
This commit is contained in:
parent
7949f9f976
commit
8fb8e5cbf9
59
css/admin_notices.css
Normal file
59
css/admin_notices.css
Normal file
@ -0,0 +1,59 @@
|
||||
:not(.wrap) ~ div.updated,
|
||||
:not(.wrap) ~ div.error,
|
||||
:not(.wrap) ~ div.notice,
|
||||
:not(.wrap) ~ div.update-nag{
|
||||
margin: 5px 20px 15px 2px;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#meta-link-notices-wrap {
|
||||
margin: 0;
|
||||
/* padding: 8px 20px 12px; */
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#meta-link-notices-wrap > button.notice-dismiss {
|
||||
position: relative;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.notice_container{
|
||||
padding: 9px 0px 1px 0px;
|
||||
background-color: gainsboro;
|
||||
}
|
||||
|
||||
.notice_container.empty{
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.notice_container > div.updated,
|
||||
.notice_container > div.error,
|
||||
.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;
|
||||
}
|
||||
21
js/move_notices.js
Normal file
21
js/move_notices.js
Normal file
@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Move all notices "above the fold"
|
||||
*
|
||||
* Used for plugins that print their notices after 'admin_notice'
|
||||
*/
|
||||
|
||||
(function ($,document){
|
||||
$(document).ready(function(){
|
||||
//alert ('move_notices.js');
|
||||
//$( 'div.updated, div.error, div.notice' ).not( '.inline, .below-h2' ).insertAfter( $headerEnd );
|
||||
|
||||
//alert('plugin move notices');
|
||||
$( 'div.updated, div.error, div.notice, div.update-nag' ).not( '.inline, .below-h2' ).insertBefore('.wrap:first'); //alert('plugin move notices');
|
||||
|
||||
// $( 'div.updated, div.error, div.notice, div.update-nag' ).not( '.inline, .below-h2' ).each(function(){
|
||||
// $(this).insertBefore('.wrap'); //alert('plugin move notices');
|
||||
// });
|
||||
|
||||
});
|
||||
}(jQuery, document))
|
||||
|
||||
59
js/notice_manager_panel.js
Normal file
59
js/notice_manager_panel.js
Normal file
@ -0,0 +1,59 @@
|
||||
(function($,document){
|
||||
var button = $( '#meta-link-notices' ),
|
||||
panel = $( '#meta-link-notices-wrap' ),
|
||||
haveClosed = false,
|
||||
haveDismissed = false;
|
||||
|
||||
//auto-open notice-panel for quick dismiss
|
||||
$(document).ready(function(){
|
||||
if (button.length){
|
||||
panel.toggle();
|
||||
button.addClass( 'screen-meta-active' );
|
||||
|
||||
screenMeta.open(panel,button);
|
||||
}
|
||||
});
|
||||
|
||||
var dismiss = $( '#meta-link-notices-wrap button' );
|
||||
dismiss.on('click',function(){
|
||||
screenMeta.close(panel,button);
|
||||
$( 'div.updated, div.error, div.notice, div.update-nag' ).not( '.inline, .below-h2' ).appendTo('.notice_container').eq(0);
|
||||
$('.notice_container').removeClass('empty');
|
||||
dismiss.hide();
|
||||
haveDismissed = true;
|
||||
});
|
||||
|
||||
//original wp focus on click function
|
||||
/* button.on( 'focus.scroll-into-view', function(e){
|
||||
if ( e.target.scrollIntoView )
|
||||
e.target.scrollIntoView(false);
|
||||
}); */
|
||||
|
||||
//scroll page to top when closing notice panel
|
||||
button.on('click',function(){
|
||||
haveClosed = true;
|
||||
if ( $(this).hasClass('screen-meta-active') ){
|
||||
$(window).scrollTop(true);
|
||||
}else{
|
||||
wait (500).then(function(){ //still jumpy sometimes - but scrolls to correct position 400 ~ 600
|
||||
$(window).scrollTop(true);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
wait = window.wait || function(ms){
|
||||
var dfd = $.Deferred();
|
||||
setTimeout(dfd.resolve, ms); //callback, timeout till callback
|
||||
return dfd.promise();
|
||||
};
|
||||
|
||||
// auto-close notices panel after short delay
|
||||
// only auto-close if we have not interacted (opened/closed) with panel previously
|
||||
wait(20000).then(function(){
|
||||
if ( ! haveClosed )
|
||||
screenMeta.close(panel,button);
|
||||
});
|
||||
|
||||
}(jQuery,document) )
|
||||
82
notice-manager.php
Normal file
82
notice-manager.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Name: abuyoyo / Notice Manager
|
||||
* Description: Manage notices on WordPress admin pages.
|
||||
* Version: 0.9
|
||||
* Author: abuyoyo
|
||||
* Author URI: https://github.com/abuyoyo/
|
||||
*/
|
||||
if ( ! defined('ABSPATH') )
|
||||
wp_die( 'No soup for you!' );
|
||||
|
||||
/**
|
||||
* @todo If no notices on page - don't show Notice Manager panel
|
||||
*/
|
||||
class NoticeManager{
|
||||
|
||||
function __construct(){
|
||||
// exit early if not admin page
|
||||
if ( !is_admin() )
|
||||
return;
|
||||
|
||||
add_action( 'admin_enqueue_scripts' , [ $this , 'admin_enqueues' ] );
|
||||
|
||||
add_action( 'admin_init' , [ $this , 'register_notice_manager_panel' ] );
|
||||
|
||||
// we don't want to update wp-plugin registered with same name
|
||||
add_filter( 'site_transient_update_plugins', [ $this, 'remove_update_notifications' ] );
|
||||
}
|
||||
|
||||
function admin_enqueues(){
|
||||
wp_enqueue_script( 'move_notices', plugin_dir_url( __FILE__ ) . 'js/move_notices.js' , null, false , true ); //default script - moves all notices above wrap h1/h2
|
||||
wp_enqueue_style( 'admin_notices', plugin_dir_url( __FILE__ ) . 'css/admin_notices.css' );
|
||||
}
|
||||
|
||||
function register_notice_manager_panel(){
|
||||
if ( ! function_exists( 'add_screen_meta_link' ) )
|
||||
return;
|
||||
|
||||
add_screen_meta_link(
|
||||
'meta-link-notices', // $id
|
||||
'Notices', // $text
|
||||
'', // $href - not used
|
||||
'*', // $page - string or array of page/screen IDs
|
||||
[ 'aria-controls' => 'meta-link-notices-wrap' ], // $attributes - Additional attributes for the link tag.
|
||||
[ $this , 'print_notice_manager_panel' ] // $panel callback - cb echoes its output
|
||||
);
|
||||
|
||||
wp_enqueue_script( 'notice_manager_panel', plugin_dir_url( __FILE__ ) . 'js/notice_manager_panel.js' , null, false , true );
|
||||
}
|
||||
|
||||
/* not JSON-safe - unescaped quotes */
|
||||
function print_notice_manager_panel(){
|
||||
|
||||
// NOTE:
|
||||
// button is a copy of is-dismissible button - for styling purposes only
|
||||
// js functionality and listener - js/notice_manager_meta_panel.js
|
||||
echo '<div class="notice_container empty"></div>';
|
||||
echo '<button type="button" class="notice-dismiss"><span class="screen-reader-text">' . __( 'Dismiss' ) . '</span><strong> Dismiss Notices</strong></button><div></div>' ;
|
||||
}
|
||||
|
||||
function remove_update_notifications($value) {
|
||||
|
||||
if ( isset( $value ) && is_object( $value ) ) {
|
||||
unset( $value->response[ plugin_basename(__FILE__) ] );
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
global $notice_manager;
|
||||
$notice_manager = new NoticeManager();
|
||||
|
||||
|
||||
add_filter( 'wds_required_plugins', function($required){
|
||||
$req_array = [
|
||||
'screen-meta-links/screen-meta-links.php',
|
||||
];
|
||||
return array_merge( $required, $req_array );
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user