PHP 8.2.31
Preview: wc-notice-functions.php Size: 7.50 KB
/home/nshryvcy/himaltourism.com/wp-content/plugins/woocommerce/includes/wc-notice-functions.php

<?php
/**
 * WooCommerce Message Functions
 *
 * Functions for error/message handling and display.
 *
 * @package WooCommerce\Functions
 * @version 2.1.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Get the count of notices added, either for all notices (default) or for one.
 * particular notice type specified by $notice_type.
 *
 * @since  2.1
 * @param  string $notice_type Optional. The name of the notice type - either error, success or notice.
 * @return int
 */
function wc_notice_count( $notice_type = '' ) {
	if ( ! did_action( 'woocommerce_init' ) ) {
		wc_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.3' );
		return;
	}

	$notice_count = 0;
	$all_notices  = WC()->session->get( 'wc_notices', array() );

	if ( isset( $all_notices[ $notice_type ] ) ) {

		$notice_count = count( $all_notices[ $notice_type ] );

	} elseif ( empty( $notice_type ) ) {

		foreach ( $all_notices as $notices ) {
			$notice_count += count( $notices );
		}
	}

	return $notice_count;
}

/**
 * Check if a notice has already been added.
 *
 * @since  2.1
 * @param  string $message The text to display in the notice.
 * @param  string $notice_type Optional. The name of the notice type - either error, success or notice.
 * @return bool
 */
function wc_has_notice( $message, $notice_type = 'success' ) {
	if ( ! did_action( 'woocommerce_init' ) ) {
		wc_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.3' );
		return false;
	}

	$notices = WC()->session->get( 'wc_notices', array() );
	$notices = isset( $notices[ $notice_type ] ) ? $notices[ $notice_type ] : array();
	return array_search( $message, wp_list_pluck( $notices, 'notice' ), true ) !== false;
}

/**
 * Add and store a notice.
 *
 * @since 2.1
 * @version 3.9.0
 * @param string $message     The text to display in the notice.
 * @param string $notice_type Optional. The name of the notice type - either error, success or notice.
 * @param array  $data        Optional notice data.
 */
function wc_add_notice( $message, $notice_type = 'success', $data = array() ) {
	if ( ! did_action( 'woocommerce_init' ) ) {
		wc_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.3' );
		return;
	}

	$notices = WC()->session->get( 'wc_notices', array() );

	// Backward compatibility.
	if ( 'success' === $notice_type ) {
		$message = apply_filters( 'woocommerce_add_message', $message );
	}

	$message = apply_filters( 'woocommerce_add_' . $notice_type, $message );

	if ( ! empty( $message ) ) {
		$notices[ $notice_type ][] = array(
			'notice' => $message,
			'data'   => $data,
		);
	}

	WC()->session->set( 'wc_notices', $notices );
}

/**
 * Set all notices at once.
 *
 * @since 2.6.0
 * @param array[] $notices Array of notices.
 */
function wc_set_notices( $notices ) {
	if ( ! did_action( 'woocommerce_init' ) ) {
		wc_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.6' );
		return;
	}

	WC()->session->set( 'wc_notices', $notices );
}

/**
 * Unset all notices.
 *
 * @since 2.1
 */
function wc_clear_notices() {
	if ( ! did_action( 'woocommerce_init' ) ) {
		wc_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.3' );
		return;
	}
	WC()->session->set( 'wc_notices', null );
}

/**
 * Prints messages and errors which are stored in the session, then clears them.
 *
 * @since 2.1
 * @param bool $return true to return rather than echo. @since 3.5.0.
 * @return string|null
 */
function wc_print_notices( $return = false ) {
	if ( ! did_action( 'woocommerce_init' ) ) {
		wc_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.3' );
		return;
	}

	$all_notices  = WC()->session->get( 'wc_notices', array() );
	$notice_types = apply_filters( 'woocommerce_notice_types', array( 'error', 'success', 'notice' ) );

	// Buffer output.
	ob_start();

	foreach ( $notice_types as $notice_type ) {
		if ( wc_notice_count( $notice_type ) > 0 ) {
			$messages = array();

			foreach ( $all_notices[ $notice_type ] as $notice ) {
				$messages[] = isset( $notice['notice'] ) ? $notice['notice'] : $notice;
			}

			wc_get_template(
				"notices/{$notice_type}.php",
				array(
					'messages' => array_filter( $messages ), // @deprecated 3.9.0
					'notices'  => array_filter( $all_notices[ $notice_type ] ),
				)
			);
		}
	}

	wc_clear_notices();

	$notices = wc_kses_notice( ob_get_clean() );

	if ( $return ) {
		return $notices;
	}

	echo $notices; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}

