2013-07-26 14:36:28 +00:00
< ? php
/**
2015-11-03 13:53:50 +00:00
* WooCommerce Admin Settings Class
2013-07-26 14:36:28 +00:00
*
2015-05-15 19:12:11 +00:00
* @ author WooThemes
* @ category Admin
* @ package WooCommerce / Admin
2015-11-11 14:18:26 +00:00
* @ version 2.5 . 0
2013-07-26 14:36:28 +00:00
*/
2014-09-12 00:40:30 +00:00
if ( ! defined ( 'ABSPATH' ) ) {
2016-03-04 09:41:31 +00:00
exit ;
2014-09-12 00:40:30 +00:00
}
2013-07-26 14:36:28 +00:00
2017-02-16 11:46:01 +00:00
if ( ! class_exists ( 'WC_Admin_Settings' , false ) ) :
2013-07-26 14:36:28 +00:00
/**
2016-03-04 09:41:31 +00:00
* WC_Admin_Settings Class .
2013-07-26 14:36:28 +00:00
*/
class WC_Admin_Settings {
2016-01-05 15:37:28 +00:00
/**
* Setting pages .
*
* @ var array
*/
2014-01-03 14:13:07 +00:00
private static $settings = array ();
2016-01-05 15:37:28 +00:00
/**
* Error messages .
*
* @ var array
*/
2013-07-26 14:36:28 +00:00
private static $errors = array ();
2016-01-05 15:37:28 +00:00
/**
* Update messages .
*
* @ var array
*/
2013-07-26 14:36:28 +00:00
private static $messages = array ();
/**
2015-11-03 12:28:01 +00:00
* Include the settings page classes .
2013-07-26 14:36:28 +00:00
*/
public static function get_settings_pages () {
2014-01-03 14:13:07 +00:00
if ( empty ( self :: $settings ) ) {
$settings = array ();
2016-07-27 10:58:43 +00:00
include_once ( dirname ( __FILE__ ) . '/settings/class-wc-settings-page.php' );
2014-01-03 14:13:07 +00:00
$settings [] = include ( 'settings/class-wc-settings-general.php' );
$settings [] = include ( 'settings/class-wc-settings-products.php' );
$settings [] = include ( 'settings/class-wc-settings-tax.php' );
$settings [] = include ( 'settings/class-wc-settings-shipping.php' );
2016-01-05 11:23:15 +00:00
$settings [] = include ( 'settings/class-wc-settings-checkout.php' );
2014-01-03 14:13:07 +00:00
$settings [] = include ( 'settings/class-wc-settings-accounts.php' );
$settings [] = include ( 'settings/class-wc-settings-emails.php' );
$settings [] = include ( 'settings/class-wc-settings-integrations.php' );
2015-05-15 19:12:11 +00:00
$settings [] = include ( 'settings/class-wc-settings-api.php' );
2014-01-03 14:13:07 +00:00
self :: $settings = apply_filters ( 'woocommerce_get_settings_pages' , $settings );
}
2014-09-12 00:40:30 +00:00
2014-01-03 14:13:07 +00:00
return self :: $settings ;
2013-07-26 14:36:28 +00:00
}
/**
2015-11-03 12:28:01 +00:00
* Save the settings .
2013-07-26 14:36:28 +00:00
*/
public static function save () {
2014-06-08 20:33:11 +00:00
global $current_tab ;
2013-07-26 14:36:28 +00:00
2014-09-12 00:40:30 +00:00
if ( empty ( $_REQUEST [ '_wpnonce' ] ) || ! wp_verify_nonce ( $_REQUEST [ '_wpnonce' ], 'woocommerce-settings' ) ) {
die ( __ ( 'Action failed. Please refresh the page and retry.' , 'woocommerce' ) );
}
2013-07-26 14:36:28 +00:00
2014-09-12 00:40:30 +00:00
// Trigger actions
do_action ( 'woocommerce_settings_save_' . $current_tab );
do_action ( 'woocommerce_update_options_' . $current_tab );
do_action ( 'woocommerce_update_options' );
2013-07-26 14:36:28 +00:00
self :: add_message ( __ ( 'Your settings have been saved.' , 'woocommerce' ) );
2013-08-06 15:56:15 +00:00
self :: check_download_folder_protection ();
2013-07-26 14:36:28 +00:00
2016-01-05 11:23:15 +00:00
// Clear any unwanted data and flush rules
delete_transient ( 'woocommerce_cache_excluded_uris' );
2013-09-03 15:14:56 +00:00
WC () -> query -> init_query_vars ();
WC () -> query -> add_endpoints ();
2017-01-11 16:12:00 +00:00
wp_schedule_single_event ( time (), 'woocommerce_flush_rewrite_rules' );
2013-09-03 15:14:56 +00:00
2013-07-26 14:36:28 +00:00
do_action ( 'woocommerce_settings_saved' );
}
/**
2015-11-03 12:28:01 +00:00
* Add a message .
2013-07-26 14:36:28 +00:00
* @ param string $text
*/
public static function add_message ( $text ) {
self :: $messages [] = $text ;
}
/**
2015-11-03 12:28:01 +00:00
* Add an error .
2013-07-26 14:36:28 +00:00
* @ param string $text
*/
public static function add_error ( $text ) {
self :: $errors [] = $text ;
}
/**
2015-11-03 12:28:01 +00:00
* Output messages + errors .
2014-09-12 00:40:30 +00:00
* @ return string
2013-07-26 14:36:28 +00:00
*/
public static function show_messages () {
if ( sizeof ( self :: $errors ) > 0 ) {
2014-09-12 00:40:30 +00:00
foreach ( self :: $errors as $error ) {
2016-02-22 13:32:31 +00:00
echo '<div id="message" class="error inline"><p><strong>' . esc_html ( $error ) . '</strong></p></div>' ;
2014-09-12 00:40:30 +00:00
}
2013-07-26 14:36:28 +00:00
} elseif ( sizeof ( self :: $messages ) > 0 ) {
2014-09-12 00:40:30 +00:00
foreach ( self :: $messages as $message ) {
2016-02-22 13:32:31 +00:00
echo '<div id="message" class="updated inline"><p><strong>' . esc_html ( $message ) . '</strong></p></div>' ;
2014-09-12 00:40:30 +00:00
}
2013-07-26 14:36:28 +00:00
}
}
/**
* Settings page .
*
* Handles the display of the main woocommerce settings page in admin .
*/
public static function output () {
2014-09-12 00:40:30 +00:00
global $current_section , $current_tab ;
2013-07-26 14:36:28 +00:00
2014-11-13 08:57:09 +00:00
$suffix = defined ( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min' ;
2014-09-12 00:40:30 +00:00
do_action ( 'woocommerce_settings_start' );
2013-07-26 14:36:28 +00:00
2015-01-09 16:39:10 +00:00
wp_enqueue_script ( 'woocommerce_settings' , WC () -> plugin_url () . '/assets/js/admin/settings' . $suffix . '.js' , array ( 'jquery' , 'jquery-ui-datepicker' , 'jquery-ui-sortable' , 'iris' , 'select2' ), WC () -> version , true );
2013-07-26 14:36:28 +00:00
wp_localize_script ( 'woocommerce_settings' , 'woocommerce_settings_params' , array (
2016-08-27 01:46:45 +00:00
'i18n_nav_warning' => __ ( 'The changes you made will be lost if you navigate away from this page.' , 'woocommerce' ),
2013-07-26 14:36:28 +00:00
) );
// Include settings pages
self :: get_settings_pages ();
// Get current tab/section
2014-02-11 10:30:37 +00:00
$current_tab = empty ( $_GET [ 'tab' ] ) ? 'general' : sanitize_title ( $_GET [ 'tab' ] );
$current_section = empty ( $_REQUEST [ 'section' ] ) ? '' : sanitize_title ( $_REQUEST [ 'section' ] );
2013-07-26 14:36:28 +00:00
2014-09-12 00:40:30 +00:00
// Save settings if data has been posted
if ( ! empty ( $_POST ) ) {
self :: save ();
}
2013-07-26 14:36:28 +00:00
2014-09-12 00:40:30 +00:00
// Add any posted messages
if ( ! empty ( $_GET [ 'wc_error' ] ) ) {
self :: add_error ( stripslashes ( $_GET [ 'wc_error' ] ) );
}
2013-07-26 14:36:28 +00:00
2014-09-12 00:40:30 +00:00
if ( ! empty ( $_GET [ 'wc_message' ] ) ) {
self :: add_message ( stripslashes ( $_GET [ 'wc_message' ] ) );
}
2013-07-26 14:36:28 +00:00
2014-09-12 00:40:30 +00:00
// Get tabs for the settings page
$tabs = apply_filters ( 'woocommerce_settings_tabs_array' , array () );
2013-07-26 14:36:28 +00:00
2016-07-27 10:58:43 +00:00
include ( dirname ( __FILE__ ) . '/views/html-admin-settings.php' );
2013-07-26 14:36:28 +00:00
}
/**
* Get a setting from the settings API .
*
2017-05-15 11:50:52 +00:00
* @ param string $option_name
* @ param mixed $default
*
* @ return mixed
2013-07-26 14:36:28 +00:00
*/
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 ] );
2014-09-12 00:40:30 +00:00
if ( isset ( $option_values [ $key ] ) ) {
2013-07-26 14:36:28 +00:00
$option_value = $option_values [ $key ];
2014-09-12 00:40:30 +00:00
} else {
2013-07-26 14:36:28 +00:00
$option_value = null ;
2014-09-12 00:40:30 +00:00
}
2013-07-26 14:36:28 +00:00
// Single value
} else {
$option_value = get_option ( $option_name , null );
}
2014-09-12 00:40:30 +00:00
if ( is_array ( $option_value ) ) {
2013-07-26 14:36:28 +00:00
$option_value = array_map ( 'stripslashes' , $option_value );
2014-09-12 00:40:30 +00:00
} elseif ( ! is_null ( $option_value ) ) {
2013-07-26 14:36:28 +00:00
$option_value = stripslashes ( $option_value );
2014-09-12 00:40:30 +00:00
}
2013-07-26 14:36:28 +00:00
2016-09-07 22:32:24 +00:00
return ( null === $option_value ) ? $default : $option_value ;
2013-07-26 14:36:28 +00:00
}
/**
* Output admin fields .
*
* Loops though the woocommerce options array and outputs each field .
*
2017-05-15 11:50:52 +00:00
* @ param array [] $options Opens array to output
2013-07-26 14:36:28 +00:00
*/
public static function output_fields ( $options ) {
2014-09-12 00:40:30 +00:00
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 ;
}
2014-11-16 07:49:43 +00:00
if ( ! isset ( $value [ 'placeholder' ] ) ) {
$value [ 'placeholder' ] = '' ;
}
2014-09-12 00:40:30 +00:00
// Custom attribute handling
2013-07-26 14:36:28 +00:00
$custom_attributes = array ();
2014-09-12 00:40:30 +00:00
if ( ! empty ( $value [ 'custom_attributes' ] ) && is_array ( $value [ 'custom_attributes' ] ) ) {
foreach ( $value [ 'custom_attributes' ] as $attribute => $attribute_value ) {
2013-07-26 14:36:28 +00:00
$custom_attributes [] = esc_attr ( $attribute ) . '="' . esc_attr ( $attribute_value ) . '"' ;
2014-09-12 00:40:30 +00:00
}
}
2013-07-26 14:36:28 +00:00
// Description handling
2015-01-15 15:33:02 +00:00
$field_description = self :: get_field_description ( $value );
extract ( $field_description );
2013-07-26 14:36:28 +00:00
// Switch based on type
2014-09-12 00:40:30 +00:00
switch ( $value [ 'type' ] ) {
// Section Titles
case 'title' :
if ( ! empty ( $value [ 'title' ] ) ) {
2016-02-17 18:01:20 +00:00
echo '<h2>' . esc_html ( $value [ 'title' ] ) . '</h2>' ;
2014-09-12 00:40:30 +00:00
}
if ( ! empty ( $value [ 'desc' ] ) ) {
echo wpautop ( wptexturize ( wp_kses_post ( $value [ 'desc' ] ) ) );
}
2016-09-01 20:50:14 +00:00
echo '<table class="form-table">' . " \n \n " ;
2014-09-12 00:40:30 +00:00
if ( ! empty ( $value [ 'id' ] ) ) {
do_action ( 'woocommerce_settings_' . sanitize_title ( $value [ 'id' ] ) );
}
break ;
// Section Ends
case 'sectionend' :
if ( ! empty ( $value [ 'id' ] ) ) {
do_action ( 'woocommerce_settings_' . sanitize_title ( $value [ 'id' ] ) . '_end' );
}
echo '</table>' ;
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 'password' :
$option_value = self :: get_option ( $value [ 'id' ], $value [ 'default' ] );
?> <tr valign="top">
2013-07-26 14:36:28 +00:00
< th scope = " row " class = " titledesc " >
< label for = " <?php echo esc_attr( $value['id'] ); ?> " >< ? php echo esc_html ( $value [ 'title' ] ); ?> </label>
2014-10-17 15:24:21 +00:00
< ? php echo $tooltip_html ; ?>
2013-07-26 14:36:28 +00:00
</ th >
2014-09-12 00:40:30 +00:00
< td class = " forminp forminp-<?php echo sanitize_title( $value['type'] ) ?> " >
< input
name = " <?php echo esc_attr( $value['id'] ); ?> "
id = " <?php echo esc_attr( $value['id'] ); ?> "
2017-04-04 20:27:11 +00:00
type = " <?php echo esc_attr( $value['type'] ); ?> "
2014-09-12 00:40:30 +00:00
style = " <?php echo esc_attr( $value['css'] ); ?> "
value = " <?php echo esc_attr( $option_value ); ?> "
class = " <?php echo esc_attr( $value['class'] ); ?> "
2014-11-16 07:49:43 +00:00
placeholder = " <?php echo esc_attr( $value['placeholder'] ); ?> "
2014-09-12 00:40:30 +00:00
< ? php echo implode ( ' ' , $custom_attributes ); ?>
2017-04-04 20:27:11 +00:00
/> < ? php echo $description ; ?>
</ td >
</ tr >< ? php
break ;
// Color picker.
case 'color' :
$option_value = self :: get_option ( $value [ 'id' ], $value [ 'default' ] );
?> <tr valign="top">
< th scope = " row " class = " titledesc " >
< label for = " <?php echo esc_attr( $value['id'] ); ?> " >< ? php echo esc_html ( $value [ 'title' ] ); ?> </label>
< ? php echo $tooltip_html ; ?>
</ th >
< td class = " forminp forminp-<?php echo sanitize_title( $value['type'] ) ?> " >& lrm ;
< span class = " colorpickpreview " style = " background: <?php echo esc_attr( $option_value ); ?> " ></ span >
< input
name = " <?php echo esc_attr( $value['id'] ); ?> "
id = " <?php echo esc_attr( $value['id'] ); ?> "
type = " text "
dir = " ltr "
style = " <?php echo esc_attr( $value['css'] ); ?> "
value = " <?php echo esc_attr( $option_value ); ?> "
class = " <?php echo esc_attr( $value['class'] ); ?>colorpick "
placeholder = " <?php echo esc_attr( $value['placeholder'] ); ?> "
< ? php echo implode ( ' ' , $custom_attributes ); ?>
2017-03-22 20:12:07 +00:00
/>& lrm ; < ? php echo $description ; ?>
2017-04-04 20:27:11 +00:00
< div id = " colorPickerDiv_<?php echo esc_attr( $value['id'] ); ?> " class = " colorpickdiv " style = " z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;display:none; " ></ div >
2014-09-12 00:40:30 +00:00
</ td >
</ tr >< ? php
break ;
// Textarea
case 'textarea' :
$option_value = self :: get_option ( $value [ 'id' ], $value [ 'default' ] );
?> <tr valign="top">
2013-07-26 14:36:28 +00:00
< th scope = " row " class = " titledesc " >
< label for = " <?php echo esc_attr( $value['id'] ); ?> " >< ? php echo esc_html ( $value [ 'title' ] ); ?> </label>
2014-10-17 15:24:21 +00:00
< ? php echo $tooltip_html ; ?>
2013-07-26 14:36:28 +00:00
</ th >
2014-09-12 00:40:30 +00:00
< td class = " forminp forminp-<?php echo sanitize_title( $value['type'] ) ?> " >
< ? php echo $description ; ?>
< textarea
name = " <?php echo esc_attr( $value['id'] ); ?> "
id = " <?php echo esc_attr( $value['id'] ); ?> "
style = " <?php echo esc_attr( $value['css'] ); ?> "
class = " <?php echo esc_attr( $value['class'] ); ?> "
2014-11-16 07:49:43 +00:00
placeholder = " <?php echo esc_attr( $value['placeholder'] ); ?> "
2014-09-12 00:40:30 +00:00
< ? php echo implode ( ' ' , $custom_attributes ); ?>
>< ? php echo esc_textarea ( $option_value ); ?> </textarea>
</ td >
</ tr >< ? php
break ;
// Select boxes
case 'select' :
case 'multiselect' :
$option_value = self :: get_option ( $value [ 'id' ], $value [ 'default' ] );
?> <tr valign="top">
2013-07-26 14:36:28 +00:00
< th scope = " row " class = " titledesc " >
< label for = " <?php echo esc_attr( $value['id'] ); ?> " >< ? php echo esc_html ( $value [ 'title' ] ); ?> </label>
2014-10-17 15:24:21 +00:00
< ? php echo $tooltip_html ; ?>
2013-07-26 14:36:28 +00:00
</ th >
2014-09-12 00:40:30 +00:00
< td class = " forminp forminp-<?php echo sanitize_title( $value['type'] ) ?> " >
< select
2016-09-07 22:32:24 +00:00
name = " <?php echo esc_attr( $value['id'] ); ?><?php echo ( 'multiselect' === $value['type'] ) ? '[]' : ''; ?> "
2014-09-12 00:40:30 +00:00
id = " <?php echo esc_attr( $value['id'] ); ?> "
style = " <?php echo esc_attr( $value['css'] ); ?> "
class = " <?php echo esc_attr( $value['class'] ); ?> "
< ? php echo implode ( ' ' , $custom_attributes ); ?>
< ? php echo ( 'multiselect' == $value [ 'type' ] ) ? 'multiple="multiple"' : '' ; ?>
>
< ? php
foreach ( $value [ 'options' ] as $key => $val ) {
?>
< option value = " <?php echo esc_attr( $key ); ?> " < ? php
if ( is_array ( $option_value ) ) {
selected ( in_array ( $key , $option_value ), true );
} else {
selected ( $option_value , $key );
}
?> ><?php echo $val ?></option>
< ? php
}
?>
2016-03-04 09:23:45 +00:00
</ select > < ? php echo $description ; ?>
2014-09-12 00:40:30 +00:00
</ td >
</ tr >< ? php
break ;
// Radio inputs
case 'radio' :
$option_value = self :: get_option ( $value [ 'id' ], $value [ 'default' ] );
?> <tr valign="top">
2013-07-26 14:36:28 +00:00
< th scope = " row " class = " titledesc " >
< label for = " <?php echo esc_attr( $value['id'] ); ?> " >< ? php echo esc_html ( $value [ 'title' ] ); ?> </label>
2014-10-17 15:24:21 +00:00
< ? php echo $tooltip_html ; ?>
2013-07-26 14:36:28 +00:00
</ th >
2014-09-12 00:40:30 +00:00
< td class = " forminp forminp-<?php echo sanitize_title( $value['type'] ) ?> " >
< fieldset >
< ? php echo $description ; ?>
< ul >
< ? php
foreach ( $value [ 'options' ] as $key => $val ) {
?>
< li >
< label >< input
name = " <?php echo esc_attr( $value['id'] ); ?> "
value = " <?php echo $key ; ?> "
type = " radio "
style = " <?php echo esc_attr( $value['css'] ); ?> "
class = " <?php echo esc_attr( $value['class'] ); ?> "
< ? php echo implode ( ' ' , $custom_attributes ); ?>
< ? php checked ( $key , $option_value ); ?>
/> < ? php echo $val ?> </label>
</ li >
< ? php
}
?>
</ ul >
</ fieldset >
</ td >
</ tr >< ? php
break ;
// Checkbox input
case 'checkbox' :
2013-07-26 14:36:28 +00:00
2014-01-22 15:22:58 +00:00
$option_value = self :: get_option ( $value [ 'id' ], $value [ 'default' ] );
$visbility_class = array ();
2013-07-26 14:36:28 +00:00
2014-09-12 00:40:30 +00:00
if ( ! isset ( $value [ 'hide_if_checked' ] ) ) {
$value [ 'hide_if_checked' ] = false ;
}
if ( ! isset ( $value [ 'show_if_checked' ] ) ) {
$value [ 'show_if_checked' ] = false ;
}
if ( 'yes' == $value [ 'hide_if_checked' ] || 'yes' == $value [ 'show_if_checked' ] ) {
$visbility_class [] = 'hidden_option' ;
}
if ( 'option' == $value [ 'hide_if_checked' ] ) {
$visbility_class [] = 'hide_options_if_checked' ;
}
if ( 'option' == $value [ 'show_if_checked' ] ) {
$visbility_class [] = 'show_options_if_checked' ;
}
if ( ! isset ( $value [ 'checkboxgroup' ] ) || 'start' == $value [ 'checkboxgroup' ] ) {
?>
< tr valign = " top " class = " <?php echo esc_attr( implode( ' ', $visbility_class ) ); ?> " >
2014-01-22 15:22:58 +00:00
< th scope = " row " class = " titledesc " >< ? php echo esc_html ( $value [ 'title' ] ) ?> </th>
< td class = " forminp forminp-checkbox " >
< fieldset >
2013-07-26 14:36:28 +00:00
< ? php
2014-09-12 00:40:30 +00:00
} else {
?>
< fieldset class = " <?php echo esc_attr( implode( ' ', $visbility_class ) ); ?> " >
< ? php
}
if ( ! empty ( $value [ 'title' ] ) ) {
?>
< legend class = " screen-reader-text " >< span >< ? php echo esc_html ( $value [ 'title' ] ) ?> </span></legend>
< ? php
}
?>
2013-07-26 14:36:28 +00:00
< label for = " <?php echo $value['id'] ?> " >
2014-01-22 15:22:58 +00:00
< input
name = " <?php echo esc_attr( $value['id'] ); ?> "
id = " <?php echo esc_attr( $value['id'] ); ?> "
type = " checkbox "
2016-03-04 09:23:45 +00:00
class = " <?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?> "
2014-01-22 15:22:58 +00:00
value = " 1 "
2016-09-02 01:33:57 +00:00
< ? php checked ( $option_value , 'yes' ); ?>
2014-01-22 15:22:58 +00:00
< ? php echo implode ( ' ' , $custom_attributes ); ?>
/> < ? php echo $description ?>
2014-10-17 15:24:21 +00:00
</ label > < ? php echo $tooltip_html ; ?>
2013-07-26 14:36:28 +00:00
< ? php
2014-01-22 15:22:58 +00:00
if ( ! isset ( $value [ 'checkboxgroup' ] ) || 'end' == $value [ 'checkboxgroup' ] ) {
?>
</ fieldset >
</ td >
</ tr >
2013-07-26 14:36:28 +00:00
< ? php
} else {
?>
2014-01-22 15:22:58 +00:00
</ fieldset >
2013-07-26 14:36:28 +00:00
< ? php
}
2014-09-12 00:40:30 +00:00
break ;
2013-07-26 14:36:28 +00:00
2014-09-12 00:40:30 +00:00
// Image width settings
case 'image_width' :
2013-07-26 14:36:28 +00:00
2016-08-27 03:23:21 +00:00
$image_size = str_replace ( '_image_size' , '' , $value [ 'id' ] );
2015-07-31 10:29:04 +00:00
$size = wc_get_image_size ( $image_size );
2016-08-27 03:23:21 +00:00
$width = isset ( $size [ 'width' ] ) ? $size [ 'width' ] : $value [ 'default' ][ 'width' ];
$height = isset ( $size [ 'height' ] ) ? $size [ 'height' ] : $value [ 'default' ][ 'height' ];
$crop = isset ( $size [ 'crop' ] ) ? $size [ 'crop' ] : $value [ 'default' ][ 'crop' ];
2014-09-12 00:40:30 +00:00
$disabled_attr = '' ;
$disabled_message = '' ;
2014-06-11 20:12:23 +00:00
2014-09-12 00:40:30 +00:00
if ( has_filter ( 'woocommerce_get_image_size_' . $image_size ) ) {
$disabled_attr = 'disabled="disabled"' ;
$disabled_message = " <p><small> " . __ ( 'The settings of this image size have been disabled because its values are being overwritten by a filter.' , 'woocommerce' ) . " </small></p> " ;
}
2013-07-26 14:36:28 +00:00
2014-09-12 00:40:30 +00:00
?> <tr valign="top">
2016-09-02 03:40:52 +00:00
< th scope = " row " class = " titledesc " >< ? php echo esc_html ( $value [ 'title' ] ) ?> <?php echo $tooltip_html . $disabled_message; ?></th>
2014-09-12 00:40:30 +00:00
< td class = " forminp image_width_settings " >
< input name = " <?php echo esc_attr( $value['id'] ); ?>[width] " < ? php echo $disabled_attr ; ?> id="<?php echo esc_attr( $value['id'] ); ?>-width" type="text" size="3" value="<?php echo $width; ?>" /> × <input name="<?php echo esc_attr( $value['id'] ); ?>[height]" <?php echo $disabled_attr; ?> id="<?php echo esc_attr( $value['id'] ); ?>-height" type="text" size="3" value="<?php echo $height; ?>" />px
2016-10-12 10:16:30 +00:00
< label >< input name = " <?php echo esc_attr( $value['id'] ); ?>[crop] " < ? php echo $disabled_attr ; ?> id="<?php echo esc_attr( $value['id'] ); ?>-crop" type="checkbox" value="1" <?php checked( 1, $crop ); ?> /> <?php _e( 'Hard crop?', 'woocommerce' ); ?></label>
2014-09-12 00:40:30 +00:00
</ td >
</ tr >< ? php
break ;
// Single page selects
case 'single_select_page' :
$args = array (
'name' => $value [ 'id' ],
'id' => $value [ 'id' ],
'sort_column' => 'menu_order' ,
'sort_order' => 'ASC' ,
'show_option_none' => ' ' ,
'class' => $value [ 'class' ],
'echo' => false ,
2016-08-27 01:46:45 +00:00
'selected' => absint ( self :: get_option ( $value [ 'id' ] ) ),
2014-09-12 00:40:30 +00:00
);
if ( isset ( $value [ 'args' ] ) ) {
$args = wp_parse_args ( $value [ 'args' ], $args );
}
?> <tr valign="top" class="single_select_page">
2014-10-17 15:24:21 +00:00
< th scope = " row " class = " titledesc " >< ? php echo esc_html ( $value [ 'title' ] ) ?> <?php echo $tooltip_html; ?></th>
2014-09-12 00:40:30 +00:00
< td class = " forminp " >
2016-09-02 01:51:31 +00:00
< ? php echo str_replace ( ' id=' , " data-placeholder=' " . esc_attr__ ( 'Select a page…' , 'woocommerce' ) . " ' style=' " . $value [ 'css' ] . " ' class=' " . $value [ 'class' ] . " ' id= " , wp_dropdown_pages ( $args ) ); ?> <?php echo $description; ?>
2014-09-12 00:40:30 +00:00
</ td >
</ tr >< ? php
break ;
// Single country selects
case 'single_select_country' :
2013-09-26 15:39:07 +00:00
$country_setting = ( string ) self :: get_option ( $value [ 'id' ] );
2013-07-26 14:36:28 +00:00
2014-09-12 00:40:30 +00:00
if ( strstr ( $country_setting , ':' ) ) {
2013-09-26 15:39:07 +00:00
$country_setting = explode ( ':' , $country_setting );
$country = current ( $country_setting );
$state = end ( $country_setting );
2014-09-12 00:40:30 +00:00
} else {
2013-09-26 15:39:07 +00:00
$country = $country_setting ;
$state = '*' ;
2014-09-12 00:40:30 +00:00
}
?> <tr valign="top">
2013-07-26 14:36:28 +00:00
< th scope = " row " class = " titledesc " >
< label for = " <?php echo esc_attr( $value['id'] ); ?> " >< ? php echo esc_html ( $value [ 'title' ] ); ?> </label>
2014-10-17 15:24:21 +00:00
< ? php echo $tooltip_html ; ?>
2013-07-26 14:36:28 +00:00
</ th >
2016-11-04 15:41:51 +00:00
< td class = " forminp " >< select name = " <?php echo esc_attr( $value['id'] ); ?> " style = " <?php echo esc_attr( $value['css'] ); ?> " data - placeholder = " <?php esc_attr_e( 'Choose a country…', 'woocommerce' ); ?> " aria - label = " <?php esc_attr_e( 'Country', 'woocommerce' ) ?> " class = " wc-enhanced-select " >
2014-09-12 00:40:30 +00:00
< ? php WC () -> countries -> country_dropdown_options ( $country , $state ); ?>
</ select > < ? php echo $description ; ?>
</ td >
</ tr >< ? php
break ;
2013-07-26 14:36:28 +00:00
2014-09-12 00:40:30 +00:00
// Country multiselects
case 'multi_select_countries' :
2013-07-26 14:36:28 +00:00
2015-04-01 15:28:51 +00:00
$selections = ( array ) self :: get_option ( $value [ 'id' ] );
2013-07-26 14:36:28 +00:00
2014-09-12 00:40:30 +00:00
if ( ! empty ( $value [ 'options' ] ) ) {
$countries = $value [ 'options' ];
} else {
$countries = WC () -> countries -> countries ;
}
2013-08-02 15:54:28 +00:00
2014-09-12 00:40:30 +00:00
asort ( $countries );
?> <tr valign="top">
2013-07-26 14:36:28 +00:00
< th scope = " row " class = " titledesc " >
< label for = " <?php echo esc_attr( $value['id'] ); ?> " >< ? php echo esc_html ( $value [ 'title' ] ); ?> </label>
2014-10-17 15:24:21 +00:00
< ? php echo $tooltip_html ; ?>
2013-07-26 14:36:28 +00:00
</ th >
2014-09-12 00:40:30 +00:00
< td class = " forminp " >
2016-11-04 15:41:51 +00:00
< select multiple = " multiple " name = " <?php echo esc_attr( $value['id'] ); ?>[] " style = " width:350px " data - placeholder = " <?php esc_attr_e( 'Choose countries…', 'woocommerce' ); ?> " aria - label = " <?php esc_attr_e( 'Country', 'woocommerce' ) ?> " class = " wc-enhanced-select " >
2014-09-12 00:40:30 +00:00
< ? php
2015-04-01 13:33:56 +00:00
if ( ! empty ( $countries ) ) {
2014-09-12 00:40:30 +00:00
foreach ( $countries as $key => $val ) {
2016-09-01 20:50:14 +00:00
echo '<option value="' . esc_attr ( $key ) . '" ' . selected ( in_array ( $key , $selections ), true , false ) . '>' . $val . '</option>' ;
2014-09-12 00:40:30 +00:00
}
}
?>
2016-10-12 10:16:30 +00:00
</ select > < ? php echo ( $description ) ? $description : '' ; ?> <br /><a class="select_all button" href="#"><?php _e( 'Select all', 'woocommerce' ); ?></a> <a class="select_none button" href="#"><?php _e( 'Select none', 'woocommerce' ); ?></a>
2014-09-12 00:40:30 +00:00
</ td >
</ tr >< ? php
break ;
// Default: run an action
default :
do_action ( 'woocommerce_admin_field_' . $value [ 'type' ], $value );
break ;
}
2013-07-26 14:36:28 +00:00
}
}
2014-10-17 15:24:21 +00:00
2014-09-23 22:27:15 +00:00
/**
2017-03-28 17:58:51 +00:00
* Helper function to get the formatted description and tip HTML for a
2015-11-03 18:20:08 +00:00
* given form field . Plugins can call this when implementing their own custom
2014-09-23 22:27:15 +00:00
* settings types .
2014-10-17 15:24:21 +00:00
*
2016-03-04 09:30:03 +00:00
* @ param array $value The form field value array
* @ return array The description and tip as a 2 element array
2014-09-23 22:27:15 +00:00
*/
2014-10-17 15:24:21 +00:00
public static function get_field_description ( $value ) {
$description = '' ;
$tooltip_html = '' ;
2014-09-23 22:27:15 +00:00
if ( true === $value [ 'desc_tip' ] ) {
2014-10-17 15:24:21 +00:00
$tooltip_html = $value [ 'desc' ];
2014-09-23 22:27:15 +00:00
} elseif ( ! empty ( $value [ 'desc_tip' ] ) ) {
2014-10-17 15:24:21 +00:00
$description = $value [ 'desc' ];
$tooltip_html = $value [ 'desc_tip' ];
2014-09-23 22:27:15 +00:00
} elseif ( ! empty ( $value [ 'desc' ] ) ) {
2014-10-17 15:24:21 +00:00
$description = $value [ 'desc' ];
2014-09-23 22:27:15 +00:00
}
if ( $description && in_array ( $value [ 'type' ], array ( 'textarea' , 'radio' ) ) ) {
$description = '<p style="margin-top:0">' . wp_kses_post ( $description ) . '</p>' ;
} elseif ( $description && in_array ( $value [ 'type' ], array ( 'checkbox' ) ) ) {
2015-03-17 14:44:02 +00:00
$description = wp_kses_post ( $description );
2014-09-23 22:27:15 +00:00
} elseif ( $description ) {
$description = '<span class="description">' . wp_kses_post ( $description ) . '</span>' ;
}
2014-10-17 15:24:21 +00:00
if ( $tooltip_html && in_array ( $value [ 'type' ], array ( 'checkbox' ) ) ) {
$tooltip_html = '<p class="description">' . $tooltip_html . '</p>' ;
} elseif ( $tooltip_html ) {
2015-10-23 15:09:08 +00:00
$tooltip_html = wc_help_tip ( $tooltip_html );
2014-09-23 22:27:15 +00:00
}
return array (
2014-10-17 15:24:21 +00:00
'description' => $description ,
2016-08-27 01:46:45 +00:00
'tooltip_html' => $tooltip_html ,
2014-09-23 22:27:15 +00:00
);
}
2013-07-26 14:36:28 +00:00
/**
* Save admin fields .
*
* Loops though the woocommerce options array and outputs each field .
*
2016-03-04 09:41:31 +00:00
* @ param array $options Options array to output
2016-06-13 14:47:09 +00:00
* @ param array $data Optional . Data to use for saving . Defaults to $_POST .
2013-11-28 16:49:30 +00:00
* @ return bool
2013-07-26 14:36:28 +00:00
*/
2016-06-13 14:47:09 +00:00
public static function save_fields ( $options , $data = null ) {
if ( is_null ( $data ) ) {
$data = $_POST ;
}
if ( empty ( $data ) ) {
2014-09-12 00:40:30 +00:00
return false ;
}
2013-07-26 14:36:28 +00:00
2016-03-04 09:41:31 +00:00
// Options to update will be stored here and saved later.
2014-09-12 00:40:30 +00:00
$update_options = array ();
2013-07-26 14:36:28 +00:00
2016-03-04 09:41:31 +00:00
// Loop options and get values to save.
2015-07-06 14:31:43 +00:00
foreach ( $options as $option ) {
if ( ! isset ( $option [ 'id' ] ) || ! isset ( $option [ 'type' ] ) ) {
2014-09-12 00:40:30 +00:00
continue ;
}
2013-07-26 14:36:28 +00:00
2016-03-04 09:41:31 +00:00
// Get posted value.
2015-07-06 14:31:43 +00:00
if ( strstr ( $option [ 'id' ], '[' ) ) {
parse_str ( $option [ 'id' ], $option_name_array );
2014-06-25 15:30:47 +00:00
$option_name = current ( array_keys ( $option_name_array ) );
$setting_name = key ( $option_name_array [ $option_name ] );
2016-06-13 14:47:09 +00:00
$raw_value = isset ( $data [ $option_name ][ $setting_name ] ) ? wp_unslash ( $data [ $option_name ][ $setting_name ] ) : null ;
2014-06-25 15:30:47 +00:00
} else {
2015-07-06 14:31:43 +00:00
$option_name = $option [ 'id' ];
2014-06-25 15:30:47 +00:00
$setting_name = '' ;
2016-06-13 14:47:09 +00:00
$raw_value = isset ( $data [ $option [ 'id' ] ] ) ? wp_unslash ( $data [ $option [ 'id' ] ] ) : null ;
2014-06-25 15:30:47 +00:00
}
2013-07-26 14:36:28 +00:00
2016-03-04 09:41:31 +00:00
// Format the value based on option type.
2015-07-06 14:31:43 +00:00
switch ( $option [ 'type' ] ) {
2014-09-12 00:40:30 +00:00
case 'checkbox' :
2016-07-27 20:52:11 +00:00
$value = '1' === $raw_value || 'yes' === $raw_value ? 'yes' : 'no' ;
2014-09-12 00:40:30 +00:00
break ;
case 'textarea' :
2015-07-06 14:31:43 +00:00
$value = wp_kses_post ( trim ( $raw_value ) );
2014-09-12 00:40:30 +00:00
break ;
case 'multiselect' :
case 'multi_select_countries' :
2015-07-06 14:31:43 +00:00
$value = array_filter ( array_map ( 'wc_clean' , ( array ) $raw_value ) );
2014-09-12 00:40:30 +00:00
break ;
case 'image_width' :
2015-08-19 17:39:38 +00:00
$value = array ();
2015-07-31 10:29:04 +00:00
if ( isset ( $raw_value [ 'width' ] ) ) {
$value [ 'width' ] = wc_clean ( $raw_value [ 'width' ] );
$value [ 'height' ] = wc_clean ( $raw_value [ 'height' ] );
$value [ 'crop' ] = isset ( $raw_value [ 'crop' ] ) ? 1 : 0 ;
2014-09-12 00:40:30 +00:00
} else {
2015-07-31 10:29:04 +00:00
$value [ 'width' ] = $option [ 'default' ][ 'width' ];
$value [ 'height' ] = $option [ 'default' ][ 'height' ];
$value [ 'crop' ] = $option [ 'default' ][ 'crop' ];
2014-09-12 00:40:30 +00:00
}
break ;
2016-06-13 22:11:51 +00:00
case 'select' :
$allowed_values = empty ( $option [ 'options' ] ) ? array () : array_keys ( $option [ 'options' ] );
if ( empty ( $option [ 'default' ] ) && empty ( $allowed_values ) ) {
$value = null ;
break ;
}
$default = ( empty ( $option [ 'default' ] ) ? $allowed_values [ 0 ] : $option [ 'default' ] );
$value = in_array ( $raw_value , $allowed_values ) ? $raw_value : $default ;
break ;
2014-09-12 00:40:30 +00:00
default :
2015-07-06 14:31:43 +00:00
$value = wc_clean ( $raw_value );
2014-09-12 00:40:30 +00:00
break ;
}
2015-07-06 14:31:43 +00:00
/**
* Fire an action when a certain 'type' of field is being saved .
* @ deprecated 2.4 . 0 - doesn ' t allow manipulation of values !
*/
2015-07-14 09:10:03 +00:00
if ( has_action ( 'woocommerce_update_option_' . sanitize_title ( $option [ 'type' ] ) ) ) {
2016-11-23 16:15:00 +00:00
wc_deprecated_function ( 'The woocommerce_update_option_X action' , '2.4.0' , 'woocommerce_admin_settings_sanitize_option filter' );
2015-07-14 09:10:03 +00:00
do_action ( 'woocommerce_update_option_' . sanitize_title ( $option [ 'type' ] ), $option );
continue ;
}
2015-07-06 14:31:43 +00:00
/**
2015-11-03 12:28:01 +00:00
* Sanitize the value of an option .
2015-07-06 14:31:43 +00:00
* @ since 2.4 . 0
*/
$value = apply_filters ( 'woocommerce_admin_settings_sanitize_option' , $value , $option , $raw_value );
/**
2015-11-03 12:28:01 +00:00
* Sanitize the value of an option by option name .
2015-07-06 14:31:43 +00:00
* @ since 2.4 . 0
*/
$value = apply_filters ( " woocommerce_admin_settings_sanitize_option_ $option_name " , $value , $option , $raw_value );
if ( is_null ( $value ) ) {
continue ;
}
2014-09-12 00:40:30 +00:00
2015-07-06 14:31:43 +00:00
// Check if option is an array and handle that differently to single values.
if ( $option_name && $setting_name ) {
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 ();
2014-09-12 00:40:30 +00:00
}
2015-07-06 14:31:43 +00:00
$update_options [ $option_name ][ $setting_name ] = $value ;
} else {
$update_options [ $option_name ] = $value ;
2013-07-26 14:36:28 +00:00
}
2015-07-06 14:31:43 +00:00
/**
2016-03-04 09:41:31 +00:00
* Fire an action before saved .
2015-07-06 14:31:43 +00:00
* @ deprecated 2.4 . 0 - doesn ' t allow manipulation of values !
*/
do_action ( 'woocommerce_update_option' , $option );
2014-09-12 00:40:30 +00:00
}
2013-07-26 14:36:28 +00:00
2016-03-04 09:41:31 +00:00
// Save all options in our array.
2014-09-12 00:40:30 +00:00
foreach ( $update_options as $name => $value ) {
update_option ( $name , $value );
}
2013-07-26 14:36:28 +00:00
2014-09-12 00:40:30 +00:00
return true ;
2013-07-26 14:36:28 +00:00
}
2013-08-06 15:56:15 +00:00
/**
2015-11-03 12:28:01 +00:00
* Checks which method we ' re using to serve downloads .
2013-08-06 15:56:15 +00:00
*
2015-11-03 12:28:01 +00:00
* If using force or x - sendfile , this ensures the . htaccess is in place .
2013-08-06 15:56:15 +00:00
*/
public static function check_download_folder_protection () {
2014-09-12 00:40:30 +00:00
$upload_dir = wp_upload_dir ();
$downloads_url = $upload_dir [ 'basedir' ] . '/woocommerce_uploads' ;
2015-08-24 12:50:14 +00:00
$download_method = get_option ( 'woocommerce_file_download_method' );
2013-08-06 15:56:15 +00:00
2014-09-12 00:40:30 +00:00
if ( 'redirect' == $download_method ) {
2013-08-06 15:56:15 +00:00
// Redirect method - don't protect
2014-09-12 00:40:30 +00:00
if ( file_exists ( $downloads_url . '/.htaccess' ) ) {
2013-08-06 15:56:15 +00:00
unlink ( $downloads_url . '/.htaccess' );
2014-09-12 00:40:30 +00:00
}
2013-08-06 15:56:15 +00:00
} 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 );
}
}
}
}
2013-07-26 14:36:28 +00:00
}
2013-11-03 23:55:34 +00:00
endif ;