wc_has_notice function

This commit is contained in:
Mike Jolley 2014-01-07 13:35:01 +00:00
parent 858416605d
commit 85b4ca8c03
2 changed files with 15 additions and 3 deletions

View File

@ -89,8 +89,8 @@ class WC_Query {
* Get any errors from querystring
*/
public function get_errors() {
if ( isset( $_GET['wc_error'] ) )
wc_add_notice( esc_attr( $_GET['wc_error'] ), 'error' );
if ( ! empty( $_GET['wc_error'] ) && ( $error = sanitize_text_field( urldecode( $_GET['wc_error'] ) ) ) && ! wc_has_notice( $error, 'error' ) )
wc_add_notice( $error, 'error' );
}
/**

View File

@ -20,7 +20,6 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
* @return int
*/
function wc_notice_count( $notice_type = '' ) {
$notice_count = 0;
$all_notices = WC()->session->get( 'wc_notices', array() );
@ -39,6 +38,19 @@ function wc_notice_count( $notice_type = '' ) {
return $notice_count;
}
/**
* See if a notice has already been added
*
* @param string $message The text to display in the notice.
* @param string $notice_type The singular name of the notice type - either error, success or notice. [optional]
* @return bool
*/
function wc_has_notice( $message, $notice_type = 'success' ) {
$notices = WC()->session->get( 'wc_notices', array() );
$notices = isset( $notices[ $notice_type ] ) ? $notices[ $notice_type ] : array();
return array_search( $message, $notices ) !== false;
}
/**
* Add and store a notice
*