Skip to content

Commit

Permalink
Notice functions tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrice committed Sep 5, 2014
1 parent 0e4a4ef commit 81b50b6
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions includes/wc-notice-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

/**
* Get the count of notices added, either for all notices (default) or for one particular notice type specified
* by $notice_type.
* Get the count of notices added, either for all notices (default) or for one
* particular notice type specified by $notice_type.
*
* @param string $notice_type The name of the notice type - either error, success or notice. [optional]
* @since 2.1
* @param string $notice_type The name of the notice type - either error, success or notice. [optional]
* @return int
*/
function wc_notice_count( $notice_type = '' ) {
Expand All @@ -39,10 +40,11 @@ function wc_notice_count( $notice_type = '' ) {
}

/**
* See if a notice has already been added
* Check 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]
* @since 2.1
* @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' ) {
Expand All @@ -54,16 +56,18 @@ function wc_has_notice( $message, $notice_type = 'success' ) {
/**
* Add and store a notice
*
* @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]
* @since 2.1
* @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]
*/
function wc_add_notice( $message, $notice_type = 'success' ) {

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

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

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

Expand Down Expand Up @@ -105,13 +109,15 @@ function wc_print_notices() {
/**
* Print a single notice immediately
*
* @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]
* @since 2.1
* @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]
*/
function wc_print_notice( $message, $notice_type = 'success' ) {

if ( 'success' === $notice_type )
if ( 'success' === $notice_type ) {
$message = apply_filters( 'woocommerce_add_message', $message );
}

wc_get_template( "notices/{$notice_type}.php", array(
'messages' => array( apply_filters( 'woocommerce_add_' . $notice_type, $message ) )
Expand All @@ -120,7 +126,9 @@ function wc_print_notice( $message, $notice_type = 'success' ) {

/**
* Returns all queued notices, optionally filtered by a notice type.
* @param string $notice_type The singular name of the notice type - either error, success or notice. [optional]
*
* @since 2.1
* @param string $notice_type The singular name of the notice type - either error, success or notice. [optional]
* @return array|mixed
*/
function wc_get_notices( $notice_type = '' ) {
Expand Down

0 comments on commit 81b50b6

Please sign in to comment.