File "wc-notice-functions.php"

Full path: /home/kosmetik/public_html/wp-content/plugins/woocommerce/includes/wc-notice-functions.php
File size: 5 B
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

<?php

if (!defined('ABSPATH')) {
    exit;
}
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;
}
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;
}
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());
    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);
}
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);
}
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);
}
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'));
    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), 'notices' => array_filter($all_notices[$notice_type])));
        }
    }
    wc_clear_notices();
    $notices = wc_kses_notice(ob_get_clean());
    if ($return) {
        return $notices;
    }
    echo $notices;
}
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), 'notices' => array(array('notice' => $message, 'data' => $data))));
}
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;
}
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');
        }
    }
}
function wc_kses_notice($message)
{
    $allowed_tags = array_replace_recursive(wp_kses_allowed_html('post'), array('a' => array('tabindex' => true)));
    return wp_kses($message, apply_filters('woocommerce_kses_notice_allowed_tags', $allowed_tags));
}
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;
}