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