PluginProbe
SpinupWP / 1.3
SpinupWP v1.3
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.3, at src/AdminNotices.php

125 lines 4.1 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 $this->show_object_cache_dropin_updated_notice();
66 }
67
68 /**
69 * Show a notice about configuring mail.
70 */
71 public function show_mail_notice() {
72 if ( ! current_user_can( 'manage_options' ) || get_site_option( 'spinupwp_mail_notice_dismissed' ) ) {
73 return;
74 }
75
76 $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' );
77 $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' ) );
78 $nonce = wp_create_nonce( 'dismiss-notice' );
79 echo "<div class=\"spinupwp notice notice-success is-dismissible\" data-nonce=\"{$nonce}\" data-notice=\"mail\"><p><strong>SpinupWP</strong> — {$msg} {$link}</p></div>";
80 }
81
82 /**
83 * Show a notice about Redis Object Cache plugin being disabled.
84 */
85 public function show_redis_cache_disabled_notice() {
86 if ( ! current_user_can( 'manage_options' ) || ! get_site_option( 'spinupwp_redis_cache_disabled' ) || get_site_option( 'spinupwp_redis_cache_disabled_notice_dismissed' ) ) {
87 return;
88 }
89
90 $msg = __( 'The Redis Object Cache plugin has been deactivated and can be removed. The SpinupWP plugin now handles clearing the Redis object cache.', 'spinupwp' );
91 $nonce = wp_create_nonce( 'dismiss-notice' );
92 echo "<div class=\"spinupwp notice notice-success is-dismissible\" data-nonce=\"{$nonce}\" data-notice=\"redis_cache_disabled\"><p><strong>SpinupWP</strong> — {$msg}</p></div>";
93 }
94
95 /**
96 * Show a notice when the object-cache.php drop-in has been updated.
97 */
98 public function show_object_cache_dropin_updated_notice() {
99 $wpcontent_dir = untrailingslashit( WP_CONTENT_DIR );
100
101 if ( file_exists( $wpcontent_dir . '/object-cache.php' ) ) {
102 $plugin_path = untrailingslashit( dirname( __DIR__ ) );
103
104 $dropin = get_plugin_data( $wpcontent_dir . '/object-cache.php' );
105 $plugin = get_plugin_data( $plugin_path . '/drop-ins/object-cache.php' );
106
107 if ( $dropin['PluginURI'] !== $plugin['PluginURI'] ) {
108 return;
109 }
110
111 if ( version_compare( $dropin['Version'], $plugin['Version'], '<' ) ) {
112 @unlink( $wpcontent_dir . '/object-cache.php' );
113
114 if ( @copy( $plugin_path . '/drop-ins/object-cache.php', $wpcontent_dir . '/object-cache.php' ) ) {
115 $msg = __( 'Object cache drop-in updated.', 'spinupwp' );
116 echo "<div class=\"spinupwp notice notice-success\"><p><strong>SpinupWP</strong> — {$msg}</p></div>";
117 } else {
118 $msg = __( 'Object cache drop-in could not be updated.', 'spinupwp' );
119 echo "<div class=\"spinupwp notice notice-error\"><p><strong>SpinupWP</strong> — {$msg}</p></div>";
120 }
121 }
122 }
123 }
124 }
125