/**
 * Print a single notice immediately.
 *
 * @since 2.1
 * @version 3.9.0
 * @param string $message The text to display in the notice.
 * @param string $notice_type Optional. The singular name of the notice type - either error, success or notice.
 * @param array  $data        Optional notice data. @since 3.9.0.
 */
function wc_print_notice( $message, $notice_type = 'success', $data = array() ) {
	if ( 'success' === $notice_type ) {
		$message = apply_filters( 'woocommerce_add_message', $message );
	}

	$message = apply_filters( 'woocommerce_add_' . $notice_type, $message );

	wc_get_template(
		"notices/{$notice_type}.php",
		array(
			'messages' => array( $message ), // @deprecated 3.9.0
			'notices'  => array(
				array(
					'notice' => $message,
					'data'   => $data,
				),
			),
		)
	);
}

/**
 * Returns all queued notices, optionally filtered by a notice type.
 *
 * @since  2.1
 * @version 3.9.0
 * @param  string $notice_type Optional. The singular name of the notice type - either error, success or notice.
 * @return array[]
 */
function wc_get_notices( $notice_type = '' ) {
	if ( ! did_action( 'woocommerce_init' ) ) {
		wc_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.3' );
		return;
	}

	$all_notices = WC()->session->get( 'wc_notices', array() );

	if ( empty( $notice_type ) ) {
		$notices = $all_notices;
	} elseif ( isset( $all_notices[ $notice_type ] ) ) {
		$notices = $all_notices[ $notice_type ];
	} else {
		$notices = array();
	}

	return $notices;
}

/**
 * Add notices for WP Errors.
 *
 * @param WP_Error $errors Errors.
 */
function wc_add_wp_error_notices( $errors ) {
	if ( is_wp_error( $errors ) && $errors->get_error_messages() ) {
		foreach ( $errors->get_error_messages() as $error ) {
			wc_add_notice( $error, 'error' );
		}
	}
}

/**
 * Filters out the same tags as wp_kses_post, but allows tabindex for <a> element.
 *
 * @since 3.5.0
 * @param string $message Content to filter through kses.
 * @return string
 */
function wc_kses_notice( $message ) {
	$allowed_tags = array_replace_recursive(
		wp_kses_allowed_html( 'post' ),
		array(
			'a' => array(
				'tabindex' => true,
			),
		)
	);

	/**
	 * Kses notice allowed tags.
	 *
	 * @since 3.9.0
	 * @param array[]|string $allowed_tags An array of allowed HTML elements and attributes, or a context name such as 'post'.
	 */
	return wp_kses( $message, apply_filters( 'woocommerce_kses_notice_allowed_tags', $allowed_tags ) );
}

/**
 * Get notice data attribute.
 *
 * @since 3.9.0
 * @param array $notice Notice data.
 * @return string
 */
function wc_get_notice_data_attr( $notice ) {
	if ( empty( $notice['data'] ) ) {
		return;
	}

	$attr = '';

	foreach ( $notice['data'] as $key => $value ) {
		$attr .= sprintf(
			' data-%1$s="%2$s"',
			sanitize_title( $key ),
			esc_attr( $value )
		);
	}

	return $attr;
}

Directory Contents

Dirs: 27 × Files: 110

