| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPPIZZA_MODULE_SETTINGS_ORDER_HISTORY Class |
| 4 |
* |
| 5 |
* @package WPPIZZA |
| 6 |
* @subpackage WPPIZZA_MODULE_SETTINGS_ORDER_HISTORY |
| 7 |
* @copyright Copyright (c) 2015, Oliver Bach |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 3.0 |
| 10 |
* |
| 11 |
*/ |
| 12 |
if ( ! defined( 'ABSPATH' ) ) exit;/*Exit if accessed directly*/ |
| 13 |
|
| 14 |
|
| 15 |
/************************************************************************************************************************ |
| 16 |
* |
| 17 |
* |
| 18 |
* |
| 19 |
* |
| 20 |
* |
| 21 |
* |
| 22 |
************************************************************************************************************************/ |
| 23 |
class WPPIZZA_MODULE_SETTINGS_ORDER_HISTORY{ |
| 24 |
|
| 25 |
private $settings_page = 'settings';/* which admin subpage (identified there by this->class_key) are we adding this to */ |
| 26 |
|
| 27 |
|
| 28 |
private $section_key = 'order_history';/* must be unique */ |
| 29 |
|
| 30 |
|
| 31 |
function __construct() { |
| 32 |
/********************************************************** |
| 33 |
[add settings to admin] |
| 34 |
***********************************************************/ |
| 35 |
if(is_admin()){ |
| 36 |
/* add admin options settings page*/ |
| 37 |
add_filter('wppizza_filter_settings_sections_'.$this->settings_page.'', array($this, 'admin_options_settings'), 20, 5); |
| 38 |
/* add admin options settings page fields */ |
| 39 |
add_action('wppizza_admin_settings_section_fields_'.$this->settings_page.'', array($this, 'admin_options_fields_settings'), 10, 5); |
| 40 |
/**add default options **/ |
| 41 |
add_filter('wppizza_filter_setup_default_options', array( $this, 'options_default')); |
| 42 |
/**validate options**/ |
| 43 |
add_filter('wppizza_filter_options_validate', array( $this, 'options_validate'), 10, 2 ); |
| 44 |
} |
| 45 |
/********************************************************** |
| 46 |
[filter/actions depending on settings] |
| 47 |
***********************************************************/ |
| 48 |
/** set max results per page admin order history **/ |
| 49 |
add_filter('wppizza_filter_order_history_max_results',array( $this, 'admin_order_history_max_results')); |
| 50 |
/** set polling time admin order history **/ |
| 51 |
add_filter('wppizza_filter_order_history_polling_time', array( $this, 'admin_order_history_polling_time')); |
| 52 |
/** set auto poll admin order history **/ |
| 53 |
add_filter('wppizza_filter_order_history_polling_auto', array( $this, 'admin_order_history_polling_auto')); |
| 54 |
} |
| 55 |
|
| 56 |
/******************************************************************************************************************************************************* |
| 57 |
* |
| 58 |
* |
| 59 |
* |
| 60 |
* [frontend filters] |
| 61 |
* |
| 62 |
* |
| 63 |
* |
| 64 |
********************************************************************************************************************************************************/ |
| 65 |
/************************************* |
| 66 |
|
| 67 |
admin_order_history_max_results |
| 68 |
|
| 69 |
**************************************/ |
| 70 |
function admin_order_history_max_results($int){ |
| 71 |
global $wppizza_options; |
| 72 |
if(!empty($wppizza_options[$this->settings_page]['admin_order_history_max_results'])){ |
| 73 |
$int = $wppizza_options[$this->settings_page]['admin_order_history_max_results']; |
| 74 |
} |
| 75 |
|
| 76 |
return $int; |
| 77 |
} |
| 78 |
/************************************* |
| 79 |
|
| 80 |
admin_order_history_polling_time |
| 81 |
|
| 82 |
**************************************/ |
| 83 |
function admin_order_history_polling_time($int){ |
| 84 |
global $wppizza_options; |
| 85 |
if(!empty($wppizza_options[$this->settings_page]['admin_order_history_polling_time'])){ |
| 86 |
$int = $wppizza_options[$this->settings_page]['admin_order_history_polling_time']; |
| 87 |
} |
| 88 |
|
| 89 |
return $int; |
| 90 |
} |
| 91 |
/************************************* |
| 92 |
|
| 93 |
admin_order_history_polling_auto |
| 94 |
|
| 95 |
**************************************/ |
| 96 |
function admin_order_history_polling_auto($bool){ |
| 97 |
global $wppizza_options; |
| 98 |
$bool = !empty($wppizza_options[$this->settings_page]['admin_order_history_polling_auto']) ? true : false; |
| 99 |
|
| 100 |
return $bool; |
| 101 |
} |
| 102 |
/******************************************************************************************************************************************************* |
| 103 |
* |
| 104 |
* |
| 105 |
* |
| 106 |
* [add admin page options] |
| 107 |
* |
| 108 |
* |
| 109 |
* |
| 110 |
********************************************************************************************************************************************************/ |
| 111 |
|
| 112 |
/*------------------------------------------------------------------------------ |
| 113 |
# |
| 114 |
# |
| 115 |
# [settings page] |
| 116 |
# |
| 117 |
# |
| 118 |
------------------------------------------------------------------------------*/ |
| 119 |
|
| 120 |
/*------------------------------------------------------------------------------ |
| 121 |
# [settings section - setting page] |
| 122 |
# @since 3.0 |
| 123 |
# @return array() |
| 124 |
------------------------------------------------------------------------------*/ |
| 125 |
function admin_options_settings($settings, $sections, $fields, $inputs, $help){ |
| 126 |
|
| 127 |
/*section*/ |
| 128 |
if($sections){ |
| 129 |
$settings['sections'][$this->section_key] = __('Order History', 'wppizza-admin'); |
| 130 |
} |
| 131 |
/*help*/ |
| 132 |
if($help){ |
| 133 |
$settings['help'][$this->section_key][] = array( |
| 134 |
'label'=>__('Order History', 'wppizza-admin'), |
| 135 |
'description'=>array( |
| 136 |
__('Please adjust settings as appropriate according to the information provided next to each individual option.', 'wppizza-admin') |
| 137 |
) |
| 138 |
); |
| 139 |
} |
| 140 |
/*fields*/ |
| 141 |
if($fields){ |
| 142 |
$field = 'admin_order_history_max_results'; |
| 143 |
$settings['fields'][$this->section_key][$field] = array( __('Max Results Per Page', 'wppizza-admin'), array( |
| 144 |
'value_key'=>$field, |
| 145 |
'option_key'=>$this->settings_page, |
| 146 |
'label'=>__('default number of results to show in admin order history','wppizza-admin'), |
| 147 |
'description'=>array() |
| 148 |
)); |
| 149 |
$field = 'admin_order_history_polling_time'; |
| 150 |
$settings['fields'][$this->section_key][$field] = array( __('Polling Time', 'wppizza-admin'), array( |
| 151 |
'value_key'=>$field, |
| 152 |
'option_key'=>$this->settings_page, |
| 153 |
'label'=>__('default polling time [in seconds]. 15 seconds minimum', 'wppizza-admin'), |
| 154 |
'description'=>array() |
| 155 |
)); |
| 156 |
$field = 'admin_order_history_polling_auto'; |
| 157 |
$settings['fields'][$this->section_key][$field] = array( __('Auto Polling', 'wppizza-admin'), array( |
| 158 |
'value_key'=>$field, |
| 159 |
'option_key'=>$this->settings_page, |
| 160 |
'label'=>__('automatically activate order polling on page load', 'wppizza-admin'), |
| 161 |
'description'=>array() |
| 162 |
)); |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
return $settings; |
| 167 |
} |
| 168 |
/*------------------------------------------------------------------------------ |
| 169 |
# [output option fields - setting page] |
| 170 |
# @since 3.0 |
| 171 |
# @return array() |
| 172 |
------------------------------------------------------------------------------*/ |
| 173 |
function admin_options_fields_settings($wppizza_options, $options_key, $field, $label, $description){ |
| 174 |
|
| 175 |
if($field=='admin_order_history_max_results'){ |
| 176 |
echo "<label>"; |
| 177 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' size='2' type='text' value='".$wppizza_options[$options_key][$field]."' />"; |
| 178 |
echo "" . $label . ""; |
| 179 |
echo "</label>"; |
| 180 |
echo"".$description.""; |
| 181 |
} |
| 182 |
|
| 183 |
if($field=='admin_order_history_polling_time'){ |
| 184 |
echo "<label>"; |
| 185 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' size='2' type='text' value='".$wppizza_options[$options_key][$field]."' />"; |
| 186 |
echo "" . $label . ""; |
| 187 |
echo "</label>"; |
| 188 |
echo"".$description.""; |
| 189 |
} |
| 190 |
|
| 191 |
if($field=='admin_order_history_polling_auto'){ |
| 192 |
echo "<label>"; |
| 193 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />"; |
| 194 |
echo "" . $label . ""; |
| 195 |
echo "</label>"; |
| 196 |
echo"".$description.""; |
| 197 |
} |
| 198 |
|
| 199 |
} |
| 200 |
/*------------------------------------------------------------------------------ |
| 201 |
# [insert default option on install] |
| 202 |
# $parameter $options array() | filter passing on filtered options |
| 203 |
# @since 3.0 |
| 204 |
# @return array() |
| 205 |
------------------------------------------------------------------------------*/ |
| 206 |
function options_default($options){ |
| 207 |
$options[$this->settings_page]['admin_order_history_max_results'] = 25; |
| 208 |
$options[$this->settings_page]['admin_order_history_polling_time'] = 60; |
| 209 |
$options[$this->settings_page]['admin_order_history_polling_auto'] = true; |
| 210 |
|
| 211 |
return $options; |
| 212 |
} |
| 213 |
|
| 214 |
/*------------------------------------------------------------------------------ |
| 215 |
# [validate options on save/update] |
| 216 |
# |
| 217 |
# @since 3.0 |
| 218 |
# @return array() |
| 219 |
------------------------------------------------------------------------------*/ |
| 220 |
function options_validate($options, $input){ |
| 221 |
/**make sure we get the full array on install/update**/ |
| 222 |
if ( empty( $_POST['_wp_http_referer'] ) ) { |
| 223 |
return $input; |
| 224 |
} |
| 225 |
/******************************** |
| 226 |
* [validate] |
| 227 |
********************************/ |
| 228 |
if(isset($_POST[''.WPPIZZA_SLUG.'_'.$this->settings_page.''])){ |
| 229 |
$options[$this->settings_page]['admin_order_history_max_results'] = wppizza_validate_int_only($input[$this->settings_page]['admin_order_history_max_results']); |
| 230 |
$options[$this->settings_page]['admin_order_history_polling_time'] = max(15,wppizza_validate_int_only($input[$this->settings_page]['admin_order_history_polling_time'])); |
| 231 |
$options[$this->settings_page]['admin_order_history_polling_auto'] = !empty($input[$this->settings_page]['admin_order_history_polling_auto']) ? true : false; |
| 232 |
} |
| 233 |
return $options; |
| 234 |
} |
| 235 |
} |
| 236 |
/*************************************************************** |
| 237 |
* |
| 238 |
* [ini] |
| 239 |
* |
| 240 |
***************************************************************/ |
| 241 |
$WPPIZZA_MODULE_SETTINGS_ORDER_HISTORY = new WPPIZZA_MODULE_SETTINGS_ORDER_HISTORY(); |
| 242 |
?> |