PluginProbe
Flash Toolkit / 1.2.4
Flash Toolkit v1.2.4
trunk 1.0 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6
flash-toolkit / includes / admin / class-flash-admin-notices.php

class-flash-admin-notices.php in Flash Toolkit 1.2.4, at includes/admin/class-flash-admin-notices.php

326 lines 8.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Display notices in admin.
4 *
5 * @class FT_Admin_Notices
6 * @version 1.0.0
7 * @package FlashToolkit/Admin
8 * @category Admin
9 * @author ThemeGrill
10 */
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 /**
17 * FT_Admin_Notices Class
18 */
19 class FT_Admin_Notices {
20
21 /**
22 * Stores notices.
23 *
24 * @var array
25 */
26 private static $notices = array();
27
28 /**
29 * Currently activated theme name.
30 *
31 * @since 1.2.0
32 * @var string
33 */
34 protected static $active_theme;
35
36 /**
37 * Array of notices - name => callback
38 *
39 * @var array
40 */
41 private static $core_notices = array(
42 'update' => 'update_notice',
43 );
44
45 /**
46 * Constructor.
47 */
48 public static function init() {
49 self::$notices = get_option( 'flash_toolkit_admin_notices', array() );
50
51 add_action( 'wp_loaded', array( __CLASS__, 'hide_notices' ) );
52 add_action( 'shutdown', array( __CLASS__, 'store_notices' ) );
53
54 self::$active_theme = wp_get_theme();
55
56
57 if ( current_user_can( 'manage_flash_toolkit' ) ) {
58 add_action( 'admin_print_styles', array( __CLASS__, 'add_notices' ) );
59 }
60
61 add_action( 'wp_loaded', array( __CLASS__, 'pro_notice' ) );
62
63 }
64
65 /**
66 * Store notices to DB
67 */
68 public static function store_notices() {
69 update_option( 'flash_toolkit_admin_notices', self::get_notices() );
70 }
71
72 /**
73 * Hooks for showing Pro theme notice.
74 *
75 * @since 1.2.0
76 */
77 public static function pro_notice() {
78
79 if ( 'Flash' != self::$active_theme ) {
80 return;
81 }
82
83 $option = get_option( 'flash_pro_notice_start_time' );
84 if ( ! $option ) {
85 update_option( 'flash_pro_notice_start_time', time() );
86 }
87
88 add_action( 'admin_notices', array( __CLASS__, 'pro_notice_markup' ), 0 );
89 add_action( 'admin_init', array( __CLASS__, 'pro_notice_temporary_ignore' ), 0 );
90 add_action( 'admin_init', array( __CLASS__, 'pro_notice_permanent_ignore' ), 0 );
91
92 }
93
94 /**
95 * Shows the Pro version notice as per various conditions.
96 *
97 * @since 1.2.0
98 */
99 public static function pro_notice_markup() {
100
101 $current_user = wp_get_current_user();
102
103 $temporary_ignore = get_user_meta( $current_user->ID, 'flash_pro_notice_temporary_ignore', true );
104 $permanent_ignore = get_user_meta( $current_user->ID, 'flash_pro_notice_permanent_ignore', true );
105
106 if ( ( get_option( 'flash_pro_notice_start_time' ) > strtotime( '-20 day' ) ) || ( $temporary_ignore > strtotime( '-20 day' ) ) || $permanent_ignore ) {
107 return;
108 }
109 ?>
110
111 <div class="updated pro-theme-notice">
112 <h3 class="pro-notice-heading"><?php esc_html_e( 'Unlock true potential of Flash!', 'flash-toolkit' ); ?></h3>
113
114 <p class="pro-notice-message">
115 <?php
116 printf(
117 esc_html__(
118 'Howdy, %1$s! You\'ve been using %2$s for a while now, and we hope you\'re happy with it. If you need more options and want to get access to the premium features, check the pricing by clicking link below. Also, you can use the coupon code %3$s to get 15 percent discount while making the purchase. Enjoy!', 'flash-toolkit'
119 ),
120 '<strong>' . esc_html( $current_user->display_name ) . '</strong>',
121 self::$active_theme,
122 '<code>upgrade15</code>'
123 );
124 ?>
125 </p> <!-- /.pro-notice-message -->
126
127 <a class="notice-dismiss" href="?flash_pro_notice_temporary_ignore_nag=1"></a>
128
129 <div class="ft-cta">
130 <?php
131 $pro_link = '<a target="_blank" href=" ' . esc_url( "https://themegrill.com/plans-pricing/" ) . ' ">' . esc_html( 'Go Pro' ) . ' </a>';
132 ?>
133
134 <a href="https://themegrill.com/pricing/?pid=1294971&vid=1294974&utm_source=dashboard-message&utm_medium=view-pricing-link&utm_campaign=upgrade"
135 class="btn button-primary" target="_blank">
136 <span class="dashicons dashicons-thumbs-up"></span>
137 <span class="cta-text"><?php esc_html_e( 'Go Pro', 'flash-toolkit' ); ?></span>
138 </a>
139
140 <a href="?flash_pro_notice_temporary_ignore_nag=1" class="btn button-secondary">
141 <span class="dashicons dashicons-calendar-alt"></span>
142 <span class="cta-text"><?php esc_html_e( 'Remind me later', 'flash-toolkit' ); ?></span>
143 </a>
144
145 <a href="?flash_pro_notice_permanent_ignore_nag=1" class="btn button-secondary">
146 <span class="dashicons dashicons-smiley"></span>
147 <span class="cta-text"><?php esc_html_e( 'I already have Pro version', 'flash-toolkit' ); ?></span>
148 </a>
149
150 <a href="https://themegrill.com/contact/" class="btn button-secondary" target="_blank">
151 <span class="dashicons dashicons-edit"></span>
152 <span class="cta-text"><?php esc_html_e( 'Got any queries?', 'flash-toolkit' ); ?></span>
153 </a>
154
155 </div> <!-- /.ft-cta -->
156 </div> <!-- /.pro-theme-notice -->
157
158 <?php
159 }
160
161 /**
162 * Removes the notice temporarily for the specific user only.
163 *
164 * @since 1.2.0
165 */
166 public static function pro_notice_temporary_ignore() {
167
168 if ( isset( $_GET['flash_pro_notice_temporary_ignore_nag'] ) && '1' == $_GET['flash_pro_notice_temporary_ignore_nag'] ) {
169 update_user_meta( get_current_user_id(), 'flash_pro_notice_temporary_ignore', time() );
170 }
171
172 }
173
174 /**
175 * Removes the notice permanently for the specific user only.
176 *
177 * @since 1.2.0
178 */
179 public static function pro_notice_permanent_ignore() {
180
181 if ( isset( $_GET['flash_pro_notice_permanent_ignore_nag'] ) && '1' == $_GET['flash_pro_notice_permanent_ignore_nag'] ) {
182 add_user_meta( get_current_user_id(), 'flash_pro_notice_permanent_ignore', 'true', true );
183 }
184
185 }
186
187 /**
188 * Get notices.
189 *
190 * @return array
191 */
192 public static function get_notices() {
193 return self::$notices;
194 }
195
196 /**
197 * Remove all notices.
198 */
199 public static function remove_all_notices() {
200 self::$notices = array();
201 }
202
203 /**
204 * Show a notice.
205 *
206 * @param string $name
207 */
208 public static function add_notice( $name ) {
209 self::$notices = array_unique( array_merge( self::get_notices(), array( $name ) ) );
210 }
211
212 /**
213 * Remove a notice from being displayed.
214 *
215 * @param string $name
216 */
217 public static function remove_notice( $name ) {
218 self::$notices = array_diff( self::get_notices(), array( $name ) );
219 delete_option( 'flash_toolkit_admin_notice_' . $name );
220 }
221
222 /**
223 * See if a notice is being shown.
224 *
225 * @param string $name
226 *
227 * @return boolean
228 */
229 public static function has_notice( $name ) {
230 return in_array( $name, self::get_notices() );
231 }
232
233 /**
234 * Hide a notice if the GET variable is set.
235 */
236 public static function hide_notices() {
237 if ( isset( $_GET['flash-toolkit-hide-notice'] ) && isset( $_GET['_flash_toolkit_notice_nonce'] ) ) {
238 if ( ! wp_verify_nonce( $_GET['_flash_toolkit_notice_nonce'], 'flash_toolkit_hide_notices_nonce' ) ) {
239 wp_die( __( 'Action failed. Please refresh the page and retry.', 'flash-toolkit' ) );
240 }
241
242 if ( ! current_user_can( 'manage_flash_toolkit' ) ) {
243 wp_die( __( 'Cheatin&#8217; huh?', 'flash-toolkit' ) );
244 }
245
246 $hide_notice = sanitize_text_field( $_GET['flash-toolkit-hide-notice'] );
247
248 self::remove_notice( $hide_notice );
249
250 update_user_meta( get_current_user_id(), 'dismissed_' . $hide_notice . '_notice', true );
251
252 do_action( 'flash_toolkit_hide_' . $hide_notice . '_notice' );
253 }
254 }
255
256 /**
257 * Add notices + styles if needed.
258 */
259 public static function add_notices() {
260 $notices = self::get_notices();
261
262 if ( $notices ) {
263 wp_enqueue_style( 'flash-toolkit-activation', FT()->plugin_url() . '/assets/css/activation.css', array(), FT_VERSION );
264
265 // Add RTL support
266 wp_style_add_data( 'flash-toolkit-activation', 'rtl', 'replace' );
267
268 foreach ( $notices as $notice ) {
269 if ( ! empty( self::$core_notices[ $notice ] ) && apply_filters( 'flash_toolkit_show_admin_notice', true, $notice ) ) {
270 add_action( 'admin_notices', array( __CLASS__, self::$core_notices[ $notice ] ) );
271 } else {
272 add_action( 'admin_notices', array( __CLASS__, 'output_custom_notices' ) );
273 }
274 }
275 }
276 }
277
278 /**
279 * Add a custom notice.
280 *
281 * @param string $name
282 * @param string $notice_html
283 */
284 public static function add_custom_notice( $name, $notice_html ) {
285 self::add_notice( $name );
286 update_option( 'flash_toolkit_admin_notice_' . $name, wp_kses_post( $notice_html ) );
287 }
288
289 /**
290 * Output any stored custom notices.
291 */
292 public static function output_custom_notices() {
293 $notices = self::get_notices();
294
295 if ( $notices ) {
296 foreach ( $notices as $notice ) {
297 if ( empty( self::$core_notices[ $notice ] ) ) {
298 $notice_html = get_option( 'flash_toolkit_admin_notice_' . $notice );
299
300 if ( $notice_html ) {
301 include( 'views/html-notice-custom.php' );
302 }
303 }
304 }
305 }
306 }
307
308 /**
309 * If we need to update, include a message with the update button.
310 */
311 public static function update_notice() {
312 if ( version_compare( get_option( 'flash_toolkit_db_version' ), FT_VERSION, '<' ) ) {
313 $updater = new FT_Background_Updater();
314 if ( $updater->is_updating() || ! empty( $_GET['do_update_flash_toolkit'] ) ) {
315 include( 'views/html-notice-updating.php' );
316 } else {
317 include( 'views/html-notice-update.php' );
318 }
319 } else {
320 include( 'views/html-notice-updated.php' );
321 }
322 }
323 }
324
325 FT_Admin_Notices::init();
326