本文整理汇总了PHP中WC_Admin_Settings::add_error方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Admin_Settings::add_error方法的具体用法?PHP WC_Admin_Settings::add_error怎么用?PHP WC_Admin_Settings::add_error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Admin_Settings
的用法示例。
在下文中一共展示了WC_Admin_Settings::add_error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: gf_auth_check
/**
* Check authentication of access credentials
*/
public function gf_auth_check()
{
$auth = $GLOBALS['wc_graphflow']->get_api()->test_auth();
if ($auth) {
$notice_text = "Your Graphflow access keys have been verified!";
WC_Admin_Settings::add_message($notice_text);
} else {
$notice_text = "Your Graphflow access keys failed verification. Please check your Graphflow Account Page to retrieve the correct keys.";
WC_Admin_Settings::add_error($notice_text);
}
}
开发者ID:asafmaoz1234,项目名称:woocommerce-recommendations-by-graphflow,代码行数:14,代码来源:class-wc-settings-graphflow.php
示例2: save_settings
public function save_settings()
{
WC_Admin_Settings::save_fields($this->settings);
$is_api_working = $this->check_api() ? 1 : 0;
update_option(WC_SiftScience_Options::$is_api_setup, $is_api_working);
if ($is_api_working === 1) {
WC_Admin_Settings::add_message('API is correctly configured');
} else {
WC_Admin_Settings::add_error('API settings are broken');
}
}
示例3: save
/**
* Save the Targets settings
*/
public function save()
{
try {
$this->verify_request(WooCommerce_Grow_Helpers::get_field('_wpnonce', $_REQUEST), 'woocommerce-grow-targets');
$is_calculate_growth = null !== WooCommerce_Grow_Helpers::get_field('calculate_growth', $_POST) ? true : false;
// Calculate and Growth settings
if ($is_calculate_growth) {
$initial_revenue_number = WooCommerce_Grow_Helpers::get_field('initial_revenue_number', $_POST);
$initial_orders_number = WooCommerce_Grow_Helpers::get_field('initial_orders_number', $_POST);
$initial_sessions_number = WooCommerce_Grow_Helpers::get_field('initial_sessions_number', $_POST);
$initial_cr_number = WooCommerce_Grow_Helpers::get_field('initial_cr_number', $_POST);
$initial_aov_number = WooCommerce_Grow_Helpers::get_field('initial_aov_number', $_POST);
// Call to GA to get sessions for the last month
$ga = WooCommerce_Grow_Google_Analytics::get_instance();
$month = date('m', strtotime('first day of previous month'));
$year = date('Y');
list($start_date, $end_date) = WooCommerce_Grow_Helpers::get_first_and_last_of_the_month($month, $year);
$initial_sessions = $ga->get_sessions_for_month($month, $year);
$filters = array('date_min' => $start_date, 'date_max' => $end_date);
$reports = WooCommerce_Grow_Helpers::setup_wc_reports($filters);
$initial_revenue = WooCommerce_Grow_Helpers::get_wc_total_sales($reports);
$initial_orders = WooCommerce_Grow_Helpers::get_wc_total_orders($reports);
WooCommerce_Grow_Helpers::add_debug_log('Revenue: ' . $initial_revenue);
WooCommerce_Grow_Helpers::add_debug_log('Orders: ' . $initial_orders);
$initial_cr = WooCommerce_Grow_Helpers::calculate_cr($initial_orders, $initial_sessions);
$initial_aov = WooCommerce_Grow_Helpers::calculate_aov($initial_revenue, $initial_orders);
$growth_rate = WooCommerce_Grow_Helpers::get_field('growth_rate', $_POST);
// Save the initial options
WooCommerce_Grow_Helpers::update_option('initial_revenue_number', $initial_revenue);
WooCommerce_Grow_Helpers::update_option('initial_orders_number', $initial_orders);
WooCommerce_Grow_Helpers::update_option('initial_sessions_number', $initial_sessions);
WooCommerce_Grow_Helpers::update_option('initial_cr_number', $initial_cr);
WooCommerce_Grow_Helpers::update_option('initial_aov_number', $initial_aov);
WooCommerce_Grow_Helpers::update_option('growth_rate', $growth_rate);
$months = WooCommerce_Grow_Helpers::get_twelve_months_ahead();
foreach ($months as $month) {
$target_sessions = WooCommerce_Grow_Helpers::calculate_growth($initial_sessions, $growth_rate);
$target_cr = WooCommerce_Grow_Helpers::calculate_growth($initial_cr, $growth_rate);
$target_aov = WooCommerce_Grow_Helpers::calculate_growth($initial_aov, $growth_rate);
$targets['sessions_percentage'][$month['year']][$month['month']] = ceil($target_sessions);
$targets['cr_percentage'][$month['year']][$month['month']] = $target_cr;
$targets['aov_percentage'][$month['year']][$month['month']] = $target_aov;
$targets['revenue_percentage'][$month['year']][$month['month']] = wc_format_decimal($target_sessions * $target_cr * $target_aov, 2);
$targets['orders_percentage'][$month['year']][$month['month']] = ceil($target_sessions * $target_cr);
}
WooCommerce_Grow_Helpers::update_option('monthly_targets', $targets);
}
} catch (Exception $e) {
WC_Admin_Settings::add_error($e->getMessage());
}
}
示例4: woogle_update_license_key_status
function woogle_update_license_key_status()
{
$result = woogle_activate_license_key();
if ($result == NULL) {
update_option('woogle_license_key_validated', '0');
update_option('woogle_license_key_expires', '0');
WC_Admin_Settings::add_error(__('Your Woogle License Key is invalid!', 'woogle'));
} elseif ($result->license == 'valid' || $result->license == 'expired') {
update_option('woogle_license_key_validated', '1');
update_option('woogle_license_key_expires', $result->expires);
WC_Admin_Settings::add_message(__('Your Woogle License Key is valid!', 'woogle'));
} else {
update_option('woogle_license_key_validated', '0');
update_option('woogle_license_key_expires', '0');
WC_Admin_Settings::add_error(__('Your Woogle License Key is invalid!', 'woogle'));
}
}
示例5: check_pdf_template_version
public function check_pdf_template_version($settings)
{
$templates = array('woocommerce_gzdp_invoice_template_attachment', 'woocommerce_gzdp_invoice_template_attachment_first');
foreach ($templates as $template) {
if ($file = get_option($template)) {
$file = get_attached_file($file);
if (!$file) {
continue;
}
try {
$invoice = new WC_GZDP_Invoice_Preview();
$pdf = new WC_GZDP_PDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->set_invoice($invoice);
$pdf->setTemplate($invoice->get_pdf_template());
$pdf->addPage();
} catch (Exception $e) {
delete_option($template);
WC_Admin_Settings::add_error(_x('Your PDF template seems be converted (version > 1.4) or compressed. Please convert (http://convert.neevia.com/pdfconvert/) your pdf file to version 1.4 or lower before uploading.', 'invoices', 'woocommerce-germanized-pro'));
}
}
}
}
示例6: pages
/**
* Manage activations
*/
public function pages()
{
// Anything you need to do before a page is loaded
do_action('woocommerce_grow_pages_start');
// Get current tab
$current_tab = empty($_GET['tab']) ? 'dashboard' : sanitize_title($_GET['tab']);
$this->add_woocommerce_grow_pages();
// Save settings if data has been posted
if (!empty($_POST)) {
$this->save($current_tab);
}
// Add any posted messages
if (!empty($_GET['wc_grow_error'])) {
WC_Admin_Settings::add_error(stripslashes($_GET['wc_error']));
}
if (!empty($_GET['wc_grow_message'])) {
WC_Admin_Settings::add_message(stripslashes($_GET['wc_message']));
}
WC_Admin_Settings::show_messages();
// Add tabs on the Grow page
$tabs = apply_filters('woocommerce_grow_page_tabs_array', array());
include 'views/html-grow-page.php';
}
示例7: save
/**
* Save settings
*/
public function save()
{
$settings = $this->get_settings();
WC_Admin_Settings::save_fields($settings);
if (isset($_POST['qsot_frontend_css_form_bg'])) {
// Save settings
$colors = array();
foreach (array('form_bg', 'form_border', 'form_action_bg', 'form_helper') as $k) {
$colors[$k] = !empty($_POST['qsot_frontend_css_' . $k]) ? wc_format_hex($_POST['qsot_frontend_css_' . $k]) : '';
}
foreach (array('good_msg', 'bad_msg', 'remove') as $K) {
foreach (array('_bg', '_border', '_text') as $k) {
$colors[$K . $k] = !empty($_POST['qsot_frontend_css_' . $K . $k]) ? wc_format_hex($_POST['qsot_frontend_css_' . $K . $k]) : '';
}
}
foreach (array('past_calendar_item', 'calendar_item') as $K) {
foreach (array('_bg', '_border', '_text', '_text_hover') as $k) {
$colors[$K . $k] = !empty($_POST['qsot_frontend_css_' . $K . $k]) ? wc_format_hex($_POST['qsot_frontend_css_' . $K . $k]) : '';
}
}
// Check the colors.
$valid_colors = true;
foreach ($colors as $color) {
if (!preg_match('/^#[a-f0-9]{6}$/i', $color)) {
$valid_colors = false;
WC_Admin_Settings::add_error(sprintf(__('Error saving the Frontend Styles, %s is not a valid color, please use only valid colors code.', 'opentickets-community-edition'), $color));
break;
}
}
if ($valid_colors) {
$old_colors = get_option('woocommerce_frontend_css_colors');
$options = qsot_options::instance();
$options->{'qsot-event-frontend-colors'} = $colors;
if ($old_colors != $colors) {
QSOT::compile_frontend_styles();
}
}
}
}
示例8: bulk_process_products
/**
* Bulk processing for existing posts
*/
public function bulk_process_products()
{
if (!isset($_POST['woocommerce_sale-category_bulk_process'])) {
return;
}
if (!$this->sale_category && !isset($_POST['woocommerce_sale-category_sale_category'])) {
$this->errors[] = __('Please select your sale category, if you want to bulk process your existing products', 'woocommerce-sale-category');
return;
}
if (isset($_POST['woocommerce_sale-category_sale_category'])) {
$sale_category = intval($_POST['woocommerce_sale-category_sale_category']);
} else {
$sale_category = $this->sale_category;
}
$products = wc_get_product_ids_on_sale();
if (!$products) {
WC_Admin_Settings::add_error(__('No products on sale found', 'woocommerce-sale-category'));
return;
}
foreach ($products as $post_id) {
wp_set_object_terms($post_id, $sale_category, 'product_cat', true);
}
WC_Admin_Settings::add_message(__(count($products) . ' products processed', 'woocommerce-sale-category'));
}
示例9: save
/**
* Save settings
*/
public function save()
{
$settings = $this->get_settings();
$filtered_settings = $image_id_fields = array();
// filter out the image ids types, because WC barfs on itself over them
foreach ($settings as $field) {
if ('qsot-image-ids' == $field['type']) {
$image_id_fields[] = $field;
} else {
$filtered_settings[] = $field;
}
}
// only allow wc to save the 'safe' ones
WC_Admin_Settings::save_fields($filtered_settings);
// handle any image id fields
foreach ($image_id_fields as $field) {
// if the field did not have any values passed, then skip it
if (!isset($_POST[$field['id']])) {
continue;
}
$raw_values = $_POST[$field['id']];
// next sanitize the individual values for the field
$values = array_filter(array_map('absint', $raw_values));
// allow modification of the data
$values = apply_filters('woocommerce_admin_settings_sanitize_option', $values, $field, $raw_values);
$values = apply_filters('woocommerce_admin_settings_sanitize_option_' . $field['id'], $values, $field, $raw_values);
// update the value
update_option($field['id'], $values);
}
if (isset($_POST['qsot_frontend_css_form_bg'])) {
// Save settings
$colors = array();
foreach (array('form_bg', 'form_border', 'form_action_bg', 'form_helper') as $k) {
$colors[$k] = !empty($_POST['qsot_frontend_css_' . $k]) ? wc_format_hex($_POST['qsot_frontend_css_' . $k]) : '';
}
foreach (array('good_msg', 'bad_msg', 'remove') as $K) {
foreach (array('_bg', '_border', '_text') as $k) {
$colors[$K . $k] = !empty($_POST['qsot_frontend_css_' . $K . $k]) ? wc_format_hex($_POST['qsot_frontend_css_' . $K . $k]) : '';
}
}
foreach (array('past_calendar_item', 'calendar_item') as $K) {
foreach (array('_bg', '_border', '_text', '_text_hover') as $k) {
$colors[$K . $k] = !empty($_POST['qsot_frontend_css_' . $K . $k]) ? wc_format_hex($_POST['qsot_frontend_css_' . $K . $k]) : '';
}
}
// Check the colors.
$valid_colors = true;
foreach ($colors as $color) {
if (!preg_match('/^#[a-f0-9]{6}$/i', $color)) {
$valid_colors = false;
WC_Admin_Settings::add_error(sprintf(__('Error saving the Frontend Styles, %s is not a valid color, please use only valid colors code.', 'opentickets-community-edition'), $color));
break;
}
}
if ($valid_colors) {
$old_colors = get_option('woocommerce_frontend_css_colors');
$options = qsot_options::instance();
$options->{'qsot-event-frontend-colors'} = $colors;
if ($old_colors != $colors) {
QSOT::compile_frontend_styles();
}
}
}
}
示例10: validate_active_credentials
/**
* Validate the provided credentials.
*/
protected function validate_active_credentials()
{
$settings = wc_gateway_ppec()->settings->load_settings(true);
$creds = $settings->get_active_api_credentials();
$username = $creds->get_username();
$password = $creds->get_password();
if (!empty($username)) {
if (empty($password)) {
WC_Admin_Settings::add_error(__('Error: You must enter API password.', 'woocommerce-gateway-paypal-express-checkout'));
return false;
}
if (is_a($creds, 'WC_Gateway_PPEC_Client_Credential_Signature') && $creds->get_signature()) {
try {
$payer_id = wc_gateway_ppec()->client->test_api_credentials($creds, $settings->get_environment());
if (!$payer_id) {
WC_Admin_Settings::add_error(sprintf(__('Error: The %s credentials you provided are not valid. Please double-check that you entered them correctly and try again.', 'woocommerce-gateway-paypal-express-checkout'), __($settings->get_environment(), 'woocommerce-gateway-paypal-express-checkout')));
return false;
}
} catch (PayPal_API_Exception $ex) {
WC_Admin_Settings::add_error(sprintf(__('An error occurred while trying to validate your %s API credentials. Unable to verify that your API credentials are correct.', 'woocommerce-gateway-paypal-express-checkout'), __($settings->get_environment(), 'woocommerce-gateway-paypal-express-checkout')));
}
} elseif (is_a($creds, 'WC_Gateway_PPEC_Client_Credential_Certificate') && $creds->get_certificate()) {
$cert = @openssl_x509_read($creds->get_certificate());
if (false === $cert) {
WC_Admin_Settings::add_error(sprintf(__('Error: The %s API certificate is not valid.', 'woocommerce-gateway-paypal-express-checkout'), __($settings->get_environment(), 'woocommerce-gateway-paypal-express-checkout')));
return false;
}
$cert_info = openssl_x509_parse($cert);
$valid_until = $cert_info['validTo_time_t'];
if ($valid_until < time()) {
WC_Admin_Settings::add_error(sprintf(__('Error: The %s API certificate has expired.', 'woocommerce-gateway-paypal-express-checkout'), __($settings->get_environment(), 'woocommerce-gateway-paypal-express-checkout')));
return false;
}
if ($cert_info['subject']['CN'] != $creds->get_username()) {
WC_Admin_Settings::add_error(__('Error: The API username does not match the name in the API certificate. Make sure that you have the correct API certificate.', 'woocommerce-gateway-paypal-express-checkout'));
return false;
}
try {
$payer_id = wc_gateway_ppec()->client->test_api_credentials($creds, $settings->get_environment());
if (!$payer_id) {
WC_Admin_Settings::add_error(sprintf(__('Error: The %s credentials you provided are not valid. Please double-check that you entered them correctly and try again.', 'woocommerce-gateway-paypal-express-checkout'), __($settings->get_environment(), 'woocommerce-gateway-paypal-express-checkout')));
return false;
}
} catch (PayPal_API_Exception $ex) {
WC_Admin_Settings::add_error(sprintf(__('An error occurred while trying to validate your %s API credentials. Unable to verify that your API credentials are correct.', 'woocommerce-gateway-paypal-express-checkout'), __($settings->get_environment(), 'woocommerce-gateway-paypal-express-checkout')));
}
} else {
WC_Admin_Settings::add_error(sprintf(__('Error: You must provide a %s API signature or certificate.', 'woocommerce-gateway-paypal-express-checkout'), __($settings->get_environment(), 'woocommerce-gateway-paypal-express-checkout')));
return false;
}
$settings_array = (array) get_option('woocommerce_ppec_paypal_settings', array());
if ('yes' === $settings_array['require_billing']) {
$is_account_enabled_for_billing_address = false;
try {
$is_account_enabled_for_billing_address = wc_gateway_ppec()->client->test_for_billing_address_enabled($creds, $settings->get_environment());
} catch (PayPal_API_Exception $ex) {
$is_account_enabled_for_billing_address = false;
}
if (!$is_account_enabled_for_billing_address) {
$settings_array['require_billing'] = 'no';
update_option('woocommerce_ppec_paypal_settings', $settings_array);
WC_Admin_Settings::add_error(__('The "require billing address" option is not enabled by your account and has been disabled.', 'woocommerce-gateway-paypal-express-checkout'));
}
}
}
}
示例11: save
/**
* Save settings
*/
public function save()
{
$settings = $this->get_settings();
WC_Admin_Settings::save_fields($settings);
if (isset($_POST['woocommerce_frontend_css_primary'])) {
// Save settings
$primary = !empty($_POST['woocommerce_frontend_css_primary']) ? wc_format_hex($_POST['woocommerce_frontend_css_primary']) : '';
$secondary = !empty($_POST['woocommerce_frontend_css_secondary']) ? wc_format_hex($_POST['woocommerce_frontend_css_secondary']) : '';
$highlight = !empty($_POST['woocommerce_frontend_css_highlight']) ? wc_format_hex($_POST['woocommerce_frontend_css_highlight']) : '';
$content_bg = !empty($_POST['woocommerce_frontend_css_content_bg']) ? wc_format_hex($_POST['woocommerce_frontend_css_content_bg']) : '';
$subtext = !empty($_POST['woocommerce_frontend_css_subtext']) ? wc_format_hex($_POST['woocommerce_frontend_css_subtext']) : '';
$colors = array('primary' => $primary, 'secondary' => $secondary, 'highlight' => $highlight, 'content_bg' => $content_bg, 'subtext' => $subtext);
// Check the colors.
$valid_colors = true;
foreach ($colors as $color) {
if (!preg_match('/^#[a-f0-9]{6}$/i', $color)) {
$valid_colors = false;
WC_Admin_Settings::add_error(sprintf(__('Error saving the Frontend Styles, %s is not a valid color, please use only valid colors code.', 'woocommerce'), $color));
break;
}
}
if ($valid_colors) {
$old_colors = get_option('woocommerce_frontend_css_colors');
update_option('woocommerce_frontend_css_colors', $colors);
if ($old_colors != $colors) {
woocommerce_compile_less_styles();
}
}
}
}
示例12: after_save
public function after_save($settings)
{
if (!empty($_POST['woocommerce_gzd_small_enterprise'])) {
update_option('woocommerce_gzd_shipping_tax', 'no');
update_option('woocommerce_gzd_shipping_tax_force', 'no');
update_option('woocommerce_gzd_fee_tax', 'no');
update_option('woocommerce_gzd_fee_tax_force', 'no');
if (!empty($_POST['woocommerce_gzd_enable_virtual_vat'])) {
update_option('woocommerce_gzd_enable_virtual_vat', 'no');
WC_Admin_Settings::add_error(__('Sorry, but the new Virtual VAT rules cannot be applied to small business.', 'woocommerce-germanized'));
}
}
}
示例13: errorWebhook
public function errorWebhook($e, $force_host_ssl, $url)
{
switch ($e->getErrorCode()) {
case '6001':
$msg = 'El webhook ya existe, omite este mensaje.';
return;
case '6002':
case '6003':
$msg = 'No es posible conectarse con el servicio de webhook, verifica la URL: ' . $url;
if ($force_host_ssl == true) {
$this->createWebhook(true);
}
break;
default:
/* Demás errores 400 */
$msg = 'La petición no pudo ser procesada.';
break;
}
$error = $e->getErrorCode() . '. ' . $msg;
/**
* Para solo mostrar un mensaje de error en backoffice y no 2,
* esto debido a que se vuelve a realizar la petición "createWebhook" con el parámetro "force_host_ssl"
**/
if (!$force_host_ssl) {
return;
}
if (function_exists('wc_add_notice')) {
wc_add_notice($error, 'error');
} else {
$settings = new WC_Admin_Settings();
$settings->add_error($error);
}
}
示例14: save
/**
* Save global settings
*/
public function save()
{
global $current_section;
if ($current_section && $this->section_save()) {
update_option('wc_tfls_timestamp', time());
} else {
if (!empty($_POST['wc_tfls_debug_ip']) && !filter_var($_POST['wc_tfls_debug_ip'], FILTER_VALIDATE_IP)) {
WC_Admin_Settings::add_error(__('Debugging IP must be a valid IP address.', 'woocommerce-tfls'));
} else {
if (isset($_POST['delete_group'])) {
$section_settings = (array) get_option('_oga_tfls_countries_groups');
$metakeys = array();
foreach ($_POST['delete_group'] as $value) {
unset($section_settings[$value]);
$metakeys[] = "'_" . $value . "_price'";
$metakeys[] = "'_" . $value . "_sale_price'";
$metakeys[] = "'_" . $value . "_variable_price'";
$metakeys[] = "'_" . $value . "_variable_sale_price'";
}
update_option('_oga_tfls_countries_groups', $section_settings);
//delete postmeta data
global $wpdb;
$wpdb->query("DELETE FROM " . $wpdb->postmeta . " WHERE meta_key in (" . implode(',', $metakeys) . ")");
}
//Database geoip update
if (!wp_next_scheduled('tfls_update_geoip') && isset($_POST['wc_tfls_update_geoip'])) {
$update_errors = tfls_download_geoipdb();
if ($update_errors) {
WC_Admin_Settings::add_error($update_errors);
unset($_POST['wc_tfls_update_geoip']);
} else {
wp_schedule_event(time() + 2419200, '4weeks', 'tfls_update_geoip');
WC_Admin_Settings::add_message(__('GeoIP info has been updated.', 'woocommerce-tfls'));
}
} elseif (wp_next_scheduled('tfls_update_geoip') && !isset($_POST['wc_tfls_update_geoip'])) {
wp_unschedule_event(wp_next_scheduled('tfls_update_geoip'), 'tfls_update_geoip');
}
//save settings
$settings = $this->get_settings();
WC_Admin_Settings::save_fields($settings);
update_option('wc_tfls_timestamp', time());
}
}
}
开发者ID:voice-brand-agency,项目名称:the-fairy-light-shop-site-plugin,代码行数:47,代码来源:class-wc-settings-tfls.php
示例15: after_save
public function after_save($settings)
{
if (!empty($_POST['woocommerce_gzd_small_enterprise'])) {
update_option('woocommerce_gzd_shipping_tax', 'no');
update_option('woocommerce_gzd_shipping_tax_force', 'no');
update_option('woocommerce_gzd_fee_tax', 'no');
update_option('woocommerce_gzd_fee_tax_force', 'no');
if (!empty($_POST['woocommerce_gzd_enable_virtual_vat'])) {
update_option('woocommerce_gzd_enable_virtual_vat', 'no');
WC_Admin_Settings::add_error(__('Sorry, but the new Virtual VAT rules cannot be applied to small business.', 'woocommerce-germanized'));
}
}
if ('yes' === get_option('woocommerce_gzd_enable_virtual_vat')) {
// Make sure that tax based location is set to billing address
if ('base' === get_option('woocommerce_tax_based_on')) {
update_option('woocommerce_tax_based_on', 'billing');
}
}
}