query->init_query_vars();
WC()->query->add_endpoints();
flush_rewrite_rules();
do_action( 'woocommerce_settings_saved' );
}
/**
* Add a message
* @param string $text
*/
public static function add_message( $text ) {
self::$messages[] = $text;
}
/**
* Add an error
* @param string $text
*/
public static function add_error( $text ) {
self::$errors[] = $text;
}
/**
* Output messages + errors
* @return string
*/
public static function show_messages() {
if ( sizeof( self::$errors ) > 0 ) {
foreach ( self::$errors as $error ) {
echo '
' . esc_html( $error ) . '
';
}
} elseif ( sizeof( self::$messages ) > 0 ) {
foreach ( self::$messages as $message ) {
echo '' . esc_html( $message ) . '
';
}
}
}
/**
* Settings page.
*
* Handles the display of the main woocommerce settings page in admin.
*
* @return void
*/
public static function output() {
global $current_section, $current_tab;
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
do_action( 'woocommerce_settings_start' );
wp_enqueue_script( 'woocommerce_settings', WC()->plugin_url() . '/assets/js/admin/settings' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'iris', 'chosen' ), WC()->version, true );
wp_localize_script( 'woocommerce_settings', 'woocommerce_settings_params', array(
'i18n_nav_warning' => __( 'The changes you made will be lost if you navigate away from this page.', 'woocommerce' )
) );
// Include settings pages
self::get_settings_pages();
// Get current tab/section
$current_tab = empty( $_GET['tab'] ) ? 'general' : sanitize_title( $_GET['tab'] );
$current_section = empty( $_REQUEST['section'] ) ? '' : sanitize_title( $_REQUEST['section'] );
// Save settings if data has been posted
if ( ! empty( $_POST ) ) {
self::save();
}
// Add any posted messages
if ( ! empty( $_GET['wc_error'] ) ) {
self::add_error( stripslashes( $_GET['wc_error'] ) );
}
if ( ! empty( $_GET['wc_message'] ) ) {
self::add_message( stripslashes( $_GET['wc_message'] ) );
}
self::show_messages();
// Get tabs for the settings page
$tabs = apply_filters( 'woocommerce_settings_tabs_array', array() );
include 'views/html-admin-settings.php';
}
/**
* Get a setting from the settings API.
*
* @param mixed $option_name
* @return string
*/
public static function get_option( $option_name, $default = '' ) {
// Array value
if ( strstr( $option_name, '[' ) ) {
parse_str( $option_name, $option_array );
// Option name is first key
$option_name = current( array_keys( $option_array ) );
// Get value
$option_values = get_option( $option_name, '' );
$key = key( $option_array[ $option_name ] );
if ( isset( $option_values[ $key ] ) ) {
$option_value = $option_values[ $key ];
} else {
$option_value = null;
}
// Single value
} else {
$option_value = get_option( $option_name, null );
}
if ( is_array( $option_value ) ) {
$option_value = array_map( 'stripslashes', $option_value );
} elseif ( ! is_null( $option_value ) ) {
$option_value = stripslashes( $option_value );
}
return $option_value === null ? $default : $option_value;
}
/**
* Output admin fields.
*
* Loops though the woocommerce options array and outputs each field.
*
* @param array $options Opens array to output
*/
public static function output_fields( $options ) {
foreach ( $options as $value ) {
if ( ! isset( $value['type'] ) ) {
continue;
}
if ( ! isset( $value['id'] ) ) {
$value['id'] = '';
}
if ( ! isset( $value['title'] ) ) {
$value['title'] = isset( $value['name'] ) ? $value['name'] : '';
}
if ( ! isset( $value['class'] ) ) {
$value['class'] = '';
}
if ( ! isset( $value['css'] ) ) {
$value['css'] = '';
}
if ( ! isset( $value['default'] ) ) {
$value['default'] = '';
}
if ( ! isset( $value['desc'] ) ) {
$value['desc'] = '';
}
if ( ! isset( $value['desc_tip'] ) ) {
$value['desc_tip'] = false;
}
// Custom attribute handling
$custom_attributes = array();
if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
}
}
// Description handling
extract( self::get_field_description( $value ) );
// Switch based on type
switch ( $value['type'] ) {
// Section Titles
case 'title':
if ( ! empty( $value['title'] ) ) {
echo '' . esc_html( $value['title'] ) . '
';
}
if ( ! empty( $value['desc'] ) ) {
echo wpautop( wptexturize( wp_kses_post( $value['desc'] ) ) );
}
echo '';
if ( ! empty( $value['id'] ) ) {
do_action( 'woocommerce_settings_' . sanitize_title( $value['id'] ) . '_after' );
}
break;
// Standard text inputs and subtypes like 'number'
case 'text':
case 'email':
case 'number':
case 'color' :
case 'password' :
$type = $value['type'];
$class = '';
$option_value = self::get_option( $value['id'], $value['default'] );
if ( $value['type'] == 'color' ) {
$type = 'text';
$value['class'] .= 'colorpick';
$description .= '';
}
?>
|
/>
|
|
|
|
|
|
|
|
|
" . __( 'The settings of this image size have been disabled because its values are being overwritten by a filter.', 'woocommerce' ) . "";
}
?>
|
id="-width" type="text" size="3" value="" /> × id="-height" type="text" size="3" value="" />px
|
$value['id'],
'id' => $value['id'],
'sort_column' => 'menu_order',
'sort_order' => 'ASC',
'show_option_none' => ' ',
'class' => $value['class'],
'echo' => false,
'selected' => absint( self::get_option( $value['id'] ) )
);
if ( isset( $value['args'] ) ) {
$args = wp_parse_args( $value['args'], $args );
}
?>
|
|
countries->countries;
if ( strstr( $country_setting, ':' ) ) {
$country_setting = explode( ':', $country_setting );
$country = current( $country_setting );
$state = end( $country_setting );
} else {
$country = $country_setting;
$state = '*';
}
?>
|
|
countries->countries;
}
asort( $countries );
?>
|
|
' . wp_kses_post( $description ) . '';
} elseif ( $description && in_array( $value['type'], array( 'checkbox' ) ) ) {
$description = wp_kses_post( $description );
} elseif ( $description ) {
$description = '' . wp_kses_post( $description ) . '';
}
if ( $tooltip_html && in_array( $value['type'], array( 'checkbox' ) ) ) {
$tooltip_html = '' . $tooltip_html . '
';
} elseif ( $tooltip_html ) {
$tooltip_html = '';
}
return array(
'description' => $description,
'tooltip_html' => $tooltip_html
);
}
/**
* Save admin fields.
*
* Loops though the woocommerce options array and outputs each field.
*
* @param array $options Opens array to output
* @return bool
*/
public static function save_fields( $options ) {
if ( empty( $_POST ) ) {
return false;
}
// Options to update will be stored here
$update_options = array();
// Loop options and get values to save
foreach ( $options as $value ) {
if ( ! isset( $value['id'] ) || ! isset( $value['type'] ) ) {
continue;
}
// Get posted value
if ( strstr( $value['id'], '[' ) ) {
parse_str( $value['id'], $option_name_array );
$option_name = current( array_keys( $option_name_array ) );
$setting_name = key( $option_name_array[ $option_name ] );
$option_value = isset( $_POST[ $option_name ][ $setting_name ] ) ? stripslashes_deep( $_POST[ $option_name ][ $setting_name ] ) : null;
} else {
$option_name = $value['id'];
$setting_name = '';
$option_value = isset( $_POST[ $value['id'] ] ) ? stripslashes_deep( $_POST[ $value['id'] ] ) : null;
}
// Format value
switch ( sanitize_title( $value['type'] ) ) {
case 'checkbox' :
$option_value = is_null( $option_value ) ? 'no' : 'yes';
break;
case 'textarea' :
$option_value = wp_kses_post( trim( $option_value ) );
break;
case 'text' :
case 'email':
case 'number':
case 'select' :
case 'color' :
case 'password' :
case 'single_select_page' :
case 'single_select_country' :
case 'radio' :
if ( in_array( $value['id'], array( 'woocommerce_price_thousand_sep', 'woocommerce_price_decimal_sep' ) ) ) {
$option_value = wp_kses_post( $option_value );
} elseif ( 'woocommerce_price_num_decimals' == $value['id'] ) {
$option_value = is_null( $option_value ) ? 2 : absint( $option_value );
} elseif ( 'woocommerce_hold_stock_minutes' == $value['id'] ) {
$option_value = ! empty( $option_value ) ? absint( $option_value ) : ''; // Allow > 0 or set to ''
wp_clear_scheduled_hook( 'woocommerce_cancel_unpaid_orders' );
if ( '' !== $option_value ) {
wp_schedule_single_event( time() + ( absint( $option_value ) * 60 ), 'woocommerce_cancel_unpaid_orders' );
}
} else {
$option_value = wc_clean( $option_value );
}
break;
case 'multiselect' :
case 'multi_select_countries' :
$option_value = array_filter( array_map( 'wc_clean', (array) $option_value ) );
break;
case 'image_width' :
if ( isset( $option_value['width'] ) ) {
$update_options[ $value['id'] ]['width'] = wc_clean( $option_value['width'] );
$update_options[ $value['id'] ]['height'] = wc_clean( $option_value['height'] );
$update_options[ $value['id'] ]['crop'] = isset( $option_value['crop'] ) ? 1 : 0;
} else {
$update_options[ $value['id'] ]['width'] = $value['default']['width'];
$update_options[ $value['id'] ]['height'] = $value['default']['height'];
$update_options[ $value['id'] ]['crop'] = $value['default']['crop'];
}
break;
default :
do_action( 'woocommerce_update_option_' . sanitize_title( $value['type'] ), $value );
break;
}
if ( ! is_null( $option_value ) ) {
// Check if option is an array
if ( $option_name && $setting_name ) {
// Get old option value
if ( ! isset( $update_options[ $option_name ] ) ) {
$update_options[ $option_name ] = get_option( $option_name, array() );
}
if ( ! is_array( $update_options[ $option_name ] ) ) {
$update_options[ $option_name ] = array();
}
$update_options[ $option_name ][ $setting_name ] = $option_value;
// Single value
} else {
$update_options[ $option_name ] = $option_value;
}
}
// Custom handling
do_action( 'woocommerce_update_option', $value );
}
// Now save the options
foreach ( $update_options as $name => $value ) {
update_option( $name, $value );
}
return true;
}
/**
* Checks which method we're using to serve downloads
*
* If using force or x-sendfile, this ensures the .htaccess is in place
*
* @return void
*/
public static function check_download_folder_protection() {
$upload_dir = wp_upload_dir();
$downloads_url = $upload_dir['basedir'] . '/woocommerce_uploads';
$download_method = get_option('woocommerce_file_download_method');
if ( 'redirect' == $download_method ) {
// Redirect method - don't protect
if ( file_exists( $downloads_url . '/.htaccess' ) ) {
unlink( $downloads_url . '/.htaccess' );
}
} else {
// Force method - protect, add rules to the htaccess file
if ( ! file_exists( $downloads_url . '/.htaccess' ) ) {
if ( $file_handle = @fopen( $downloads_url . '/.htaccess', 'w' ) ) {
fwrite( $file_handle, 'deny from all' );
fclose( $file_handle );
}
}
}
}
}
endif;