← All changes
|
freemius/includes/managers/class-fs-admin-notice-manager.php
+23
-89
8.0.2
→
2.1.2
View file →
| @@ -159,12 +159,9 @@ | ||
| 159 | 159 | $msg['id'], |
| 160 | 160 | false, |
| 161 | 161 | isset( $msg['wp_user_id'] ) ? $msg['wp_user_id'] : null, |
| 162 | 162 | ! empty( $msg['plugin'] ) ? $msg['plugin'] : null, |
| 163 | - $is_network_and_blog_admins, | |
| 164 | - isset( $msg['dismissible'] ) ? | |
| 165 | - $msg['dismissible'] : | |
| 166 | - null | |
| 163 | + $is_network_and_blog_admins | |
| 167 | 164 | ); |
| 168 | 165 | } |
| 169 | 166 | } |
| 170 | 167 | } |
| @@ -177,14 +174,9 @@ | ||
| 177 | 174 | * @since 1.0.7 |
| 178 | 175 | * |
| 179 | 176 | */ |
| 180 | 177 | function dismiss_notice_ajax_callback() { |
| 181 | - check_admin_referer( 'fs_dismiss_notice_action' ); | |
| 182 | - | |
| 183 | - if ( ! is_numeric( $_POST['message_id'] ) ) { | |
| 184 | - $this->_sticky_storage->remove( $_POST['message_id'] ); | |
| 185 | - } | |
| 186 | - | |
| 178 | + $this->_sticky_storage->remove( $_POST['message_id'] ); | |
| 187 | 179 | wp_die(); |
| 188 | 180 | } |
| 189 | 181 | |
| 190 | 182 | /** |
| @@ -193,16 +185,10 @@ | ||
| 193 | 185 | * @author Vova Feldman (@svovaf) |
| 194 | 186 | * @since 1.0.7 |
| 195 | 187 | */ |
| 196 | 188 | static function _add_sticky_dismiss_javascript() { |
| 197 | - $sticky_admin_notice_js_template_name = 'sticky-admin-notice-js.php'; | |
| 198 | - | |
| 199 | - if ( ! file_exists( fs_get_template_path( $sticky_admin_notice_js_template_name ) ) ) { | |
| 200 | - return; | |
| 201 | - } | |
| 202 | - | |
| 203 | 189 | $params = array(); |
| 204 | - fs_require_once_template( $sticky_admin_notice_js_template_name, $params ); | |
| 190 | + fs_require_once_template( 'sticky-admin-notice-js.php', $params ); | |
| 205 | 191 | } |
| 206 | 192 | |
| 207 | 193 | private static $_added_sticky_javascript = false; |
| 208 | 194 | |
| @@ -232,8 +218,11 @@ | ||
| 232 | 218 | // Only show messages to admins. |
| 233 | 219 | return; |
| 234 | 220 | } |
| 235 | 221 | |
| 222 | + | |
| 223 | + $show_admin_notices = ( ! $this->is_gutenberg_page() ); | |
| 224 | + | |
| 236 | 225 | foreach ( $this->_notices as $id => $msg ) { |
| 237 | 226 | if ( isset( $msg['wp_user_id'] ) && is_numeric( $msg['wp_user_id'] ) ) { |
| 238 | 227 | if ( get_current_user_id() != $msg['wp_user_id'] ) { |
| 239 | 228 | continue; |
| @@ -274,9 +263,9 @@ | ||
| 274 | 263 | */ |
| 275 | 264 | $show_notice = call_user_func_array( 'fs_apply_filter', array( |
| 276 | 265 | $this->_module_unique_affix, |
| 277 | 266 | 'show_admin_notice', |
| 278 | - $this->show_admin_notices(), | |
| 267 | + $show_admin_notices, | |
| 279 | 268 | $msg |
| 280 | 269 | ) ); |
| 281 | 270 | |
| 282 | 271 | if ( true !== $show_notice ) { |
| @@ -329,32 +318,8 @@ | ||
| 329 | 318 | return false; |
| 330 | 319 | } |
| 331 | 320 | |
| 332 | 321 | /** |
| 333 | - * Check if admin notices should be shown on page. E.g., we don't want to show notices in the Visual Editor. | |
| 334 | - * | |
| 335 | - * @author Xiaheng Chen (@xhchen) | |
| 336 | - * @since 2.4.2 | |
| 337 | - * | |
| 338 | - * @return bool | |
| 339 | - */ | |
| 340 | - function show_admin_notices() { | |
| 341 | - global $pagenow; | |
| 342 | - | |
| 343 | - if ( 'about.php' === $pagenow ) { | |
| 344 | - // Don't show admin notices on the About page. | |
| 345 | - return false; | |
| 346 | - } | |
| 347 | - | |
| 348 | - if ( $this->is_gutenberg_page() ) { | |
| 349 | - // Don't show admin notices in Gutenberg (visual editor). | |
| 350 | - return false; | |
| 351 | - } | |
| 352 | - | |
| 353 | - return true; | |
| 354 | - } | |
| 355 | - | |
| 356 | - /** | |
| 357 | 322 | * Add admin message to admin messages queue, and hook to admin_notices / all_admin_notices if not yet hooked. |
| 358 | 323 | * |
| 359 | 324 | * @author Vova Feldman (@svovaf) |
| 360 | 325 | * @since 1.0.4 |
| @@ -368,10 +333,8 @@ | ||
| 368 | 333 | * @param number|null $wp_user_id |
| 369 | 334 | * @param string|null $plugin_title |
| 370 | 335 | * @param bool $is_network_and_blog_admins Whether or not the message should be shown both on network |
| 371 | 336 | * and blog admin pages. |
| 372 | - * @param bool|null $is_dismissible | |
| 373 | - * @param array $data | |
| 374 | 337 | * |
| 375 | 338 | * @uses add_action() |
| 376 | 339 | */ |
| 377 | 340 | function add( |
| @@ -382,11 +345,9 @@ | ||
| 382 | 345 | $id = '', |
| 383 | 346 | $store_if_sticky = true, |
| 384 | 347 | $wp_user_id = null, |
| 385 | 348 | $plugin_title = null, |
| 386 | - $is_network_and_blog_admins = false, | |
| 387 | - $is_dismissible = null, | |
| 388 | - $data = array() | |
| 349 | + $is_network_and_blog_admins = false | |
| 389 | 350 | ) { |
| 390 | 351 | $notices_type = $this->get_notices_type(); |
| 391 | 352 | |
| 392 | 353 | if ( empty( $this->_notices ) ) { |
| @@ -404,18 +365,16 @@ | ||
| 404 | 365 | $id = md5( $title . ' ' . $message . ' ' . $type ); |
| 405 | 366 | } |
| 406 | 367 | |
| 407 | 368 | $message_object = array( |
| 408 | - 'message' => $message, | |
| 409 | - 'title' => $title, | |
| 410 | - 'type' => $type, | |
| 411 | - 'sticky' => $is_sticky, | |
| 412 | - 'id' => $id, | |
| 413 | - 'manager_id' => $this->_id, | |
| 414 | - 'plugin' => ( ! is_null( $plugin_title ) ? $plugin_title : $this->_title ), | |
| 415 | - 'wp_user_id' => $wp_user_id, | |
| 416 | - 'dismissible' => $is_dismissible, | |
| 417 | - 'data' => $data | |
| 369 | + 'message' => $message, | |
| 370 | + 'title' => $title, | |
| 371 | + 'type' => $type, | |
| 372 | + 'sticky' => $is_sticky, | |
| 373 | + 'id' => $id, | |
| 374 | + 'manager_id' => $this->_id, | |
| 375 | + 'plugin' => ( ! is_null( $plugin_title ) ? $plugin_title : $this->_title ), | |
| 376 | + 'wp_user_id' => $wp_user_id, | |
| 418 | 377 | ); |
| 419 | 378 | |
| 420 | 379 | if ( $is_sticky && $store_if_sticky ) { |
| 421 | 380 | $this->_sticky_storage->{$id} = $message_object; |
| @@ -428,11 +387,10 @@ | ||
| 428 | 387 | * @author Vova Feldman (@svovaf) |
| 429 | 388 | * @since 1.0.7 |
| 430 | 389 | * |
| 431 | 390 | * @param string|string[] $ids |
| 432 | - * @param bool $store | |
| 433 | 391 | */ |
| 434 | - function remove_sticky( $ids, $store = true ) { | |
| 392 | + function remove_sticky( $ids ) { | |
| 435 | 393 | if ( ! is_array( $ids ) ) { |
| 436 | 394 | $ids = array( $ids ); |
| 437 | 395 | } |
| 438 | 396 | |
| @@ -437,9 +395,9 @@ | ||
| 437 | 395 | } |
| 438 | 396 | |
| 439 | 397 | foreach ( $ids as $id ) { |
| 440 | 398 | // Remove from sticky storage. |
| 441 | - $this->_sticky_storage->remove( $id, $store ); | |
| 399 | + $this->_sticky_storage->remove( $id ); | |
| 442 | 400 | |
| 443 | 401 | if ( isset( $this->_notices[ $id ] ) ) { |
| 444 | 402 | unset( $this->_notices[ $id ] ); |
| 445 | 403 | } |
| @@ -473,50 +431,26 @@ | ||
| 473 | 431 | * @param number|null $wp_user_id |
| 474 | 432 | * @param string|null $plugin_title |
| 475 | 433 | * @param bool $is_network_and_blog_admins Whether or not the message should be shown both on network |
| 476 | 434 | * and blog admin pages. |
| 477 | - * @param bool $is_dimissible | |
| 478 | - * @param array $data | |
| 479 | 435 | */ |
| 480 | - function add_sticky( $message, $id, $title = '', $type = 'success', $wp_user_id = null, $plugin_title = null, $is_network_and_blog_admins = false, $is_dimissible = true, $data = array() ) { | |
| 436 | + function add_sticky( $message, $id, $title = '', $type = 'success', $wp_user_id = null, $plugin_title = null, $is_network_and_blog_admins = false ) { | |
| 481 | 437 | if ( ! empty( $this->_module_unique_affix ) ) { |
| 482 | 438 | $message = fs_apply_filter( $this->_module_unique_affix, "sticky_message_{$id}", $message ); |
| 483 | 439 | $title = fs_apply_filter( $this->_module_unique_affix, "sticky_title_{$id}", $title ); |
| 484 | 440 | } |
| 485 | 441 | |
| 486 | - $this->add( $message, $title, $type, true, $id, true, $wp_user_id, $plugin_title, $is_network_and_blog_admins, $is_dimissible, $data ); | |
| 442 | + $this->add( $message, $title, $type, true, $id, true, $wp_user_id, $plugin_title, $is_network_and_blog_admins ); | |
| 487 | 443 | } |
| 488 | 444 | |
| 489 | 445 | /** |
| 490 | - * Retrieves the data of an sticky notice. | |
| 491 | - * | |
| 492 | - * @author Leo Fajardo (@leorw) | |
| 493 | - * @since 2.4.3 | |
| 494 | - * | |
| 495 | - * @param string $id Message ID. | |
| 496 | - * | |
| 497 | - * @return array|null | |
| 498 | - */ | |
| 499 | - function get_sticky( $id ) { | |
| 500 | - return isset( $this->_sticky_storage->{$id} ) ? | |
| 501 | - $this->_sticky_storage->{$id} : | |
| 502 | - null; | |
| 503 | - } | |
| 504 | - | |
| 505 | - /** | |
| 506 | 446 | * Clear all sticky messages. |
| 507 | 447 | * |
| 508 | 448 | * @author Vova Feldman (@svovaf) |
| 509 | 449 | * @since 1.0.8 |
| 510 | - * | |
| 511 | - * @param bool $is_temporary @since 2.5.1 | |
| 512 | 450 | */ |
| 513 | - function clear_all_sticky( $is_temporary = false ) { | |
| 514 | - if ( $is_temporary ) { | |
| 515 | - $this->_notices = array(); | |
| 516 | - } else { | |
| 517 | - $this->_sticky_storage->clear_all(); | |
| 518 | - } | |
| 451 | + function clear_all_sticky() { | |
| 452 | + $this->_sticky_storage->clear_all(); | |
| 519 | 453 | } |
| 520 | 454 | |
| 521 | 455 | #-------------------------------------------------------------------------------- |
| 522 | 456 | #region Helper Method |
| @@ -534,5 +468,5 @@ | ||
| 534 | 468 | 'admin_notices'; |
| 535 | 469 | } |
| 536 | 470 | |
| 537 | 471 | #endregion |
| 538 | - } | |
| 472 | + } | |