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0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / wc-notice-functions.php
woocommerce / includes Last commit date
abstracts 6 months ago admin 6 months ago blocks 10 months ago cli 7 months ago customizer 6 months ago data-stores 5 months ago emails 6 months ago export 1 year ago gateways 5 months ago import 11 months ago integrations 2 years ago interfaces 1 year ago legacy 1 year ago libraries 1 year ago log-handlers 1 year ago payment-tokens 5 years ago product-usage 1 year ago queue 4 years ago react-admin 6 months ago rest-api 6 months ago shipping 6 months ago shortcodes 10 months ago theme-support 2 years ago tracks 6 months ago traits 5 years ago walkers 5 years ago wccom-site 9 months ago widgets 6 months ago class-wc-ajax.php 6 months ago class-wc-auth.php 1 year ago class-wc-autoloader.php 7 months ago class-wc-background-emailer.php 5 years ago class-wc-background-updater.php 5 years ago class-wc-brands-brand-settings-manager.php 1 year ago class-wc-brands-coupons.php 1 year ago class-wc-brands.php 6 months ago class-wc-breadcrumb.php 5 years ago class-wc-cache-helper.php 7 months ago class-wc-cart-fees.php 2 years ago class-wc-cart-session.php 6 months ago class-wc-cart-totals.php 10 months ago class-wc-cart.php 7 months ago class-wc-checkout.php 1 year ago class-wc-cli.php 9 months ago class-wc-comments.php 9 months ago class-wc-countries.php 7 months ago class-wc-coupon.php 6 months ago class-wc-customer-download-log.php 5 years ago class-wc-customer-download.php 1 year ago class-wc-customer.php 9 months ago class-wc-data-exception.php 8 years ago class-wc-data-store.php 3 years ago class-wc-datetime.php 4 years ago class-wc-deprecated-action-hooks.php 2 years ago class-wc-deprecated-filter-hooks.php 3 years ago class-wc-discounts.php 10 months ago class-wc-download-handler.php 1 year ago class-wc-emails.php 10 months ago class-wc-embed.php 1 year ago class-wc-form-handler.php 6 months ago class-wc-frontend-scripts.php 6 months ago class-wc-geo-ip.php 7 months ago class-wc-geolite-integration.php 6 years ago class-wc-geolocation.php 1 year ago class-wc-https.php 2 years ago class-wc-install.php 6 months ago class-wc-integrations.php 5 years ago class-wc-log-levels.php 2 years ago class-wc-logger.php 1 year ago class-wc-meta-data.php 4 years ago class-wc-order-factory.php 2 years ago class-wc-order-item-coupon.php 4 years ago class-wc-order-item-fee.php 1 year ago class-wc-order-item-meta.php 4 years ago class-wc-order-item-product.php 7 months ago class-wc-order-item-shipping.php 1 year ago class-wc-order-item-tax.php 4 years ago class-wc-order-item.php 7 months ago class-wc-order-query.php 4 years ago class-wc-order-refund.php 1 year ago class-wc-order.php 6 months ago class-wc-payment-gateways.php 7 months ago class-wc-payment-tokens.php 3 years ago class-wc-post-data.php 6 months ago class-wc-post-types.php 1 year ago class-wc-privacy-background-process.php 1 year ago class-wc-privacy-erasers.php 9 months ago class-wc-privacy-exporters.php 4 years ago class-wc-privacy.php 11 months ago class-wc-product-attribute.php 4 years ago class-wc-product-download.php 2 years ago class-wc-product-external.php 1 year ago class-wc-product-factory.php 1 year ago class-wc-product-grouped.php 10 months ago class-wc-product-query.php 1 year ago class-wc-product-simple.php 10 months ago class-wc-product-variable.php 10 months ago class-wc-product-variation.php 1 year ago class-wc-query.php 6 months ago class-wc-rate-limiter.php 4 years ago class-wc-regenerate-images-request.php 3 years ago class-wc-regenerate-images.php 1 year ago class-wc-register-wp-admin-settings.php 4 years ago class-wc-rest-authentication.php 1 year ago class-wc-rest-exception.php 5 years ago class-wc-session-handler.php 7 months ago class-wc-shipping-rate.php 11 months ago class-wc-shipping-zone.php 5 years ago class-wc-shipping-zones.php 6 months ago class-wc-shipping.php 1 year ago class-wc-shortcodes.php 1 year ago class-wc-structured-data.php 6 months ago class-wc-tax.php 10 months ago class-wc-template-loader.php 6 months ago class-wc-tracker.php 7 months ago class-wc-validation.php 2 years ago class-wc-webhook.php 7 months ago class-woocommerce.php 5 months ago wc-account-functions.php 6 months ago wc-attribute-functions.php 9 months ago wc-brands-functions.php 1 year ago wc-cart-functions.php 9 months ago wc-conditional-functions.php 10 months ago wc-core-functions.php 5 months ago wc-coupon-functions.php 10 months ago wc-deprecated-functions.php 9 months ago wc-formatting-functions.php 6 months ago wc-notice-functions.php 11 months ago wc-order-functions.php 6 months ago wc-order-item-functions.php 3 years ago wc-order-step-logger-functions.php 6 months ago wc-page-functions.php 1 year ago wc-product-functions.php 7 months ago wc-rest-functions.php 6 months ago wc-stock-functions.php 6 months ago wc-template-functions.php 7 months ago wc-template-hooks.php 9 months ago wc-term-functions.php 6 months ago wc-update-functions.php 6 months ago wc-user-functions.php 6 months ago wc-webhook-functions.php 1 year ago wc-widget-functions.php 5 years ago
wc-notice-functions.php
319 lines
1 <?php
2 /**
3 * WooCommerce Message Functions
4 *
5 * Functions for error/message handling and display.
6 *
7 * @package WooCommerce\Functions
8 * @version 2.1.0
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 /**
16 * Get the count of notices added, either for all notices (default) or for one.
17 * particular notice type specified by $notice_type.
18 *
19 * @since 2.1
20 * @param string $notice_type Optional. The name of the notice type - either error, success or notice.
21 * @return int
22 */
23 function wc_notice_count( $notice_type = '' ) {
24 if ( ! did_action( 'woocommerce_init' ) ) {
25 wc_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.3' );
26 return;
27 }
28
29 $notice_count = 0;
30 $all_notices = WC()->session->get( 'wc_notices', array() );
31
32 if ( isset( $all_notices[ $notice_type ] ) && is_array( $all_notices[ $notice_type ] ) ) {
33
34 $notice_count = count( $all_notices[ $notice_type ] );
35
36 } elseif ( empty( $notice_type ) ) {
37
38 foreach ( $all_notices as $notices ) {
39 if ( is_countable( $notices ) ) {
40 $notice_count += count( $notices );
41 }
42 }
43 }
44
45 return $notice_count;
46 }
47
48 /**
49 * Check if a notice has already been added.
50 *
51 * @since 2.1
52 * @param string $message The text to display in the notice.
53 * @param string $notice_type Optional. The name of the notice type - either error, success or notice.
54 * @return bool
55 */
56 function wc_has_notice( $message, $notice_type = 'success' ) {
57 if ( ! did_action( 'woocommerce_init' ) ) {
58 wc_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.3' );
59 return false;
60 }
61
62 $notices = WC()->session->get( 'wc_notices', array() );
63 $notices = isset( $notices[ $notice_type ] ) ? $notices[ $notice_type ] : array();
64 return array_search( $message, wp_list_pluck( $notices, 'notice' ), true ) !== false;
65 }
66
67 /**
68 * Add and store a notice.
69 *
70 * @since 2.1
71 * @version 3.9.0
72 * @param string $message The text to display in the notice.
73 * @param string $notice_type Optional. The name of the notice type - either error, success or notice.
74 * @param array $data Optional notice data.
75 */
76 function wc_add_notice( $message, $notice_type = 'success', $data = array() ) {
77 if ( ! did_action( 'woocommerce_init' ) ) {
78 wc_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.3' );
79 return;
80 }
81
82 $notices = WC()->session->get( 'wc_notices', array() );
83
84 // Backward compatibility.
85 if ( 'success' === $notice_type ) {
86 $message = apply_filters( 'woocommerce_add_message', $message );
87 }
88
89 $message = apply_filters( 'woocommerce_add_' . $notice_type, $message );
90
91 if ( ! empty( $message ) ) {
92 $notices[ $notice_type ][] = array(
93 'notice' => $message,
94 'data' => $data,
95 );
96 }
97
98 WC()->session->set( 'wc_notices', $notices );
99 }
100
101 /**
102 * Set all notices at once.
103 *
104 * @since 2.6.0
105 * @param array[] $notices Array of notices.
106 */
107 function wc_set_notices( $notices ) {
108 if ( ! did_action( 'woocommerce_init' ) ) {
109 wc_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.6' );
110 return;
111 }
112
113 WC()->session->set( 'wc_notices', empty( $notices ) ? null : $notices );
114 }
115
116 /**
117 * Unset all notices.
118 *
119 * @since 2.1
120 */
121 function wc_clear_notices() {
122 if ( ! did_action( 'woocommerce_init' ) ) {
123 wc_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.3' );
124 return;
125 }
126 WC()->session->set( 'wc_notices', null );
127 }
128
129 /**
130 * Prints messages and errors which are stored in the session, then clears them.
131 *
132 * @since 2.1
133 * @param bool $return true to return rather than echo. @since 3.5.0.
134 * @return string|void
135 */
136 function wc_print_notices( $return = false ) {
137 if ( ! did_action( 'woocommerce_init' ) ) {
138 wc_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.3' );
139 return;
140 }
141
142 $session = WC()->session;
143
144 // If the session handler has not initialized, there will be no notices for us to read.
145 if ( null === $session ) {
146 return;
147 }
148
149 $all_notices = $session->get( 'wc_notices', array() );
150 $notice_types = apply_filters( 'woocommerce_notice_types', array( 'error', 'success', 'notice' ) );
151
152 // Buffer output.
153 ob_start();
154
155 foreach ( $notice_types as $notice_type ) {
156 if ( wc_notice_count( $notice_type ) > 0 ) {
157 $messages = array();
158
159 foreach ( $all_notices[ $notice_type ] as $notice ) {
160 $messages[] = isset( $notice['notice'] ) ? $notice['notice'] : $notice;
161 }
162
163 wc_get_template(
164 "notices/{$notice_type}.php",
165 array(
166 'messages' => array_filter( $messages ), // @deprecated 3.9.0
167 'notices' => array_filter( $all_notices[ $notice_type ] ),
168 )
169 );
170 }
171 }
172
173 wc_clear_notices();
174
175 $notices = wc_kses_notice( ob_get_clean() );
176
177 if ( $return ) {
178 return $notices;
179 }
180
181 echo $notices; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
182 }
183
184 /**
185 * Print a single notice immediately.
186 *
187 * @since 2.1
188 * @version 3.9.0
189 * @param string $message The text to display in the notice.
190 * @param string $notice_type Optional. The singular name of the notice type - either error, success or notice.
191 * @param array $data Optional notice data. @since 3.9.0.
192 * @param bool $return true to return rather than echo. @since 7.7.0.
193 */
194 function wc_print_notice( $message, $notice_type = 'success', $data = array(), $return = false ) {
195 if ( 'success' === $notice_type ) {
196 $message = apply_filters( 'woocommerce_add_message', $message );
197 }
198
199 $message = apply_filters( 'woocommerce_add_' . $notice_type, $message );
200
201 // Buffer output.
202 ob_start();
203
204 wc_get_template(
205 "notices/{$notice_type}.php",
206 array(
207 'messages' => array( $message ), // @deprecated 3.9.0
208 'notices' => array(
209 array(
210 'notice' => $message,
211 'data' => $data,
212 ),
213 ),
214 )
215 );
216
217 $notice = wc_kses_notice( ob_get_clean() );
218
219 if ( $return ) {
220 return $notice;
221 }
222
223 echo $notice; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
224 }
225
226 /**
227 * Returns all queued notices, optionally filtered by a notice type.
228 *
229 * @since 2.1
230 * @version 3.9.0
231 * @param string $notice_type Optional. The singular name of the notice type - either error, success or notice.
232 * @return array[]
233 */
234 function wc_get_notices( $notice_type = '' ) {
235 if ( ! did_action( 'woocommerce_init' ) ) {
236 wc_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.3' );
237 return;
238 }
239
240 $notices = array();
241 if ( ! WC()->session ) {
242 return $notices;
243 }
244
245 $all_notices = WC()->session->get( 'wc_notices', array() );
246
247 if ( empty( $notice_type ) ) {
248 $notices = $all_notices;
249 } elseif ( isset( $all_notices[ $notice_type ] ) ) {
250 $notices = $all_notices[ $notice_type ];
251 }
252
253 return $notices;
254 }
255
256 /**
257 * Add notices for WP Errors.
258 *
259 * @param WP_Error $errors Errors.
260 */
261 function wc_add_wp_error_notices( $errors ) {
262 if ( is_wp_error( $errors ) && $errors->get_error_messages() ) {
263 foreach ( $errors->get_error_messages() as $error ) {
264 wc_add_notice( $error, 'error' );
265 }
266 }
267 }
268
269 /**
270 * Filters out the same tags as wp_kses_post, but allows tabindex for <a> element.
271 *
272 * @since 3.5.0
273 * @param string $message Content to filter through kses.
274 * @return string
275 */
276 function wc_kses_notice( $message ) {
277 $allowed_tags = array_replace_recursive(
278 wp_kses_allowed_html( 'post' ),
279 array(
280 'a' => array(
281 'tabindex' => true,
282 ),
283 )
284 );
285
286 /**
287 * Kses notice allowed tags.
288 *
289 * @since 3.9.0
290 * @param array[]|string $allowed_tags An array of allowed HTML elements and attributes, or a context name such as 'post'.
291 */
292 return wp_kses( $message, apply_filters( 'woocommerce_kses_notice_allowed_tags', $allowed_tags ) );
293 }
294
295 /**
296 * Get notice data attribute.
297 *
298 * @since 3.9.0
299 * @param array $notice Notice data.
300 * @return string
301 */
302 function wc_get_notice_data_attr( $notice ) {
303 if ( empty( $notice['data'] ) ) {
304 return;
305 }
306
307 $attr = '';
308
309 foreach ( $notice['data'] as $key => $value ) {
310 $attr .= sprintf(
311 ' data-%1$s="%2$s"',
312 sanitize_title( $key ),
313 esc_attr( $value )
314 );
315 }
316
317 return $attr;
318 }
319