Name Size Perms Modified Actions
abstracts DIR
- drwxr-xr-x 2026-03-03 06:10:17
Edit Download
admin DIR
- drwxr-xr-x 2026-03-03 06:10:17
Edit Download
blocks DIR
- drwxr-xr-x 2026-03-03 06:10:17
Edit Download
cli DIR
- drwxr-xr-x 2026-03-03 06:10:17
Edit Download
- drwxr-xr-x 2026-03-03 06:10:17
Edit Download
- drwxr-xr-x 2026-03-03 06:10:17
Edit Download
emails DIR
- drwxr-xr-x 2026-03-03 06:10:17
Edit Download
export DIR
- drwxr-xr-x 2026-03-03 06:10:17
Edit Download
gateways DIR
- drwxr-xr-x 2026-03-03 06:10:17
Edit Download
import DIR
- drwxr-xr-x 2026-03-03 06:10:17
Edit Download
- drwxr-xr-x 2026-03-03 06:10:16
Edit Download
- drwxr-xr-x 2026-03-03 06:10:17
Edit Download
legacy DIR
- drwxr-xr-x 2026-03-03 06:10:17
Edit Download
libraries DIR
- drwxr-xr-x 2026-03-03 06:10:17
Edit Download
- drwxr-xr-x 2026-03-03 06:10:17
Edit Download
- drwxr-xr-x 2026-03-03 06:10:17
Edit Download
queue DIR
- drwxr-xr-x 2026-03-03 06:10:17
Edit Download
- drwxr-xr-x 2026-03-03 06:10:17
Edit Download
rest-api DIR
- drwxr-xr-x 2026-03-03 06:10:17
Edit Download
shipping DIR
- drwxr-xr-x 2026-03-03 06:10:16
Edit Download
- drwxr-xr-x 2026-03-03 06:10:17
Edit Download
- drwxr-xr-x 2026-03-03 06:10:18
Edit Download
tracks DIR
- drwxr-xr-x 2026-03-03 06:10:18
Edit Download
traits DIR
- drwxr-xr-x 2026-03-03 06:10:18
Edit Download
walkers DIR
- drwxr-xr-x 2026-03-03 06:10:18
Edit Download
- drwxr-xr-x 2026-03-03 06:10:18
Edit Download
widgets DIR
- drwxr-xr-x 2026-03-03 06:10:18
Edit Download
101.43 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
4.99 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
12.58 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
2.74 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
4.58 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
3.45 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
9.49 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
11.82 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
3.41 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
16.07 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
28.15 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
65.32 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
46.40 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
1.70 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
15.86 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
46.91 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
33.90 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
3.37 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
10.45 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
28.91 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
1.29 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
6.59 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
2.26 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
6.88 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
7.34 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
32.84 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
25.47 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
22.46 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
4.18 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
44.02 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
26.49 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
30.41 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
1.99 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
10.44 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
4.33 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
75.56 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
1.28 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
2.54 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
8.77 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
2.21 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
7.17 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
4.08 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
8.76 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
5.80 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
13.14 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
7.78 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
6.49 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
11.28 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
2.55 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
5.59 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
67.13 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
5.42 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
6.24 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
20.39 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
28.19 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
1.67 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
13.61 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
14.69 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
15.52 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
6.97 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
12.08 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
4.84 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
3.58 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
5.22 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
2.18 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
1.89 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
21.51 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
16.87 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
32.60 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
4.00 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
7.74 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
15.19 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
5.05 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
19.52 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
276 B lrw-r--r-- 2026-03-03 06:10:17
Edit Download
13.78 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
5.51 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
13.08 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
4.01 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
11.57 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
17.23 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
17.32 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
37.00 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
21.42 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
25.88 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
5.74 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
30.01 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
36.00 KB lrw-r--r-- 2026-03-03 06:10:17
Edit Download
12.96 KB lrw-r--r-- 2026-03-03 06:10:18
Edit Download
20.61 KB lrw-r--r-- 2026-03-03 06:10:18
Edit Download
17.36 KB lrw-r--r-- 2026-03-03 06:10:18
Edit Download
13.78 KB lrw-r--r-- 2026-03-03 06:10:18
Edit Download
79.13 KB lrw-r--r-- 2026-03-03 06:10:18
Edit Download
2.68 KB lrw-r--r-- 2026-03-03 06:10:18
Edit Download
32.70 KB lrw-r--r-- 2026-03-03 06:10:18
Edit Download
43.99 KB lrw-r--r-- 2026-03-03 06:10:18
Edit Download
7.50 KB lrw-r--r-- 2026-03-03 06:10:18
Edit Download
35.95 KB lrw-r--r-- 2026-03-03 06:10:18
Edit Download
5.03 KB lrw-r--r-- 2026-03-03 06:10:18
Edit Download
6.92 KB lrw-r--r-- 2026-03-03 06:10:18
Edit Download
48.22 KB lrw-r--r-- 2026-03-03 06:10:18
Edit Download
10.89 KB lrw-r--r-- 2026-03-03 06:10:18
Edit Download
13.22 KB lrw-r--r-- 2026-03-03 06:10:18
Edit Download
117.28 KB lrw-r--r-- 2026-03-03 06:10:18
Edit Download
12.38 KB lrw-r--r-- 2026-03-03 06:10:18
Edit Download
20.66 KB lrw-r--r-- 2026-03-03 06:10:18
Edit Download
76.38 KB lrw-r--r-- 2026-03-03 06:10:18
Edit Download
27.65 KB lrw-r--r-- 2026-03-03 06:10:18
Edit Download
5.60 KB lrw-r--r-- 2026-03-03 06:10:18
Edit Download
2.01 KB lrw-r--r-- 2026-03-03 06:10:18
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).