| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPPIZZA_MODULE_OPENINGTIMES_STANDARD Class |
| 4 |
* |
| 5 |
* @package WPPIZZA |
| 6 |
* @subpackage WPPIZZA_MODULE_OPENINGTIMES_STANDARD |
| 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_OPENINGTIMES_STANDARD{ |
| 24 |
|
| 25 |
private $settings_page = 'openingtimes';/* which admin subpage (identified there by this->class_key) are we adding this to */ |
| 26 |
private $section_key = 'standard';/* must be unique */ |
| 27 |
|
| 28 |
function __construct() { |
| 29 |
/********************************************************** |
| 30 |
[add settings to admin] |
| 31 |
***********************************************************/ |
| 32 |
if(is_admin()){ |
| 33 |
/* add admin options settings page*/ |
| 34 |
add_filter('wppizza_filter_settings_sections_'.$this->settings_page.'', array($this, 'admin_options_settings'), 20, 5); |
| 35 |
/* add admin options settings page fields */ |
| 36 |
add_action('wppizza_admin_settings_section_fields_'.$this->settings_page.'', array($this, 'admin_options_fields_settings'), 10, 5); |
| 37 |
/**add default options **/ |
| 38 |
add_filter('wppizza_filter_setup_default_options', array( $this, 'options_default')); |
| 39 |
/**validate options**/ |
| 40 |
add_filter('wppizza_filter_options_validate', array( $this, 'options_validate'), 10, 2 ); |
| 41 |
/**add text header*/ |
| 42 |
add_action('wppizza_settings_sections_header_'.$this->settings_page.'', array( $this, 'sections_header'), 10, 2 ); |
| 43 |
} |
| 44 |
/********************************************************** |
| 45 |
[filter/actions depending on settings] |
| 46 |
***********************************************************/ |
| 47 |
|
| 48 |
} |
| 49 |
|
| 50 |
/******************************************************************************************************************************************************* |
| 51 |
* |
| 52 |
* |
| 53 |
* |
| 54 |
* [frontend filters] |
| 55 |
* |
| 56 |
* |
| 57 |
* |
| 58 |
********************************************************************************************************************************************************/ |
| 59 |
|
| 60 |
|
| 61 |
/******************************************************************************************************************************************************* |
| 62 |
* |
| 63 |
* |
| 64 |
* |
| 65 |
* [add admin page options] |
| 66 |
* |
| 67 |
* |
| 68 |
* |
| 69 |
********************************************************************************************************************************************************/ |
| 70 |
|
| 71 |
/*------------------------------------------------------------------------------ |
| 72 |
# |
| 73 |
# |
| 74 |
# [settings page] |
| 75 |
# |
| 76 |
# |
| 77 |
------------------------------------------------------------------------------*/ |
| 78 |
/********************************************************* |
| 79 |
[more header info] |
| 80 |
*********************************************************/ |
| 81 |
function sections_header($arg, $section_count){ |
| 82 |
if($arg['id']==$this->section_key){ |
| 83 |
|
| 84 |
$timezone_set = (get_option('timezone_string')!='') ? get_option('timezone_string') : get_option('gmt_offset') ; |
| 85 |
echo '<span style="font-size:90%">'.__('your currently set timezone: ', 'wppizza-admin').' '.$timezone_set.' - <a href="'.admin_url('options-general.php').'">'.__('click to change', 'wppizza-admin').'</a></span>'; |
| 86 |
} |
| 87 |
} |
| 88 |
/*------------------------------------------------------------------------------ |
| 89 |
# [settings section - setting page] |
| 90 |
# @since 3.0 |
| 91 |
# @return array() |
| 92 |
------------------------------------------------------------------------------*/ |
| 93 |
function admin_options_settings($settings, $sections, $fields, $inputs, $help){ |
| 94 |
|
| 95 |
/*section*/ |
| 96 |
if($sections){ |
| 97 |
$settings['sections'][$this->section_key] = __('Standard Opening Times', 'wppizza-admin'); |
| 98 |
} |
| 99 |
|
| 100 |
/*help*/ |
| 101 |
if($help){ |
| 102 |
$settings['help'][$this->section_key][] = array( |
| 103 |
'label'=>__('Manage Standard Opening Times', 'wppizza-admin'), |
| 104 |
'description'=>array( |
| 105 |
__('Set your standard opening times. It will not be possible to place an order outside these times.', 'wppizza-admin'), |
| 106 |
'<b>'.__('USE 24 HOUR CLOCK.', 'wppizza-admin').'</b>', |
| 107 |
__('If you are closed on a given day set both times to be the same, if you are open 24 hours set times from 0:00 to 24:00', 'wppizza-admin'), |
| 108 |
'<span class="wppizza-highlight">'.__('Ensure that the Wordpress timezone setting in Settings->Timezone is correct', 'wppizza-admin').'</span>' |
| 109 |
) |
| 110 |
); |
| 111 |
} |
| 112 |
|
| 113 |
/*fields*/ |
| 114 |
if($fields){ |
| 115 |
$field = 'opening_times_standard'; |
| 116 |
$settings['fields'][$this->section_key][$field] = array( '', array( |
| 117 |
'value_key'=>$field, |
| 118 |
'option_key'=>$this->settings_page, |
| 119 |
'label'=>'', |
| 120 |
'description'=>array() |
| 121 |
)); |
| 122 |
} |
| 123 |
|
| 124 |
return $settings; |
| 125 |
} |
| 126 |
/*------------------------------------------------------------------------------ |
| 127 |
# [output option fields - setting page] |
| 128 |
# @since 3.0 |
| 129 |
# @return array() |
| 130 |
------------------------------------------------------------------------------*/ |
| 131 |
function admin_options_fields_settings($wppizza_options, $options_key, $field, $label, $description){ |
| 132 |
|
| 133 |
if($field=='opening_times_standard'){ |
| 134 |
echo"<div id='wppizza_".$field."_options' class='wppizza_admin_options'>"; |
| 135 |
foreach(wppizza_days() as $k=>$v){ |
| 136 |
echo"<div>"; |
| 137 |
echo"<label class='wppizza_weekday'>".$v.":</label> ".__('open from', 'wppizza-admin').":"; |
| 138 |
echo "<input name='".WPPIZZA_SLUG."[".$this->settings_page."][".$field."][".$k."][open]' size='3' type='text' autocomplete='off' class='wppizza-time-select' value='".$wppizza_options[$this->settings_page][$field][$k]['open']."' />"; |
| 139 |
echo"".__('to', 'wppizza-admin').":"; |
| 140 |
echo "<input name='".WPPIZZA_SLUG."[".$this->settings_page."][".$field."][".$k."][close]' size='3' type='text' autocomplete='off' class='wppizza-time-select' value='".$wppizza_options[$this->settings_page][$field][$k]['close']."' />"; |
| 141 |
echo"</div>"; |
| 142 |
} |
| 143 |
echo"</div>"; |
| 144 |
} |
| 145 |
} |
| 146 |
/*------------------------------------------------------------------------------ |
| 147 |
# [insert default option on install] |
| 148 |
# $parameter $options array() | filter passing on filtered options |
| 149 |
# @since 3.0 |
| 150 |
# @return array() |
| 151 |
------------------------------------------------------------------------------*/ |
| 152 |
function options_default($options){ |
| 153 |
|
| 154 |
$options[$this->settings_page]['opening_times_standard']=array( |
| 155 |
0=>array('open'=>'14:30','close'=>'01:00'), |
| 156 |
1=>array('open'=>'09:30','close'=>'02:00'), |
| 157 |
2=>array('open'=>'09:30','close'=>'02:00'), |
| 158 |
3=>array('open'=>'09:30','close'=>'02:00'), |
| 159 |
4=>array('open'=>'09:30','close'=>'02:00'), |
| 160 |
5=>array('open'=>'09:30','close'=>'02:00'), |
| 161 |
6=>array('open'=>'09:30','close'=>'02:00') |
| 162 |
); |
| 163 |
|
| 164 |
return $options; |
| 165 |
} |
| 166 |
|
| 167 |
/*------------------------------------------------------------------------------ |
| 168 |
# [validate options on save/update] |
| 169 |
# |
| 170 |
# @since 3.0 |
| 171 |
# @return array() |
| 172 |
------------------------------------------------------------------------------*/ |
| 173 |
function options_validate($options, $input){ |
| 174 |
/**make sure we get the full array on install/update**/ |
| 175 |
if ( empty( $_POST['_wp_http_referer'] ) ) { |
| 176 |
return $input; |
| 177 |
} |
| 178 |
|
| 179 |
if(isset($_POST[''.WPPIZZA_SLUG.'_'.$this->settings_page.''])){ |
| 180 |
|
| 181 |
$options[$this->settings_page]['opening_times_standard'] = array(); |
| 182 |
ksort($input[$this->settings_page]['opening_times_standard']);//just for consistency. not really necessary though |
| 183 |
foreach($input[$this->settings_page]['opening_times_standard'] as $k=>$v){ |
| 184 |
foreach($v as $l=>$m){ |
| 185 |
$options[$this->settings_page]['opening_times_standard'][$k][$l]=wppizza_validate_24hourtime($m); |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
} |
| 190 |
return $options; |
| 191 |
} |
| 192 |
|
| 193 |
} |
| 194 |
/*************************************************************** |
| 195 |
* |
| 196 |
* [ini] |
| 197 |
* |
| 198 |
***************************************************************/ |
| 199 |
$WPPIZZA_MODULE_OPENINGTIMES_STANDARD = new WPPIZZA_MODULE_OPENINGTIMES_STANDARD(); |
| 200 |
?> |