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 / evf-notice-functions.php
everest-forms / includes Last commit date
abstracts 6 years ago admin 6 years ago export 6 years ago fields 6 years ago interfaces 8 years ago libraries 7 years ago log-handlers 6 years ago shortcodes 6 years ago templates 6 years ago class-everest-forms.php 6 years ago class-evf-ajax.php 6 years ago class-evf-autoloader.php 8 years ago class-evf-background-updater.php 8 years ago class-evf-cache-helper.php 6 years ago class-evf-deprecated-action-hooks.php 6 years ago class-evf-deprecated-filter-hooks.php 7 years ago class-evf-emails.php 6 years ago class-evf-fields.php 6 years ago class-evf-form-block.php 6 years ago class-evf-form-handler.php 6 years ago class-evf-form-task.php 6 years ago class-evf-forms-features.php 6 years ago class-evf-frontend-scripts.php 6 years ago class-evf-install.php 6 years ago class-evf-integrations.php 7 years ago class-evf-log-levels.php 8 years ago class-evf-logger.php 6 years ago class-evf-post-types.php 6 years ago class-evf-privacy.php 6 years ago class-evf-session-handler.php 7 years ago class-evf-shortcodes.php 7 years ago class-evf-smart-tags.php 6 years ago class-evf-template-loader.php 6 years ago class-evf-validation.php 6 years ago evf-conditional-functions.php 6 years ago evf-core-functions.php 6 years ago evf-deprecated-functions.php 6 years ago evf-entry-functions.php 6 years ago evf-formatting-functions.php 6 years ago evf-notice-functions.php 6 years ago evf-template-functions.php 6 years ago evf-template-hooks.php 8 years ago evf-update-functions.php 6 years ago
evf-notice-functions.php
214 lines
1 <?php
2 /**
3 * Everest Forms Message Functions
4 *
5 * Functions for error/message handling and display.
6 *
7 * @package EverestForms/Functions
8 * @version 1.0.0
9 */
10
11 defined( 'ABSPATH' ) || exit;
12
13 /**
14 * Get the count of notices added, either for all notices (default) or for one.
15 * particular notice type specified by $notice_type.
16 *
17 * @since 1.0.0
18 * @param string $notice_type Optional. The name of the notice type - either error, success or notice.
19 * @return int
20 */
21 function evf_notice_count( $notice_type = '' ) {
22 if ( ! did_action( 'everest_forms_init' ) ) {
23 evf_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before everest_forms_init.', 'everest-forms' ), '1.0' );
24 return;
25 }
26
27 $notice_count = 0;
28 $all_notices = evf()->session->get( 'evf_notices', array() );
29
30 if ( isset( $all_notices[ $notice_type ] ) ) {
31
32 $notice_count = count( $all_notices[ $notice_type ] );
33
34 } elseif ( empty( $notice_type ) ) {
35
36 foreach ( $all_notices as $notices ) {
37 $notice_count += count( $notices );
38 }
39 }
40
41 return $notice_count;
42 }
43
44 /**
45 * Check if a notice has already been added.
46 *
47 * @since 1.0.0
48 * @param string $message The text to display in the notice.
49 * @param string $notice_type Optional. The name of the notice type - either error, success or notice.
50 * @return bool
51 */
52 function evf_has_notice( $message, $notice_type = 'success' ) {
53 if ( ! did_action( 'everest_forms_init' ) ) {
54 evf_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before everest_forms_init.', 'everest-forms' ), '1.0' );
55 return false;
56 }
57
58 $notices = evf()->session->get( 'evf_notices', array() );
59 $notices = isset( $notices[ $notice_type ] ) ? $notices[ $notice_type ] : array();
60
61 return array_search( $message, $notices, true ) !== false;
62 }
63
64 /**
65 * Add and store a notice.
66 *
67 * @since 1.0.0
68 * @param string $message The text to display in the notice.
69 * @param string $notice_type Optional. The name of the notice type - either error, success or notice.
70 */
71 function evf_add_notice( $message, $notice_type = 'success' ) {
72 if ( ! did_action( 'everest_forms_init' ) ) {
73 evf_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before everest_forms_init.', 'everest-forms' ), '1.0' );
74 return;
75 }
76
77 $notices = evf()->session->get( 'evf_notices', array() );
78
79 // Backward compatibility.
80 if ( 'success' === $notice_type ) {
81 $message = apply_filters( 'everest_forms_add_message', $message );
82 }
83
84 $notices[ $notice_type ][] = apply_filters( 'everest_forms_add_' . $notice_type, $message );
85
86 evf()->session->set( 'evf_notices', $notices );
87 }
88
89 /**
90 * Set all notices at once.
91 *
92 * @since 1.0.0
93 * @param mixed $notices Array of notices.
94 */
95 function evf_set_notices( $notices ) {
96 if ( ! did_action( 'everest_forms_init' ) ) {
97 evf_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before everest_forms_init.', 'everest-forms' ), '1.0' );
98 return;
99 }
100 evf()->session->set( 'evf_notices', $notices );
101 }
102
103 /**
104 * Unset all notices.
105 *
106 * @since 1.0.0
107 */
108 function evf_clear_notices() {
109 if ( ! did_action( 'everest_forms_init' ) ) {
110 evf_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before everest_forms_init.', 'everest-forms' ), '1.0' );
111 return;
112 }
113 evf()->session->set( 'evf_notices', null );
114 }
115
116 /**
117 * Prints messages and errors which are stored in the session, then clears them.
118 *
119 * @since 1.0.0
120 *
121 * @param array $form_data Prepared form settings.
122 */
123 function evf_print_notices( $form_data = array() ) {
124 if ( ! did_action( 'everest_forms_init' ) ) {
125 evf_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before everest_forms_init.', 'everest-forms' ), '1.0' );
126 return;
127 }
128
129 $form_id = isset( $form_data['id'] ) ? absint( $form_data['id'] ) : 0;
130 $all_notices = evf()->session->get( 'evf_notices', array() );
131 $notice_types = apply_filters( 'everest_forms_notice_types', array( 'error', 'success', 'notice' ) );
132
133 // Skips notice print if it isn't the right form.
134 if ( isset( $_REQUEST['everest_forms']['id'] ) && ( (int) $form_id !== (int) $_REQUEST['everest_forms']['id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
135 return;
136 }
137
138 foreach ( $notice_types as $notice_type ) {
139 if ( evf_notice_count( $notice_type ) > 0 ) {
140 foreach ( $all_notices[ $notice_type ] as $key => $message ) {
141 $all_notices[ $notice_type ][ $key ] = evf_string_translation( $form_id, 'notice_message_' . $notice_type, $message );
142 }
143 evf_get_template(
144 "notices/{$notice_type}.php",
145 array(
146 'messages' => array_filter( $all_notices[ $notice_type ] ),
147 )
148 );
149 }
150 }
151
152 evf_clear_notices();
153 }
154 add_action( 'everest_forms_display_fields_before', 'evf_print_notices', 10 );
155
156 /**
157 * Print a single notice immediately.
158 *
159 * @since 1.0.0
160 * @param string $message The text to display in the notice.
161 * @param string $notice_type Optional. The name of the notice type - either error, success or notice.
162 */
163 function evf_print_notice( $message, $notice_type = 'success' ) {
164 if ( 'success' === $notice_type ) {
165 $message = apply_filters( 'everest_forms_add_message', $message );
166 }
167
168 evf_get_template(
169 "notices/{$notice_type}.php",
170 array(
171 'messages' => array( apply_filters( 'everest_forms_add_' . $notice_type, $message ) ),
172 )
173 );
174 }
175
176 /**
177 * Returns all queued notices, optionally filtered by a notice type.
178 *
179 * @since 1.0.0
180 * @param string $notice_type Optional. The name of the notice type - either error, success or notice.
181 * @return array|mixed
182 */
183 function evf_get_notices( $notice_type = '' ) {
184 if ( ! did_action( 'everest_forms_init' ) ) {
185 evf_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before everest_forms_init.', 'everest-forms' ), '1.0' );
186 return;
187 }
188
189 $all_notices = evf()->session->get( 'evf_notices', array() );
190
191 if ( empty( $notice_type ) ) {
192 $notices = $all_notices;
193 } elseif ( isset( $all_notices[ $notice_type ] ) ) {
194 $notices = $all_notices[ $notice_type ];
195 } else {
196 $notices = array();
197 }
198
199 return $notices;
200 }
201
202 /**
203 * Add notices for WP Errors.
204 *
205 * @param WP_Error $errors Errors.
206 */
207 function evf_add_wp_error_notices( $errors ) {
208 if ( is_wp_error( $errors ) && $errors->get_error_messages() ) {
209 foreach ( $errors->get_error_messages() as $error ) {
210 evf_add_notice( $error, 'error' );
211 }
212 }
213 }
214