PluginProbe ʕ •ᴥ•ʔ
Disable Admin Notices – Hide Dashboard Notifications / 1.4.6
Disable Admin Notices – Hide Dashboard Notifications v1.4.6
1.4.7 1.4.6 1.4.5 trunk 1.0.0 1.0.2 1.0.3 1.0.5 1.0.6 1.1.1 1.1.3 1.1.4 1.2.0 1.2.2 1.2.3 1.2.4 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4
disable-admin-notices / includes / class-plugin.php
disable-admin-notices / includes Last commit date
3rd-party 3 years ago classes 7 months ago class-plugin.php 1 month ago functions.php 3 years ago index.php 8 years ago
class-plugin.php
176 lines
1 <?php
2 /**
3 * Disable admin notices core class
4 *
5 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
6 * Github: https://github.com/alexkovalevv
7 * @copyright (c) 2018 Webraftic Ltd
8 * @version 1.0
9 */
10
11 // Exit if accessed directly
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 class WDN_Plugin extends Wbcr_Factory480_Plugin {
17
18 /**
19 * @var Wbcr_Factory480_Plugin
20 */
21 private static $app;
22 private $plugin_data;
23
24
25 /**
26 * @param string $plugin_path
27 * @param array $data
28 *
29 * @throws Exception
30 */
31 public function __construct( $plugin_path, $data ) {
32 parent::__construct( $plugin_path, $data );
33
34 self::$app = $this;
35 $this->plugin_data = $data;
36
37 $this->global_scripts();
38
39 if ( is_admin() ) {
40 $this->admin_scripts();
41 }
42
43 // Wordpress 6.7 fix
44 add_action( 'init', function () {
45 if ( is_admin() ) {
46 $this->register_pages();
47 }
48 } );
49
50 add_filter( 'themeisle_sdk_products', [ __CLASS__, 'register_sdk' ] );
51
52 add_filter( 'themeisle_sdk_ran_promos', '__return_true' );
53
54 add_action( 'admin_enqueue_scripts', [ $this, 'mark_internal_page' ] );
55 add_filter( 'themeisle_sdk_blackfriday_data', [ $this, 'add_black_friday_data' ] );
56 }
57 /**
58 * Register product into SDK.
59 *
60 * @param array $products All products.
61 *
62 * @return array Registered product.
63 */
64 public static function register_sdk( $products ) {
65 $products[] = WDN_PLUGIN_FILE;
66
67 return $products;
68 }
69 /**
70 * @return Wbcr_Factory480_Plugin
71 */
72 public static function app() {
73 return self::$app;
74 }
75
76 private function register_pages() {
77 //self::app()->registerPage( 'WDN_Log_Page', WDN_PLUGIN_DIR . '/admin/pages/class-pages-log.php' );
78 self::app()->registerPage( 'WDN_Settings_Page', WDN_PLUGIN_DIR . '/admin/pages/class-pages-settings.php' );
79 self::app()->registerPage( 'WDAN_Notices', WDN_PLUGIN_DIR . '/admin/pages/class-pages-notices.php' );
80 self::app()->registerPage( 'WDAN_Block_Ad_Redirects', WDN_PLUGIN_DIR . '/admin/pages/class-pages-edit-redirects.php' );
81 self::app()->registerPage( 'WDAN_Edit_Admin_Bar', WDN_PLUGIN_DIR . '/admin/pages/class-pages-edit-admin-bar.php' );
82 }
83
84 private function admin_scripts() {
85 require( WDN_PLUGIN_DIR . '/admin/options.php' );
86 require( WDN_PLUGIN_DIR . '/admin/class-page-basic.php' );
87
88 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
89 require_once( WDN_PLUGIN_DIR . '/admin/ajax/hide-notice.php' );
90 require_once( WDN_PLUGIN_DIR . '/admin/ajax/restore-notice.php' );
91 require_once( WDN_PLUGIN_DIR . '/admin/ajax/disable-adminbar-menus.php' );
92 }
93
94 require_once( WDN_PLUGIN_DIR . '/admin/boot.php' );
95 require_once( WDN_PLUGIN_DIR . '/admin/pages/class-pages-edit-admin-bar.php' );
96 require_once( WDN_PLUGIN_DIR . '/admin/pages/class-pages-edit-redirects.php' );
97 require_once( WDN_PLUGIN_DIR . '/admin/pages/class-pages-notices.php' );
98
99 /*add_action( 'plugins_loaded', function () {
100 $this->register_pages();
101 }, 30 );*/
102 }
103
104 private function global_scripts() {
105 require_once( WDN_PLUGIN_DIR . '/includes/classes/class-configurate-notices.php' );
106 new WDN_ConfigHideNotices( self::$app );
107
108 add_action( 'wp_before_admin_bar_render', [ $this, 'remove_from_admin_bar' ], 999 );
109 }
110
111 public function remove_from_admin_bar() {
112 global $wp_admin_bar;
113
114 if ( empty( $wp_admin_bar ) ) {
115 return;
116 }
117
118 $hidden_items = $this->getPopulateOption( 'hidden_adminbar_items', [] );
119
120 if ( is_admin() ) {
121 $nodes = [];
122 foreach ( $wp_admin_bar->get_nodes() as $node ) {
123 if ( false === $node->parent && ! empty( $node->title ) ) {
124 if ( "updates" === $node->id ) {
125 $node->title = "Updates";
126 }
127 if ( "comments" === $node->id ) {
128 $node->title = "Comments";
129 }
130 $nodes[ $node->id ] = strip_tags( $node->title );
131 }
132 }
133 $this->updatePopulateOption( 'adminbar_items', $nodes );
134 }
135
136 foreach ( (array) $hidden_items as $item_ID => $bool ) {
137 $wp_admin_bar->remove_menu( $item_ID );
138 }
139 }
140
141 public function add_black_friday_data( $configs ) {
142 $config = $configs['default'];
143
144 if ( defined( 'NEVE_VERSION' ) ) {
145 return $configs;
146 }
147
148 // translators: 1. Number of free licenses, 2. The price of the product.
149 $config['message'] = sprintf( __( 'You\'re using Disable Admin Notices, and the team behind it is celebrating Black Friday by giving away %1$s licences of Neve Pro. A premium WordPress theme worth %2$s, packed with starter sites, a header builder, and WooCommerce layouts. Claim yours before they run out.', 'disable-admin-notices' ), 100, '$69' );
150 $config['cta_label'] = __( 'Get Neve Pro free', 'disable-admin-notices' );
151 $config['plugin_meta_message'] = __( 'Black Friday Sale - Get Neve Pro free', 'disable-admin-notices' );
152 $config['sale_url'] = add_query_arg(
153 array(
154 'utm_term' => 'free',
155 ),
156 tsdk_translate_link( tsdk_utmify( 'https://themeisle.link/neve-claim-bf', 'bfcm', 'disable-notices' ) )
157 );
158
159 $configs[ WDN_PRODUCT_SLUG ] = $config;
160
161 return $configs;
162 }
163
164 public function mark_internal_page( $hook ) {
165 if ( strpos( $hook, 'wdan_settings' ) !== false ) {
166 do_action( 'themeisle_internal_page', WDN_PRODUCT_SLUG, 'settings' );
167 } elseif ( strpos( $hook, 'wdan-notices' ) !== false ) {
168 do_action( 'themeisle_internal_page', WDN_PRODUCT_SLUG, 'notices' );
169 } elseif ( strpos( $hook, 'wdanp-edit-redirects' ) !== false ) {
170 do_action( 'themeisle_internal_page', WDN_PRODUCT_SLUG, 'edit-redirects' );
171 } elseif ( strpos( $hook, 'wdanp-edit-admin-bar' ) !== false ) {
172 do_action( 'themeisle_internal_page', WDN_PRODUCT_SLUG, 'edit-admin-bar' );
173 }
174 }
175 }
176