PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 3.5.2
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v3.5.2
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 4 weeks ago form-migrator 4 weeks ago plugin-updates 8 years ago settings 4 weeks ago views 4 weeks ago class-evf-admin-addons.php 4 months ago class-evf-admin-assets.php 1 week ago class-evf-admin-builder.php 2 months ago class-evf-admin-dashboard.php 4 weeks ago class-evf-admin-editor.php 4 years ago class-evf-admin-embed-wizard.php 2 years ago class-evf-admin-entries-table-list.php 2 months ago class-evf-admin-entries.php 2 months ago class-evf-admin-form-templates.php 4 weeks ago class-evf-admin-forms-table-list.php 4 months ago class-evf-admin-forms.php 4 months ago class-evf-admin-import-export.php 4 weeks ago class-evf-admin-menus.php 4 weeks ago class-evf-admin-notices.php 4 months ago class-evf-admin-preview-confirmation.php 1 year ago class-evf-admin-settings.php 4 weeks ago class-evf-admin-tools.php 2 months ago class-evf-admin-welcome.php 2 years ago class-evf-admin.php 2 months ago class-evf-base-list-table.php 4 months ago evf-admin-functions.php 4 weeks ago
class-evf-admin-notices.php
414 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 'email_failed' => 'email_failed_notice',
35 );
36
37 /**
38 * Constructor.
39 */
40 public static function init() {
41 self::$notices = get_option( 'everest_forms_admin_notices', array() );
42
43 add_action( 'switch_theme', array( __CLASS__, 'reset_admin_notices' ) );
44 add_action( 'everest_forms_installed', array( __CLASS__, 'reset_admin_notices' ) );
45 add_action( 'wp_loaded', array( __CLASS__, 'hide_notices' ) );
46 add_action( 'shutdown', array( __CLASS__, 'store_notices' ) );
47
48 if ( current_user_can( 'manage_everest_forms' ) ) {
49 add_action( 'admin_print_styles', array( __CLASS__, 'add_notices' ) );
50 add_action( 'in_admin_header', array( __CLASS__, 'hide_unrelated_notices' ) );
51 }
52 }
53
54 /**
55 * Store notices to DB
56 */
57 public static function store_notices() {
58 update_option( 'everest_forms_admin_notices', self::get_notices() );
59 }
60
61 /**
62 * Get notices.
63 *
64 * @return array
65 */
66 public static function get_notices() {
67 return self::$notices;
68 }
69
70 /**
71 * Remove all notices.
72 */
73 public static function remove_all_notices() {
74 self::$notices = array();
75 }
76
77 /**
78 * Reset notices for themes when switched or a new version of EVF is installed.
79 */
80 public static function reset_admin_notices() {
81 if ( self::is_plugin_active( 'everest-forms-stripe/everest-forms-stripe.php' ) ) {
82 self::add_notice( 'deprecated_payment_charge' );
83 }
84 self::add_notice( 'review' );
85 self::add_notice( 'survey' );
86 self::add_notice( 'allow_usage' );
87 self::add_notice( 'php_deprecation' );
88 self::add_notice( 'email_failed' );
89 }
90
91 /**
92 * Show a notice.
93 *
94 * @param string $name Notice name.
95 */
96 public static function add_notice( $name ) {
97 self::$notices = array_unique( array_merge( self::get_notices(), array( $name ) ) );
98 }
99
100 /**
101 * Remove a notice from being displayed.
102 *
103 * @param string $name Notice name.
104 */
105 public static function remove_notice( $name ) {
106 self::$notices = array_diff( self::get_notices(), array( $name ) );
107 delete_option( 'everest_forms_admin_notice_' . $name );
108 }
109
110 /**
111 * See if a notice is being shown.
112 *
113 * @param string $name Notice name.
114 * @return boolean
115 */
116 public static function has_notice( $name ) {
117 return in_array( $name, self::get_notices(), true );
118 }
119
120 /**
121 * Hide a notice if the GET variable is set.
122 */
123 public static function hide_notices() {
124 if ( isset( $_GET['evf-hide-notice'] ) && isset( $_GET['_evf_notice_nonce'] ) ) {
125 if ( ! wp_verify_nonce( sanitize_key( wp_unslash( $_GET['_evf_notice_nonce'] ) ), 'everest_forms_hide_notices_nonce' ) ) {
126 wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'everest-forms' ) );
127 }
128
129 if ( ! current_user_can( 'manage_everest_forms' ) ) {
130 wp_die( esc_html__( 'You don&#8217;t have permission to do this.', 'everest-forms' ) );
131 }
132
133 $hide_notice = sanitize_text_field( wp_unslash( $_GET['evf-hide-notice'] ) );
134
135 self::remove_notice( $hide_notice );
136
137 update_user_meta( get_current_user_id(), 'dismissed_' . $hide_notice . '_notice', true );
138
139 do_action( 'everest_forms_hide_' . $hide_notice . '_notice' );
140 }
141 }
142
143 /**
144 * Add notices + styles if needed.
145 */
146 public static function add_notices() {
147 $notices = self::get_notices();
148
149 if ( empty( $notices ) ) {
150 return;
151 }
152
153 $screen = get_current_screen();
154 $screen_id = $screen ? $screen->id : '';
155 $show_on_screens = array(
156 'dashboard',
157 'plugins',
158 );
159
160 // Notices should only show on Everest Forms screens, the main dashboard, and on the plugins screen.
161 if ( ! in_array( $screen_id, evf_get_screen_ids(), true ) && ! in_array( $screen_id, $show_on_screens, true ) ) {
162 return;
163 }
164
165 wp_enqueue_style( 'everest-forms-activation', plugins_url( '/assets/css/activation.css', EVF_PLUGIN_FILE ), array(), EVF_VERSION );
166
167 // Add RTL support.
168 wp_style_add_data( 'everest-forms-activation', 'rtl', 'replace' );
169
170 foreach ( $notices as $notice ) {
171 if ( ! empty( self::$core_notices[ $notice ] ) && apply_filters( 'everest_forms_show_admin_notice', true, $notice ) ) {
172 add_action( 'admin_notices', array( __CLASS__, self::$core_notices[ $notice ] ) );
173 } else {
174 add_action( 'admin_notices', array( __CLASS__, 'output_custom_notices' ) );
175 }
176 }
177 }
178
179 /**
180 * Add a custom notice.
181 *
182 * @param string $name Notice name.
183 * @param string $notice_html Notice html.
184 */
185 public static function add_custom_notice( $name, $notice_html ) {
186 self::add_notice( $name );
187 update_option( 'everest_forms_admin_notice_' . $name, wp_kses_post( $notice_html ) );
188 }
189
190 /**
191 * Output any stored custom notices.
192 */
193 public static function output_custom_notices() {
194 $notices = self::get_notices();
195
196 if ( ! empty( $notices ) ) {
197 foreach ( $notices as $notice ) {
198 if ( empty( self::$core_notices[ $notice ] ) ) {
199 $notice_html = get_option( 'everest_forms_admin_notice_' . $notice );
200
201 if ( $notice_html ) {
202 include 'views/html-notice-custom.php';
203 }
204 }
205 }
206 }
207 }
208
209 /**
210 * If we need to update, include a message with the update button.
211 */
212 public static function update_notice() {
213 if ( EVF_Install::needs_db_update() ) {
214 $updater = new EVF_Background_Updater();
215
216 if ( $updater->is_updating() || ! empty( $_GET['do_update_everest_forms'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
217 include 'views/html-notice-updating.php';
218 } else {
219 include 'views/html-notice-update.php';
220 }
221 } else {
222 EVF_Install::update_db_version();
223 include 'views/html-notice-updated.php';
224 }
225 }
226
227 /**
228 * If we need reviews, include a message requesting review.
229 */
230 public static function review_notice() {
231 global $wpdb;
232
233 // Check if another notice is showing.
234 if ( self::survey_notice( true ) ) {
235 return;
236 }
237
238 $load = false;
239 $time = time();
240 $review = get_option( 'everest_forms_review' );
241 $activated = get_option( 'everest_forms_activated' );
242
243 // Verify for review.
244 if ( ! $review ) {
245 $review = array(
246 'time' => $time,
247 'dismissed' => false,
248 );
249 update_option( 'everest_forms_review', $review );
250 } else {
251 // Check if it has been dismissed or not.
252 if ( ( isset( $review['dismissed'] ) && ! $review['dismissed'] ) && ( isset( $review['time'] ) && ( ( $review['time'] + DAY_IN_SECONDS ) <= $time ) ) ) {
253 $load = true;
254 }
255 }
256
257 // Continue only if review request criteria meets.
258 if ( $load && class_exists( 'EverestForms_Pro', false ) ) {
259 $entries_count = $wpdb->get_var( "SELECT COUNT(entry_id) FROM {$wpdb->prefix}evf_entries WHERE `status` = 'publish'" );
260
261 // Only continue if the site has collected at least 50 entries.
262 if ( empty( $entries_count ) || $entries_count < 50 ) {
263 return;
264 }
265 } else {
266 // Only continue if plugin has been installed for at least 14 days.
267 if ( ( $activated + ( WEEK_IN_SECONDS * 2 ) ) > $time ) {
268 return;
269 }
270 }
271
272 // Ask for some love.
273 if ( $load && ( is_super_admin() || current_user_can( 'manage_everest_forms' ) ) ) {
274 include 'views/html-notice-review.php';
275 }
276 }
277
278 /**
279 * If we need survey, include a message requesting survey.
280 *
281 * @param boolean $status Twice notice to check.
282 * @return boolean
283 */
284 public static function survey_notice( $status = false ) {
285
286 $time = time();
287 $survey = get_option( 'everest_forms_survey' );
288 $activated = get_option( 'everest_forms_activated' );
289 $license_key = trim( get_option( 'everest-forms-pro_license_key' ) );
290
291 if ( ! empty( $survey['dismissed'] ) ) {
292 return;
293 }
294
295 // Only continue if plugin has been installed for at least 10 days.
296 if ( ( $activated + ( DAY_IN_SECONDS * 10 ) ) > $time ) {
297 return;
298 }
299
300 if ( ! $status && $license_key && ( is_super_admin() || current_user_can( 'manage_everest_forms' ) ) ) {
301 include 'views/html-notice-survey.php';
302 }
303
304 return $status;
305 }
306
307 /**
308 * Include allow usage & discount notice.
309 */
310 public static function allow_usage_notice() {
311
312 $show_notice = true;
313 $allow_usage_notice_shown = get_option( 'everest_forms_allow_usage_notice_shown', false );
314 $allow_usage_tracking = get_option( 'everest_forms_allow_usage_tracking' );
315 $activated = get_option( 'everest_forms_activated' );
316
317 if ( 'yes' === $allow_usage_tracking || ( $activated + DAY_IN_SECONDS > time() ) || $allow_usage_notice_shown ) {
318 $show_notice = false;
319 }
320
321 if ( $show_notice && ( is_super_admin() || current_user_can( 'manage_everest_forms' ) ) ) {
322 include 'views/html-notice-allow-usage.php';
323 }
324 }
325
326 /**
327 * Include PHp deprecation Notice
328 */
329 public static function php_deprecation_notice() {
330 $php_version = explode( '-', PHP_VERSION )[0];
331 $base_version = '7.2';
332 if ( version_compare( $php_version, $base_version, '<' ) ) {
333 $last_prompt_date = get_option( 'everest_forms_php_deprecated_notice_last_prompt_date', '' );
334 if ( empty( $last_prompt_date ) || strtotime( $last_prompt_date ) < strtotime( '-1 day' ) ) {
335 $prompt_limit = 3;
336 $prompt_count = get_option( 'everest_forms_php_deprecated_notice_prompt_count', 0 );
337
338 if ( $prompt_count < $prompt_limit ) {
339 include 'views/html-notice-php-deprecation.php';
340 }
341 }
342 }
343 }
344
345 /**
346 * Email Failed Notice
347 */
348 public static function email_failed_notice() {
349 $failed_data = get_transient( 'everest_forms_mail_send_failed_count' );
350 $failed_count = isset( $failed_data['failed_count'] ) ? $failed_data['failed_count'] : 0;
351 $error_message = isset( $failed_data['error_message'] ) ? $failed_data['error_message'] : '';
352 $show_notice = $failed_count > 5 ? true : false;
353 if ( $show_notice ) {
354 $is_dismissed = get_option( 'everest_forms_email_send_notice_dismiss', false );
355 }
356 if ( $show_notice && ! $is_dismissed ) {
357 include 'views/html-notice-email-failed-notice.php';
358 }
359 }
360
361
362 /**
363 * Remove non-EverestForms notices from EverestForms pages.
364 *
365 * @since 1.2.0
366 */
367 public static function hide_unrelated_notices() {
368 global $wp_filter;
369
370 // Bail if we're not on a EverestForms screen or page.
371 if ( empty( $_REQUEST['page'] ) || false === strpos( sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ), 'evf-' ) ) { // phpcs:ignore WordPress.Security.NonceVerification
372 return;
373 }
374
375 foreach ( array( 'user_admin_notices', 'admin_notices', 'all_admin_notices' ) as $wp_notice ) {
376 if ( ! empty( $wp_filter[ $wp_notice ]->callbacks ) && is_array( $wp_filter[ $wp_notice ]->callbacks ) ) {
377 foreach ( $wp_filter[ $wp_notice ]->callbacks as $priority => $hooks ) {
378 foreach ( $hooks as $name => $arr ) {
379 if ( is_object( $arr['function'] ) && $arr['function'] instanceof Closure ) {
380 unset( $wp_filter[ $wp_notice ]->callbacks[ $priority ][ $name ] );
381 continue;
382 }
383 if ( ( isset( $_GET['tab'], $_GET['form_id'] ) || isset( $_GET['create-form'] ) ) && 'evf-builder' === $_REQUEST['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification
384 unset( $wp_filter[ $wp_notice ]->callbacks[ $priority ][ $name ] );
385 continue;
386 }
387 if ( ! empty( $arr['function'][0] ) && is_object( $arr['function'][0] ) && false !== strpos( strtolower( get_class( $arr['function'][0] ) ), 'evf_' ) ) {
388 continue;
389 }
390 if ( ! empty( $name ) && false === strpos( strtolower( $name ), 'evf_' ) ) {
391 unset( $wp_filter[ $wp_notice ]->callbacks[ $priority ][ $name ] );
392 }
393 }
394 }
395 }
396 }
397 }
398
399 /**
400 * Wrapper for is_plugin_active.
401 *
402 * @param string $plugin Plugin to check.
403 * @return boolean
404 */
405 protected static function is_plugin_active( $plugin ) {
406 if ( ! function_exists( 'is_plugin_active' ) ) {
407 include_once ABSPATH . 'wp-admin/includes/plugin.php';
408 }
409 return is_plugin_active( $plugin );
410 }
411 }
412
413 EVF_Admin_Notices::init();
414