class-configurate-notices.php
679 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This class configures hide admin notices |
| 5 | * |
| 6 | * Github: https://github.com/alexkovalevv |
| 7 | * |
| 8 | * @author Alexander Kovalev <alex.kovalevv@gmail.com> |
| 9 | * @copyright (c) 2018 Webraftic Ltd |
| 10 | * @version 1.0 |
| 11 | */ |
| 12 | |
| 13 | // Exit if accessed directly |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit; |
| 16 | } |
| 17 | |
| 18 | class WDN_ConfigHideNotices extends WBCR\Factory_Templates_134\Configurate { |
| 19 | |
| 20 | public function registerActionsAndFilters() { |
| 21 | if ( is_admin() ) { |
| 22 | $hide_notices_type = $this->getPopulateOption( 'hide_admin_notices', 'only_selected' ); |
| 23 | |
| 24 | if ( 'only_selected' === $hide_notices_type ) { |
| 25 | add_action( 'admin_head', [ $this, 'printNotices' ], 999 ); |
| 26 | } |
| 27 | |
| 28 | if ( 'not_hide' !== $hide_notices_type ) { |
| 29 | |
| 30 | add_action( 'admin_head', [ $this, 'hide_nags' ], 999 ); |
| 31 | add_action( 'admin_print_scripts', [ $this, 'catch_compact_notice' ], 999 ); |
| 32 | add_action( 'admin_print_footer_scripts', [ $this, 'show_compact_panel' ], 999 ); |
| 33 | |
| 34 | add_filter( 'wdan/notifications/all', [ $this, 'notifications_all' ] ); |
| 35 | add_action( 'wdn/notifications/panel/all', [ $this, 'notifications_panel_all' ], 10, 3 ); |
| 36 | add_filter( 'wdn/notifications/catch/all', [ $this, 'catch_notices_all' ], 10, 4 ); |
| 37 | |
| 38 | // If the type is not compact_panel, process regular notices too. |
| 39 | if ( 'compact_panel' !== $hide_notices_type ) { |
| 40 | |
| 41 | add_action( 'admin_print_scripts', [ $this, 'catch_notices' ], 999 ); |
| 42 | add_action( 'admin_bar_menu', [ $this, 'notifications_anel' ], 999 ); |
| 43 | add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_styles' ] ); |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | public function printNotices() { |
| 50 | if ( is_multisite() && is_network_admin() ) { |
| 51 | add_action( 'network_admin_notices', [ $this, 'noticesCollection' ] ); |
| 52 | } else { |
| 53 | add_action( 'admin_notices', [ $this, 'noticesCollection' ] ); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | |
| 58 | public function enqueue_styles() { |
| 59 | if ( "all" === $this->plugin->getPopulateOption( 'hide_admin_notices' ) ) { |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | wp_enqueue_style( 'wbcr-notification-hide-style', WDN_PLUGIN_URL . '/admin/assets/css/general.css', [], $this->plugin->getPluginVersion() ); |
| 64 | |
| 65 | if ( ! $this->getPopulateOption( 'show_notices_in_adminbar', false ) && current_user_can( 'manage_network' ) ) { |
| 66 | return; |
| 67 | } |
| 68 | wp_enqueue_style( 'wbcr-notification-panel-styles', WDN_PLUGIN_URL . '/admin/assets/css/notifications-panel.css', [], $this->plugin->getPluginVersion() ); |
| 69 | wp_enqueue_script( 'wbcr-notification-panel-scripts', WDN_PLUGIN_URL . '/admin/assets/js/notifications-panel.js', [], $this->plugin->getPluginVersion() ); |
| 70 | } |
| 71 | |
| 72 | public function notifications_anel( &$wp_admin_bar ) { |
| 73 | if ( ! $this->getPopulateOption( 'show_notices_in_adminbar', false ) ) { |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | if ( current_user_can( 'manage_options' ) ) { |
| 78 | $notifications_user = get_user_meta( get_current_user_id(), $this->plugin->getOptionName( 'hidden_notices' ), true ); |
| 79 | $notifications_all = apply_filters( 'wdan/notifications/all', [] ); |
| 80 | |
| 81 | if ( ! is_array( $notifications_user ) ) { |
| 82 | $notifications_user = []; |
| 83 | } |
| 84 | |
| 85 | if ( empty( $notifications_user ) && empty( $notifications_all ) ) { |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | $cont_notifications = sizeof( $notifications_user ) + sizeof( $notifications_all ); |
| 90 | |
| 91 | // Add top menu |
| 92 | $wp_admin_bar->add_menu( [ |
| 93 | 'id' => 'wbcr-han-notify-panel', |
| 94 | 'parent' => 'top-secondary', |
| 95 | 'title' => sprintf( __( 'Notifications %s', 'disable-admin-notices' ), '<span class="wbcr-han-adminbar-counter">' . $cont_notifications . '</span>' ), |
| 96 | 'href' => $this->plugin->getPluginPageUrl( 'wdan-notices' ) |
| 97 | ] ); |
| 98 | |
| 99 | $i = 0; |
| 100 | |
| 101 | // User |
| 102 | if ( ! empty( $notifications_user ) ) { |
| 103 | $wp_admin_bar->add_menu( [ |
| 104 | 'id' => 'wbcr-han-notify-panel-group-user', |
| 105 | 'parent' => 'wbcr-han-notify-panel', |
| 106 | 'title' => __( 'Hidden for you', 'disable-admin-notices' ), |
| 107 | 'href' => false, |
| 108 | 'meta' => [ |
| 109 | 'class' => '' |
| 110 | ] |
| 111 | ] ); |
| 112 | |
| 113 | foreach ( $notifications_user as $notice_id => $message ) { |
| 114 | $message = wp_kses( $message, [] ); |
| 115 | $message = $this->getExcerpt( stripslashes( $message ), 0, 350 ); |
| 116 | $message .= '<div class="wbcr-han-panel-restore-notify-line">'; |
| 117 | $message .= '<a href="#" data-nonce="' . wp_create_nonce( $this->plugin->getPluginName() . '_ajax_restore_notice_nonce' ); |
| 118 | $message .= '" data-notice-id="' . esc_attr( $notice_id ) . '" class="wbcr-han-panel-restore-notify-link">'; |
| 119 | $message .= __( 'Restore notice', 'disable-admin-notices' ); |
| 120 | $message .= '</a></div>'; |
| 121 | |
| 122 | $wp_admin_bar->add_menu( [ |
| 123 | 'id' => 'wbcr-han-notify-panel-item-' . $i, |
| 124 | 'parent' => 'wbcr-han-notify-panel', |
| 125 | 'title' => $message, |
| 126 | 'href' => false, |
| 127 | 'meta' => [ |
| 128 | 'class' => '' |
| 129 | ] |
| 130 | ] ); |
| 131 | |
| 132 | $i ++; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | if ( current_user_can( 'manage_options' ) || ( is_multisite() && current_user_can( 'manage_network' ) ) ) { |
| 137 | // All |
| 138 | do_action( 'wdn/notifications/panel/all', $wp_admin_bar, $notifications_all, $i ); |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | public function noticesCollection() { |
| 144 | global $wbcr_dan_plugin_all_notices; |
| 145 | |
| 146 | if ( empty( $wbcr_dan_plugin_all_notices ) ) { |
| 147 | return; |
| 148 | } |
| 149 | ?> |
| 150 | <!-- Disable admin notices plugin (Clearfy tools) --> |
| 151 | <script> |
| 152 | jQuery(document).ready(function ($) { |
| 153 | $(document).on('click', '.wbcr-dan-hide-notice-link', function () { |
| 154 | var self = $(this), |
| 155 | target = self.data('target'), |
| 156 | noticeID = self.data('notice-id'), |
| 157 | nonce = self.data('nonce'), |
| 158 | noticeHtml = self.closest('.wbcr-dan-hide-links').prev('.wbcr-dan-hide-notices').clone(), |
| 159 | contanierEl = self.closest('.wbcr-dan-hide-links').prev('.wbcr-dan-hide-notices').parent(); |
| 160 | |
| 161 | contanierEl.find('.wbcr-dan-hide-links').remove(); |
| 162 | contanierEl.slideUp(); |
| 163 | |
| 164 | if (!noticeID) { |
| 165 | alert('Undefinded error. Please report the bug to our support forum.'); |
| 166 | } |
| 167 | |
| 168 | $.ajax(ajaxurl, { |
| 169 | type: 'post', |
| 170 | dataType: 'json', |
| 171 | data: { |
| 172 | action: 'wbcr-dan-hide-notices', |
| 173 | target: target, |
| 174 | security: nonce, |
| 175 | notice_id: noticeID, |
| 176 | notice_html: noticeHtml.html() |
| 177 | }, |
| 178 | success: function (response) { |
| 179 | if (!response || !response.success) { |
| 180 | |
| 181 | if (response.data.error_message) { |
| 182 | console.log(response.data.error_message); |
| 183 | self.closest('li').show(); |
| 184 | } else { |
| 185 | console.log(response); |
| 186 | } |
| 187 | |
| 188 | contanierEl.show(); |
| 189 | return; |
| 190 | } |
| 191 | |
| 192 | contanierEl.remove(); |
| 193 | }, |
| 194 | error: function (xhr, ajaxOptions, thrownError) { |
| 195 | console.log(xhr.status); |
| 196 | console.log(xhr.responseText); |
| 197 | console.log(thrownError); |
| 198 | } |
| 199 | }); |
| 200 | return false; |
| 201 | }); |
| 202 | }); |
| 203 | </script> |
| 204 | <?php |
| 205 | foreach ( $wbcr_dan_plugin_all_notices as $val ) { |
| 206 | echo $val; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | public |
| 211 | function catch_notices() { |
| 212 | global $wbcr_dan_plugin_all_notices; |
| 213 | |
| 214 | try { |
| 215 | $wp_filter_admin_notices = &wdan_get_wp_filter( 'admin_notices' ); |
| 216 | $wp_filter_all_admin_notices = &wdan_get_wp_filter( 'all_admin_notices' ); |
| 217 | |
| 218 | $wp_filter_notices = $this->array_merge( $wp_filter_admin_notices, $wp_filter_all_admin_notices ); |
| 219 | } catch ( Exception $e ) { |
| 220 | $wp_filter_notices = null; |
| 221 | } |
| 222 | |
| 223 | $hide_notices_type = $this->getPopulateOption( 'hide_admin_notices' ); |
| 224 | |
| 225 | if ( empty( $hide_notices_type ) || $hide_notices_type == 'only_selected' ) { |
| 226 | $get_hidden_notices = get_user_meta( get_current_user_id(), $this->plugin->getOptionName( 'hidden_notices' ), true ); |
| 227 | $get_hidden_notices_all = apply_filters( 'wdan/notifications/all', [] ); |
| 228 | |
| 229 | $content = []; |
| 230 | foreach ( (array) $wp_filter_notices as $filters ) { |
| 231 | foreach ( $filters as $callback_name => $callback ) { |
| 232 | |
| 233 | if ( 'usof_hide_admin_notices_start' == $callback_name || 'usof_hide_admin_notices_end' == $callback_name ) { |
| 234 | continue; |
| 235 | } |
| 236 | |
| 237 | ob_start(); |
| 238 | |
| 239 | // #CLRF-140 fix bug for php7 |
| 240 | // when the developers forgot to delete the argument in the function of implementing the notification. |
| 241 | $args = []; |
| 242 | $accepted_args = isset( $callback['accepted_args'] ) && ! empty( $callback['accepted_args'] ) ? $callback['accepted_args'] : 0; |
| 243 | |
| 244 | if ( $accepted_args > 0 ) { |
| 245 | for ( $i = 0; $i < (int) $accepted_args; $i ++ ) { |
| 246 | $args[] = null; |
| 247 | } |
| 248 | } |
| 249 | //=========== |
| 250 | |
| 251 | call_user_func_array( $callback['function'], $args ); |
| 252 | $cont = ob_get_clean(); |
| 253 | |
| 254 | if ( empty( $cont ) ) { |
| 255 | continue; |
| 256 | } |
| 257 | |
| 258 | $salt = is_multisite() ? get_current_blog_id() : ''; |
| 259 | $txt = preg_replace( '/<(script|style)([^>]+)?>(.*?)<\/(script|style)>/is', '', $cont ); |
| 260 | $uniq_id1 = md5( strip_tags( str_replace( [ "\t", "\r", "\n", " " ], "", $txt ) ) . $salt ); |
| 261 | $uniq_id2 = md5( $callback_name . $salt ); |
| 262 | |
| 263 | if ( is_array( $callback['function'] ) && sizeof( $callback['function'] ) == 2 ) { |
| 264 | $class = $callback['function'][0]; |
| 265 | if ( is_object( $class ) ) { |
| 266 | $class_name = get_class( $class ); |
| 267 | $method_name = $callback['function'][1]; |
| 268 | $uniq_id2 = md5( $class_name . ':' . $method_name ); |
| 269 | } |
| 270 | } |
| 271 | //$txt = rtrim( trim( $txt ) ); |
| 272 | //$txt = preg_replace( '/^(<div[^>]+>)(.*?)(<\/div>)$/is', '<p>$2</p>', $txt ); |
| 273 | |
| 274 | // All |
| 275 | $skip_notice = apply_filters( 'wdn/notifications/catch/all', true, $get_hidden_notices_all, $uniq_id1, $uniq_id2 ); |
| 276 | if ( ! $skip_notice ) { |
| 277 | continue; |
| 278 | } |
| 279 | |
| 280 | if ( ! empty( $get_hidden_notices ) ) { |
| 281 | $skip_notice = true; |
| 282 | foreach ( (array) $get_hidden_notices as $key => $notice ) { |
| 283 | $splited_notice_id = explode( '_', $key ); |
| 284 | if ( empty( $splited_notice_id ) || sizeof( $splited_notice_id ) < 2 ) { |
| 285 | continue; |
| 286 | } |
| 287 | $compare_notice_id_1 = $splited_notice_id[0]; |
| 288 | $compare_notice_id_2 = $splited_notice_id[1]; |
| 289 | |
| 290 | if ( $compare_notice_id_1 == $uniq_id1 || $compare_notice_id_2 == $uniq_id2 ) { |
| 291 | $skip_notice = false; |
| 292 | break; |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | if ( ! $skip_notice ) { |
| 297 | continue; |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | $nonce = wp_create_nonce( $this->plugin->getPluginName() . '_ajax_hide_notices_nonce' ); |
| 302 | $hide_link_for_me = "<button data-target='user' data-nonce='{$nonce}' data-notice-id='{$uniq_id1}_{$uniq_id2}' class='wbcr-dan-hide-notice-link'>" . __( 'Hide <b>for me</b>', 'disable-admin-notices' ) . "</button>"; |
| 303 | $hide_link_for_all = ""; |
| 304 | |
| 305 | if ( current_user_can( 'manage_options' ) || ( is_multisite() && current_user_can( 'manage_network' ) ) ) { |
| 306 | $hide_link_for_all = "<button data-target='all' data-nonce='{$nonce}' data-notice-id='{$uniq_id1}_{$uniq_id2}' class='wbcr-dan-hide-notice-link'>" . __( 'Hide <b>for all</b>', 'disable-admin-notices' ) . "</button>"; |
| 307 | } |
| 308 | |
| 309 | if ( strpos( $cont, 'redux-connect-message' ) ) { |
| 310 | $a = 1; |
| 311 | } |
| 312 | |
| 313 | // Fix for Woocommerce membership and Jetpack message |
| 314 | if ( $cont != '<div class="js-wc-memberships-admin-notice-placeholder"></div>' && false === strpos( $cont, 'jetpack-jitm-message' ) ) { |
| 315 | $cont = rtrim( trim( $cont ) ); |
| 316 | // Insert opening wrapper right after the first opening <div> |
| 317 | $cont = preg_replace( |
| 318 | '/(<div\b[^>]*>)/i', |
| 319 | '$1<div class="wbcr-dan-hide-notices">', |
| 320 | $cont, |
| 321 | 1 |
| 322 | ); |
| 323 | |
| 324 | // Insert closing wrapper + links div before the LAST closing </div> |
| 325 | $cont = preg_replace( |
| 326 | '/<\/div>(?!.*<\/div>)/is', |
| 327 | '</div><div class="wbcr-dan-hide-links">' . $hide_link_for_me . ' ' . $hide_link_for_all . '</div></div>', |
| 328 | $cont, |
| 329 | 1 |
| 330 | ); |
| 331 | } |
| 332 | |
| 333 | if ( empty( $cont ) ) { |
| 334 | continue; |
| 335 | } |
| 336 | $content[] = $cont; |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | $wbcr_dan_plugin_all_notices = $content; |
| 341 | } |
| 342 | |
| 343 | wdan_clear_all_notices( 'user_admin_notices' ); |
| 344 | wdan_clear_all_notices( 'network_admin_notices' ); |
| 345 | wdan_clear_all_notices( 'admin_notices', [ |
| 346 | 'Learndash_Admin_Menus_Tabs', |
| 347 | 'WC_Memberships_Admin', |
| 348 | 'YIT_Plugin_Panel_WooCommerce' |
| 349 | ], [ 'et_pb_export_layouts_interface' ] ); |
| 350 | |
| 351 | wdan_clear_all_notices( 'all_admin_notices', [ |
| 352 | 'Learndash_Admin_Menus_Tabs', |
| 353 | 'WC_Memberships_Admin', |
| 354 | 'YIT_Plugin_Panel_WooCommerce' |
| 355 | ], [ 'et_pb_export_layouts_interface' ] ); |
| 356 | } |
| 357 | |
| 358 | |
| 359 | /** |
| 360 | * Get excerpt from string |
| 361 | * |
| 362 | * @param String $str String to get an excerpt from |
| 363 | * @param Integer $startPos Position int string to start excerpt from |
| 364 | * @param Integer $maxLength Maximum length the excerpt may be |
| 365 | * |
| 366 | * @return String excerpt |
| 367 | */ |
| 368 | public |
| 369 | function getExcerpt( |
| 370 | $str, $startPos = 0, $maxLength = 100 |
| 371 | ) { |
| 372 | if ( strlen( $str ) > $maxLength ) { |
| 373 | $excerpt = substr( $str, $startPos, $maxLength - 3 ); |
| 374 | $lastSpace = strrpos( $excerpt, ' ' ); |
| 375 | $excerpt = substr( $excerpt, 0, $lastSpace ); |
| 376 | $excerpt .= '...'; |
| 377 | } else { |
| 378 | $excerpt = $str; |
| 379 | } |
| 380 | |
| 381 | return $excerpt; |
| 382 | } |
| 383 | |
| 384 | /** |
| 385 | * @param array $arr1 |
| 386 | * @param array $arr2 |
| 387 | * |
| 388 | * @return array |
| 389 | */ |
| 390 | protected |
| 391 | function array_merge( |
| 392 | array $arr1, array $arr2 |
| 393 | ) { |
| 394 | if ( ! empty( $arr2 ) ) { |
| 395 | foreach ( $arr2 as $key => $value ) { |
| 396 | if ( ! isset( $arr1[ $key ] ) ) { |
| 397 | $arr1[ $key ] = $value; |
| 398 | } else if ( is_array( $arr1[ $key ] ) ) { |
| 399 | $arr1[ $key ] = $arr1[ $key ] + $value; |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | return $arr1; |
| 405 | } |
| 406 | |
| 407 | public function hide_nags() { |
| 408 | ?> |
| 409 | <?php if ( $this->plugin->getPopulateOption( 'disable_updates_nags_for_plugins' ) ): ?> |
| 410 | <style> |
| 411 | .update-message, #wp-admin-bar-updates, span.update-plugins { |
| 412 | display: none !important; |
| 413 | } |
| 414 | </style> |
| 415 | <?php endif; ?> |
| 416 | <?php if ( $this->plugin->getPopulateOption( 'disable_updates_nags_for_core' ) ): ?> |
| 417 | <style> |
| 418 | div.update-nag { |
| 419 | display: none !important; |
| 420 | } |
| 421 | </style> |
| 422 | <?php endif; ?> |
| 423 | <?php if ( "compact_panel" === $this->plugin->getPopulateOption( 'hide_admin_notices' ) ): ?> |
| 424 | <style id="wdan-disable-notices-style"> |
| 425 | div.updated, div.error, div.notice, div.wdan-notice { |
| 426 | display: none !important; |
| 427 | } |
| 428 | </style> |
| 429 | <style> |
| 430 | .wdan-notices-compact-panel { |
| 431 | background: #fff; |
| 432 | border: 1px solid #cecccc; |
| 433 | |
| 434 | cursor: pointer; |
| 435 | margin-bottom: 20px; |
| 436 | padding: 5px 5px 5px 5px; |
| 437 | margin: 10px 0 5px 0; |
| 438 | } |
| 439 | |
| 440 | .wdan-notices-compact-panel.wdan-oppened { |
| 441 | cursor: default; |
| 442 | } |
| 443 | |
| 444 | .wdan-notices-compact-panel h3 { |
| 445 | display: inline-block; |
| 446 | color: #32373c; |
| 447 | font-weight: normal; |
| 448 | font-size: 13px; |
| 449 | margin: 0; |
| 450 | } |
| 451 | |
| 452 | .wdan-notices-compact-panel h3 .dashicons { |
| 453 | height: 20px; |
| 454 | width: 20px; |
| 455 | font-size: 20px; |
| 456 | line-height: 0.8; |
| 457 | |
| 458 | } |
| 459 | |
| 460 | .wdan-notices-compact-panel.wdan-oppened .wdan-notices-compact-panel__title > .dashicons { |
| 461 | -webkit-transform: rotateX(180deg); |
| 462 | transform: rotateX(180deg); |
| 463 | line-height: 1; |
| 464 | } |
| 465 | |
| 466 | .wdan-notices-compact-panel ul { |
| 467 | display: block; |
| 468 | float: right; |
| 469 | margin: 0; |
| 470 | |
| 471 | } |
| 472 | |
| 473 | .wdan-notices-compact-panel__notices { |
| 474 | display: none; |
| 475 | padding: 15px; |
| 476 | } |
| 477 | |
| 478 | .wdan-notices-compact-panel.wdan-oppened .wdan-notices-compact-panel__notices { |
| 479 | display: block; |
| 480 | } |
| 481 | |
| 482 | .wdan-notices-compact-panel__error { |
| 483 | color: red; |
| 484 | } |
| 485 | |
| 486 | .wdan-notices-compact-panel__warning { |
| 487 | background-color: #2271b1; |
| 488 | border-color: #2271b1; |
| 489 | border-radius: 50%; |
| 490 | color: #fff; |
| 491 | text-align: center; |
| 492 | display: flex; |
| 493 | justify-content: center; |
| 494 | align-items: center; |
| 495 | width: 20px; |
| 496 | height: 20px; |
| 497 | } |
| 498 | |
| 499 | .wdan-notices-compact-panel__success { |
| 500 | color: green; |
| 501 | } |
| 502 | </style> |
| 503 | <?php endif; ?> |
| 504 | <?php |
| 505 | } |
| 506 | |
| 507 | public function catch_compact_notice() { |
| 508 | if ( "compact_panel" !== $this->plugin->getPopulateOption( 'hide_admin_notices' ) ) { |
| 509 | return; |
| 510 | } |
| 511 | |
| 512 | $content = wdan_collect_notices( 'admin_notices' ); |
| 513 | $content = array_merge( $content, wdan_collect_notices( 'all_admin_notices' ) ); |
| 514 | |
| 515 | wdan_clear_all_notices( 'admin_notices', [ |
| 516 | 'Learndash_Admin_Menus_Tabs', |
| 517 | 'WC_Memberships_Admin', |
| 518 | 'YIT_Plugin_Panel_WooCommerce' |
| 519 | ], [ 'et_pb_export_layouts_interface' ] ); |
| 520 | |
| 521 | wdan_clear_all_notices( 'all_admin_notices', [ |
| 522 | 'Learndash_Admin_Menus_Tabs', |
| 523 | 'WC_Memberships_Admin', |
| 524 | 'YIT_Plugin_Panel_WooCommerce' |
| 525 | ], [ 'et_pb_export_layouts_interface' ] ); |
| 526 | |
| 527 | if ( empty( $content ) ) { |
| 528 | return; |
| 529 | } |
| 530 | |
| 531 | add_action( 'admin_notices', function () use ( $content ) { |
| 532 | foreach ( $content as $html ) { |
| 533 | echo "<div class='wdan-notice'>" . base64_encode( $html ) . "</div>"; |
| 534 | } |
| 535 | } ); |
| 536 | } |
| 537 | |
| 538 | public function show_compact_panel() { |
| 539 | if ( "compact_panel" !== $this->plugin->getPopulateOption( 'hide_admin_notices' ) ) { |
| 540 | return; |
| 541 | } |
| 542 | ?> |
| 543 | |
| 544 | <script> |
| 545 | jQuery(document).ready(function ($) { |
| 546 | |
| 547 | function wdanB64DecodeUnicode(str) { |
| 548 | // Going backwards: from bytestream, to percent-encoding, to original string. |
| 549 | return decodeURIComponent(atob(str).split('').map(function (c) { |
| 550 | return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); |
| 551 | }).join('')); |
| 552 | } |
| 553 | |
| 554 | let notices = $('div.updated, div.error, div.notice, div.update-nag, div.wdan-notice').not('.inline, .below-h2').not('.inline').detach(), |
| 555 | contanier = $('.wdan-notices-compact-panel').detach(), |
| 556 | $headerEnd = $('.wp-header-end'); |
| 557 | |
| 558 | notices.each(function () { |
| 559 | contanier.find('.wdan-notices-compact-panel__notices').append("<div class='wdan-notice'>" + wdanB64DecodeUnicode($(this).html()) + "</div>"); |
| 560 | }); |
| 561 | |
| 562 | /* |
| 563 | * The `.below-h2` class is here just for backward compatibility with plugins |
| 564 | * that are (incorrectly) using it. Do not use. Use `.inline` instead. See #34570. |
| 565 | * If '.wp-header-end' is found, append the notices after it otherwise |
| 566 | * after the first h1 or h2 heading found within the main content. |
| 567 | */ |
| 568 | if (!$headerEnd.length) { |
| 569 | $headerEnd = $('.wrap h1, .wrap h2').first(); |
| 570 | } |
| 571 | |
| 572 | $headerEnd.after(contanier); |
| 573 | |
| 574 | let compactPanelNoticesEl = $('.wdan-notices-compact-panel__notices'), |
| 575 | other = compactPanelNoticesEl.find('div.wdan-notice').length; |
| 576 | |
| 577 | $('.wdan-notices-compact-panel__warning').find('span').text(other); |
| 578 | |
| 579 | $('#wdan-disable-notices-style').remove(); |
| 580 | contanier.show(); |
| 581 | |
| 582 | contanier.find('.wdan-notices-compact-panel__button').click(function () { |
| 583 | $(this).parent().toggleClass('wdan-oppened'); |
| 584 | return false; |
| 585 | }); |
| 586 | |
| 587 | }); |
| 588 | </script> |
| 589 | <div class="wdan-notices-compact-panel" style="display: none;"> |
| 590 | <div class="wdan-notices-compact-panel__button"> |
| 591 | <h3 class="wdan-notices-compact-panel__title"> |
| 592 | <span class="dashicons dashicons-arrow-down"></span> |
| 593 | <?php esc_html_e( 'Notifications', 'disable-admin-notices' ); ?> |
| 594 | </h3> |
| 595 | <ul> |
| 596 | <li class="wdan-notices-compact-panel__warning"> |
| 597 | <span>0</span> |
| 598 | </li> |
| 599 | </ul> |
| 600 | </div> |
| 601 | <div class="wdan-notices-compact-panel__notices"> |
| 602 | |
| 603 | </div> |
| 604 | </div> |
| 605 | <?php |
| 606 | } |
| 607 | |
| 608 | public function notifications_all() { |
| 609 | return $this->plugin->getPopulateOption( 'hidden_notices', [] ); |
| 610 | } |
| 611 | |
| 612 | /** |
| 613 | * @param $wp_admin_bar WP_Admin_Bar |
| 614 | * @param $notifications array |
| 615 | */ |
| 616 | public function notifications_panel_all( $wp_admin_bar, $notifications, $i ) { |
| 617 | if ( ! empty( $notifications ) ) { |
| 618 | $wp_admin_bar->add_menu( [ |
| 619 | 'id' => 'wbcr-han-notify-panel-group-all', |
| 620 | 'parent' => 'wbcr-han-notify-panel', |
| 621 | 'title' => __( 'Hidden for all', 'disable-admin-notices' ), |
| 622 | 'href' => false, |
| 623 | 'meta' => [ |
| 624 | 'class' => '' |
| 625 | ] |
| 626 | ] ); |
| 627 | |
| 628 | foreach ( $notifications as $notice_id => $message ) { |
| 629 | $message = wp_kses( $message, [] ); |
| 630 | $message = $this->getExcerpt( stripslashes( $message ), 0, 350 ); |
| 631 | $message .= '<div class="wbcr-han-panel-restore-notify-line">'; |
| 632 | $message .= '<a href="#" data-nonce="' . wp_create_nonce( $this->plugin->getPluginName() . '_ajax_restore_notice_nonce' ); |
| 633 | $message .= '" data-notice-id="' . esc_attr( $notice_id ) . '" class="wbcr-han-panel-restore-notify-link">'; |
| 634 | $message .= __( 'Restore notice', 'disable-admin-notices' ); |
| 635 | $message .= '</a></div>'; |
| 636 | |
| 637 | $wp_admin_bar->add_menu( [ |
| 638 | 'id' => 'wbcr-han-notify-panel-item-' . $i, |
| 639 | 'parent' => 'wbcr-han-notify-panel', |
| 640 | 'title' => $message, |
| 641 | 'href' => false, |
| 642 | 'meta' => [ |
| 643 | 'class' => '' |
| 644 | ] |
| 645 | ] ); |
| 646 | |
| 647 | $i ++; |
| 648 | } |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | /** |
| 653 | * @param $hidden_notices |
| 654 | * @param $uniq_id1 |
| 655 | * @param $uniq_id2 |
| 656 | * |
| 657 | * @return bool |
| 658 | */ |
| 659 | public function catch_notices_all( $skip_notice, $hidden_notices, $uniq_id1, $uniq_id2 ) { |
| 660 | $skip_notice = true; |
| 661 | if ( ! empty( $hidden_notices ) ) { |
| 662 | foreach ( (array) $hidden_notices as $key => $notice ) { |
| 663 | $splited_notice_id = explode( '_', $key ); |
| 664 | if ( empty( $splited_notice_id ) || sizeof( $splited_notice_id ) < 2 ) { |
| 665 | continue; |
| 666 | } |
| 667 | $compare_notice_id_1 = $splited_notice_id[0]; |
| 668 | $compare_notice_id_2 = $splited_notice_id[1]; |
| 669 | |
| 670 | if ( $compare_notice_id_1 == $uniq_id1 || $compare_notice_id_2 == $uniq_id2 ) { |
| 671 | $skip_notice = false; |
| 672 | break; |
| 673 | } |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | return $skip_notice; |
| 678 | } |
| 679 | } |