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