PluginProbe
SpinupWP / 1.0
SpinupWP v1.0
trunk 1.0 1.0.1 1.0.2 1.0.3 1.1 1.1.1 1.1.2 1.2 1.3 1.4 1.4.1 1.4.2 1.5 1.5.1 1.6 1.7 1.7.1 1.8.0 1.9.0 1.9.1
spinupwp / src / AdminNotices.php

AdminNotices.php in SpinupWP 1.0, at src/AdminNotices.php

94 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace DeliciousBrains\SpinupWp;
4
5 class AdminNotices {
6
7 /**
8 * @var string
9 */
10 public $url;
11
12 /**
13 * AdminNotices constructor.
14 *
15 * @param string $url
16 */
17 public function __construct( $url ) {
18 $this->url = $url;
19 }
20
21 /**
22 * Init
23 */
24 public function init() {
25 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
26 add_action( 'wp_ajax_spinupwp_dismiss_notice', array( $this, 'ajax_dismiss_notice' ) );
27
28 if ( is_multisite() ) {
29 add_action( 'network_admin_notices', array( $this, 'show_notices' ) );
30 } else {
31 add_action( 'admin_notices', array( $this, 'show_notices' ) );
32 }
33 }
34
35 /**
36 * Enqueue admin scripts.
37 */
38 public function enqueue_scripts() {
39 if ( ! current_user_can( 'manage_options' ) ) {
40 return;
41 }
42
43 wp_enqueue_script( 'spinupwp-dismiss', $this->url . 'assets/js/dismiss-notice.js', array( 'jquery' ), '1.0' );
44 }
45
46 /**
47 * Handle AJAX request to dismiss notice.
48 */
49 public function ajax_dismiss_notice() {
50 if ( ! check_ajax_referer( 'dismiss-notice', 'nonce', false ) || ! current_user_can( 'manage_options' ) ) {
51 wp_die( - 1, 403 );
52 }
53
54 $notice = filter_var( $_POST['notice'], FILTER_SANITIZE_STRING );
55
56 update_site_option( "spinupwp_{$notice}_notice_dismissed", true );
57 }
58
59 /**
60 * Show notices.
61 */
62 public function show_notices() {
63 $this->show_mail_notice();
64 $this->show_redis_cache_disabled_notice();
65 }
66
67 /**
68 * Show a notice about configuring mail.
69 */
70 public function show_mail_notice() {
71 if ( ! current_user_can( 'manage_options' ) || get_site_option( 'spinupwp_mail_notice_dismissed' ) ) {
72 return;
73 }
74
75 $msg = __( 'Your site is ready to go! You will need to set up email if you wish to send outgoing emails from this site.', 'spinupwp' );
76 $link = sprintf( '<a href="%s">%s &raquo;</a>', 'https://spinupwp.com/doc/setting-up-transactional-email-wordpress/?utm_campaign=support%2Bdocs&utm_source=SpinupWP%2BMU&utm_medium=insideplugin', __( 'More info', 'spinupwp' ) );
77 $nonce = wp_create_nonce( 'dismiss-notice' );
78 echo "<div class=\"spinupwp notice notice-success is-dismissible\" data-nonce=\"{$nonce}\" data-notice=\"mail\"><p><strong>SpinupWP</strong> — {$msg} {$link}</p></div>";
79 }
80
81 /**
82 * Show a notice about Redis Object Cache plugin being disabled.
83 */
84 public function show_redis_cache_disabled_notice() {
85 if ( ! current_user_can( 'manage_options' ) || ! get_site_option( 'spinupwp_redis_cache_disabled' ) || get_site_option( 'spinupwp_redis_cache_disabled_notice_dismissed' ) ) {
86 return;
87 }
88
89 $msg = __( 'The Redis Object Cache plugin has been deactivated and can be removed. The SpinupWP plugin now handles clearing the Redis object cache.', 'spinupwp' );
90 $nonce = wp_create_nonce( 'dismiss-notice' );
91 echo "<div class=\"spinupwp notice notice-success is-dismissible\" data-nonce=\"{$nonce}\" data-notice=\"redis_cache_disabled\"><p><strong>SpinupWP</strong> — {$msg}</p></div>";
92 }
93 }
94