PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 2.0.3
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v2.0.3
3.5.2 3.5.1 3.5.0 3.4.8 3.4.7 3.4.6 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5.1 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.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.6.1 1.6.7 1.7.0 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.2 1.7.2.1 1.7.2.2 1.7.3 1.7.4 1.7.5 1.7.5.1 1.7.5.2 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.8.0 1.8.0.1 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.0.1 1.9.1 1.9.2 1.9.3 1.9.4 1.9.4.1 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.0.1 2.0.1 2.0.2 2.0.3 2.0.3.1 2.0.4 2.0.4.1 2.0.5 2.0.6 2.0.7 2.0.8 2.0.8.1 2.0.9 3.0.0 3.0.0.1 3.0.1 3.0.2 3.0.3 3.0.3.1 3.0.4 3.0.4.1 3.0.4.2 3.0.5 3.0.5.1 3.0.5.2 3.0.6 3.0.6.1 3.0.7.1 3.0.8 3.0.8.1 3.0.9 3.0.9.1 3.0.9.2 3.0.9.3 3.0.9.4 3.0.9.5 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.3.0 3.4.0 3.4.1 3.4.2 3.4.2.1 3.4.3 3.4.4 3.4.5 trunk 1.0 1.0.1 1.0.2 1.0.3
everest-forms / includes / admin / class-evf-admin-notices.php
everest-forms / includes / admin Last commit date
builder 2 years ago plugin-updates 8 years ago settings 2 years ago views 2 years ago class-evf-admin-addons.php 4 years ago class-evf-admin-assets.php 2 years ago class-evf-admin-builder.php 7 years ago class-evf-admin-deactivation-feedback.php 3 years ago class-evf-admin-editor.php 4 years ago class-evf-admin-entries-table-list.php 3 years ago class-evf-admin-entries.php 4 years ago class-evf-admin-form-templates.php 3 years ago class-evf-admin-forms-table-list.php 3 years ago class-evf-admin-forms.php 3 years ago class-evf-admin-import-export.php 4 years ago class-evf-admin-menus.php 2 years ago class-evf-admin-notices.php 3 years ago class-evf-admin-settings.php 2 years ago class-evf-admin-tools.php 4 years ago class-evf-admin-welcome.php 2 years ago class-evf-admin.php 2 years ago evf-admin-functions.php 3 years ago
class-evf-admin-notices.php
396 lines
1 <?php
2 /**
3 * Display notices in admin
4 *
5 * @package EverestForms/Admin
6 * @version 1.0.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * EVF_Admin_Notices Class.
13 */
14 class EVF_Admin_Notices {
15
16 /**
17 * Stores notices.
18 *
19 * @var array
20 */
21 private static $notices = array();
22
23 /**
24 * Array of notices - name => callback.
25 *
26 * @var array
27 */
28 private static $core_notices = array(
29 'update' => 'update_notice',
30 'review' => 'review_notice',
31 'survey' => 'survey_notice',
32 'allow_usage' => 'allow_usage_notice',
33 'php_deprecation' => 'php_deprecation_notice',
34 );
35
36 /**
37 * Constructor.
38 */
39 public static function init() {
40 self::$notices = get_option( 'everest_forms_admin_notices', array() );
41
42 add_action( 'switch_theme', array( __CLASS__, 'reset_admin_notices' ) );
43 add_action( 'everest_forms_installed', array( __CLASS__, 'reset_admin_notices' ) );
44 add_action( 'wp_loaded', array( __CLASS__, 'hide_notices' ) );
45 add_action( 'shutdown', array( __CLASS__, 'store_notices' ) );
46
47 if ( current_user_can( 'manage_everest_forms' ) ) {
48 add_action( 'admin_print_styles', array( __CLASS__, 'add_notices' ) );
49 add_action( 'in_admin_header', array( __CLASS__, 'hide_unrelated_notices' ) );
50 }
51 }
52
53 /**
54 * Store notices to DB
55 */
56 public static function store_notices() {
57 update_option( 'everest_forms_admin_notices', self::get_notices() );
58 }
59
60 /**
61 * Get notices.
62 *
63 * @return array
64 */
65 public static function get_notices() {
66 return self::$notices;
67 }
68
69 /**
70 * Remove all notices.
71 */
72 public static function remove_all_notices() {
73 self::$notices = array();
74 }
75
76 /**
77 * Reset notices for themes when switched or a new version of EVF is installed.
78 */
79 public static function reset_admin_notices() {
80 if ( self::is_plugin_active( 'everest-forms-stripe/everest-forms-stripe.php' ) ) {
81 self::add_notice( 'deprecated_payment_charge' );
82 }
83 self::add_notice( 'review' );
84 self::add_notice( 'survey' );
85 self::add_notice( 'allow_usage' );
86 self::add_notice( 'php_deprecation' );
87 }
88
89 /**
90 * Show a notice.
91 *
92 * @param string $name Notice name.
93 */
94 public static function add_notice( $name ) {
95 self::$notices = array_unique( array_merge( self::get_notices(), array( $name ) ) );
96 }
97
98 /**
99 * Remove a notice from being displayed.
100 *
101 * @param string $name Notice name.
102 */
103 public static function remove_notice( $name ) {
104 self::$notices = array_diff( self::get_notices(), array( $name ) );
105 delete_option( 'everest_forms_admin_notice_' . $name );
106 }
107
108 /**
109 * See if a notice is being shown.
110 *
111 * @param string $name Notice name.
112 * @return boolean
113 */
114 public static function has_notice( $name ) {
115 return in_array( $name, self::get_notices(), true );
116 }
117
118 /**
119 * Hide a notice if the GET variable is set.
120 */
121 public static function hide_notices() {
122 if ( isset( $_GET['evf-hide-notice'] ) && isset( $_GET['_evf_notice_nonce'] ) ) {
123 if ( ! wp_verify_nonce( sanitize_key( wp_unslash( $_GET['_evf_notice_nonce'] ) ), 'everest_forms_hide_notices_nonce' ) ) {
124 wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'everest-forms' ) );
125 }
126
127 if ( ! current_user_can( 'manage_everest_forms' ) ) {
128 wp_die( esc_html__( 'You don&#8217;t have permission to do this.', 'everest-forms' ) );
129 }
130
131 $hide_notice = sanitize_text_field( wp_unslash( $_GET['evf-hide-notice'] ) );
132
133 self::remove_notice( $hide_notice );
134
135 update_user_meta( get_current_user_id(), 'dismissed_' . $hide_notice . '_notice', true );
136
137 do_action( 'everest_forms_hide_' . $hide_notice . '_notice' );
138 }
139 }
140
141 /**
142 * Add notices + styles if needed.
143 */
144 public static function add_notices() {
145 $notices = self::get_notices();
146
147 if ( empty( $notices ) ) {
148 return;
149 }
150
151 $screen = get_current_screen();
152 $screen_id = $screen ? $screen->id : '';
153 $show_on_screens = array(
154 'dashboard',
155 'plugins',
156 );
157
158 // Notices should only show on Everest Forms screens, the main dashboard, and on the plugins screen.
159 if ( ! in_array( $screen_id, evf_get_screen_ids(), true ) && ! in_array( $screen_id, $show_on_screens, true ) ) {
160 return;
161 }
162
163 wp_enqueue_style( 'everest-forms-activation', plugins_url( '/assets/css/activation.css', EVF_PLUGIN_FILE ), array(), EVF_VERSION );
164
165 // Add RTL support.
166 wp_style_add_data( 'everest-forms-activation', 'rtl', 'replace' );
167
168 foreach ( $notices as $notice ) {
169 if ( ! empty( self::$core_notices[ $notice ] ) && apply_filters( 'everest_forms_show_admin_notice', true, $notice ) ) {
170 add_action( 'admin_notices', array( __CLASS__, self::$core_notices[ $notice ] ) );
171 } else {
172 add_action( 'admin_notices', array( __CLASS__, 'output_custom_notices' ) );
173 }
174 }
175 }
176
177 /**
178 * Add a custom notice.
179 *
180 * @param string $name Notice name.
181 * @param string $notice_html Notice html.
182 */
183 public static function add_custom_notice( $name, $notice_html ) {
184 self::add_notice( $name );
185 update_option( 'everest_forms_admin_notice_' . $name, wp_kses_post( $notice_html ) );
186 }
187
188 /**
189 * Output any stored custom notices.
190 */
191 public static function output_custom_notices() {
192 $notices = self::get_notices();
193
194 if ( ! empty( $notices ) ) {
195 foreach ( $notices as $notice ) {
196 if ( empty( self::$core_notices[ $notice ] ) ) {
197 $notice_html = get_option( 'everest_forms_admin_notice_' . $notice );
198
199 if ( $notice_html ) {
200 include 'views/html-notice-custom.php';
201 }
202 }
203 }
204 }
205 }
206
207 /**
208 * If we need to update, include a message with the update button.
209 */
210 public static function update_notice() {
211 if ( EVF_Install::needs_db_update() ) {
212 $updater = new EVF_Background_Updater();
213
214 if ( $updater->is_updating() || ! empty( $_GET['do_update_everest_forms'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
215 include 'views/html-notice-updating.php';
216 } else {
217 include 'views/html-notice-update.php';
218 }
219 } else {
220 EVF_Install::update_db_version();
221 include 'views/html-notice-updated.php';
222 }
223 }
224
225 /**
226 * If we need reviews, include a message requesting review.
227 */
228 public static function review_notice() {
229 global $wpdb;
230
231 // Check if another notice is showing.
232 if ( self::survey_notice( true ) ) {
233 return;
234 }
235
236 $load = false;
237 $time = time();
238 $review = get_option( 'everest_forms_review' );
239 $activated = get_option( 'everest_forms_activated' );
240
241 // Verify for review.
242 if ( ! $review ) {
243 $review = array(
244 'time' => $time,
245 'dismissed' => false,
246 );
247 update_option( 'everest_forms_review', $review );
248 } else {
249 // Check if it has been dismissed or not.
250 if ( ( isset( $review['dismissed'] ) && ! $review['dismissed'] ) && ( isset( $review['time'] ) && ( ( $review['time'] + DAY_IN_SECONDS ) <= $time ) ) ) {
251 $load = true;
252 }
253 }
254
255 // Continue only if review request criteria meets.
256 if ( $load && class_exists( 'EverestForms_Pro', false ) ) {
257 $entries_count = $wpdb->get_var( "SELECT COUNT(entry_id) FROM {$wpdb->prefix}evf_entries WHERE `status` = 'publish'" );
258
259 // Only continue if the site has collected at least 50 entries.
260 if ( empty( $entries_count ) || $entries_count < 50 ) {
261 return;
262 }
263 } else {
264 // Only continue if plugin has been installed for at least 14 days.
265 if ( ( $activated + ( WEEK_IN_SECONDS * 2 ) ) > $time ) {
266 return;
267 }
268 }
269
270 // Ask for some love.
271 if ( $load && ( is_super_admin() || current_user_can( 'manage_everest_forms' ) ) ) {
272 include 'views/html-notice-review.php';
273 }
274 }
275
276 /**
277 * If we need survey, include a message requesting survey.
278 *
279 * @param boolean $status Twice notice to check.
280 * @return boolean
281 */
282 public static function survey_notice( $status = false ) {
283
284 $time = time();
285 $survey = get_option( 'everest_forms_survey' );
286 $activated = get_option( 'everest_forms_activated' );
287 $license_key = trim( get_option( 'everest-forms-pro_license_key' ) );
288
289 if ( ! empty( $survey['dismissed'] ) ) {
290 return;
291 }
292
293 // Only continue if plugin has been installed for at least 10 days.
294 if ( ( $activated + ( DAY_IN_SECONDS * 10 ) ) > $time ) {
295 return;
296 }
297
298 if ( ! $status && $license_key && ( is_super_admin() || current_user_can( 'manage_everest_forms' ) ) ) {
299 include 'views/html-notice-survey.php';
300 }
301
302 return $status;
303
304 }
305
306 /**
307 * Include allow usage & discount notice.
308 */
309 public static function allow_usage_notice() {
310
311 $show_notice = true;
312 $allow_usage_notice_shown = get_option( 'everest_forms_allow_usage_notice_shown', false );
313 $allow_usage_tracking = get_option( 'everest_forms_allow_usage_tracking' );
314 $activated = get_option( 'everest_forms_activated' );
315
316 if ( 'yes' === $allow_usage_tracking || ( $activated + DAY_IN_SECONDS > time() ) || $allow_usage_notice_shown ) {
317 $show_notice = false;
318 }
319
320 if ( $show_notice && ( is_super_admin() || current_user_can( 'manage_everest_forms' ) ) ) {
321 include 'views/html-notice-allow-usage.php';
322 }
323 }
324
325 /**
326 * Include PHp deprecation Notice
327 */
328 public static function php_deprecation_notice() {
329 $php_version = explode( '-', PHP_VERSION )[0];
330 $base_version = '7.2';
331 if ( version_compare( $php_version, $base_version, '<' ) ) {
332 $last_prompt_date = get_option( 'everest_forms_php_deprecated_notice_last_prompt_date', '' );
333 if ( empty( $last_prompt_date ) || strtotime( $last_prompt_date ) < strtotime( '-1 day' ) ) {
334 $prompt_limit = 3;
335 $prompt_count = get_option( 'everest_forms_php_deprecated_notice_prompt_count', 0 );
336
337 if ( $prompt_count < $prompt_limit ) {
338 include 'views/html-notice-php-deprecation.php';
339 }
340 }
341 }
342 }
343
344 /**
345 * Remove non-EverestForms notices from EverestForms pages.
346 *
347 * @since 1.2.0
348 */
349 public static function hide_unrelated_notices() {
350 global $wp_filter;
351
352 // Bail if we're not on a EverestForms screen or page.
353 if ( empty( $_REQUEST['page'] ) || false === strpos( sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ), 'evf-' ) ) { // phpcs:ignore WordPress.Security.NonceVerification
354 return;
355 }
356
357 foreach ( array( 'user_admin_notices', 'admin_notices', 'all_admin_notices' ) as $wp_notice ) {
358 if ( ! empty( $wp_filter[ $wp_notice ]->callbacks ) && is_array( $wp_filter[ $wp_notice ]->callbacks ) ) {
359 foreach ( $wp_filter[ $wp_notice ]->callbacks as $priority => $hooks ) {
360 foreach ( $hooks as $name => $arr ) {
361 if ( is_object( $arr['function'] ) && $arr['function'] instanceof Closure ) {
362 unset( $wp_filter[ $wp_notice ]->callbacks[ $priority ][ $name ] );
363 continue;
364 }
365 if ( ( isset( $_GET['tab'], $_GET['form_id'] ) || isset( $_GET['create-form'] ) ) && 'evf-builder' === $_REQUEST['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification
366 unset( $wp_filter[ $wp_notice ]->callbacks[ $priority ][ $name ] );
367 continue;
368 }
369 if ( ! empty( $arr['function'][0] ) && is_object( $arr['function'][0] ) && false !== strpos( strtolower( get_class( $arr['function'][0] ) ), 'evf_' ) ) {
370 continue;
371 }
372 if ( ! empty( $name ) && false === strpos( strtolower( $name ), 'evf_' ) ) {
373 unset( $wp_filter[ $wp_notice ]->callbacks[ $priority ][ $name ] );
374 }
375 }
376 }
377 }
378 }
379 }
380
381 /**
382 * Wrapper for is_plugin_active.
383 *
384 * @param string $plugin Plugin to check.
385 * @return boolean
386 */
387 protected static function is_plugin_active( $plugin ) {
388 if ( ! function_exists( 'is_plugin_active' ) ) {
389 include_once ABSPATH . 'wp-admin/includes/plugin.php';
390 }
391 return is_plugin_active( $plugin );
392 }
393 }
394
395 EVF_Admin_Notices::init();
396