options = get_option( 'notice_manager'); add_action( 'admin_enqueue_scripts' , [ $this , 'admin_enqueues' ] ); 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_print_footer_scripts', [$this,'admin_print_footer_scripts']); // 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( 'notice_manager_panel', NOTICE_MANAGER_URL . 'js/notice_manager_panel.js' , null, false , true ); wp_localize_script( 'notice_manager_panel', 'noticeManager', camelCaseKeys($this->options) ); wp_enqueue_style( 'admin_notices', NOTICE_MANAGER_URL . 'css/admin_notices.css' ); } function admin_print_footer_scripts(){ // echo ''; // echo ''; } 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 ); } /* 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 '
'; // if auto_collect is ON - we don't need the button. if (!$this->options['auto_collect']) echo '
' ; } /** * A plugin 'notice-manager' exists now on @link https://wordpress.org/plugins/ * Disable update notifications completely for our plugin. * * @todo - use update_checker to only upload our plugin from github */ function remove_update_notifications($value) { if ( isset( $value ) && is_object( $value ) ) { unset( $value->response[ NOTICE_MANAGER_BASENAME ] ); } return $value; } }