| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPPIZZA_MODULE_LAYOUT_MISCELLANEOUS Class |
| 4 |
* |
| 5 |
* @package WPPIZZA |
| 6 |
* @subpackage WPPIZZA_MODULE_LAYOUT_MISCELLANEOUS |
| 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_LAYOUT_MISCELLANEOUS{ |
| 24 |
|
| 25 |
private $settings_page = 'layout';/* which admin subpage (identified there by this->class_key) are we adding this to */ |
| 26 |
|
| 27 |
private $section_key = 'miscellaneous';/* must be unique */ |
| 28 |
|
| 29 |
|
| 30 |
function __construct() { |
| 31 |
/********************************************************** |
| 32 |
[add settings to admin] |
| 33 |
***********************************************************/ |
| 34 |
if(is_admin()){ |
| 35 |
/* add admin options settings page*/ |
| 36 |
add_filter('wppizza_filter_settings_sections_'.$this->settings_page.'', array($this, 'admin_options_settings'), 70, 5); |
| 37 |
/* add admin options settings page fields */ |
| 38 |
add_action('wppizza_admin_settings_section_fields_'.$this->settings_page.'', array($this, 'admin_options_fields_settings'), 10, 5); |
| 39 |
/**add default options **/ |
| 40 |
add_filter('wppizza_filter_setup_default_options', array( $this, 'options_default')); |
| 41 |
/**validate options**/ |
| 42 |
add_filter('wppizza_filter_options_validate', array( $this, 'options_validate'), 10, 2 ); |
| 43 |
/**add text header*/ |
| 44 |
//add_action('wppizza_settings_sections_header_'.$this->settings_page.'', array( $this, 'sections_header'), 10, 2 ); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
/******************************************************************************************************************************************************* |
| 49 |
* |
| 50 |
* |
| 51 |
* |
| 52 |
* [frontend filters] |
| 53 |
* |
| 54 |
* |
| 55 |
* |
| 56 |
********************************************************************************************************************************************************/ |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
/******************************************************************************************************************************************************* |
| 61 |
* |
| 62 |
* |
| 63 |
* |
| 64 |
* [add admin page options] |
| 65 |
* |
| 66 |
* |
| 67 |
* |
| 68 |
********************************************************************************************************************************************************/ |
| 69 |
|
| 70 |
/*------------------------------------------------------------------------------ |
| 71 |
# |
| 72 |
# |
| 73 |
# [settings page] |
| 74 |
# |
| 75 |
# |
| 76 |
------------------------------------------------------------------------------*/ |
| 77 |
|
| 78 |
/*------------------------------------------------------------------------------ |
| 79 |
# [settings section - setting page] |
| 80 |
# @since 3.0 |
| 81 |
# @return array() |
| 82 |
------------------------------------------------------------------------------*/ |
| 83 |
function admin_options_settings($settings, $sections, $fields, $inputs, $help){ |
| 84 |
|
| 85 |
/*section*/ |
| 86 |
if($sections){ |
| 87 |
$settings['sections'][$this->section_key] = __('Miscellaneous', 'wppizza-admin'); |
| 88 |
} |
| 89 |
|
| 90 |
/*help*/ |
| 91 |
if($help){ |
| 92 |
} |
| 93 |
|
| 94 |
/*fields*/ |
| 95 |
if($fields){ |
| 96 |
|
| 97 |
$field = 'add_to_cart_on_title_click'; |
| 98 |
$settings['fields'][$this->section_key][$field] = array( __('Click title to add to cart', 'wppizza-admin') , array( |
| 99 |
'value_key'=>$field, |
| 100 |
'option_key'=>$this->settings_page, |
| 101 |
'label'=>__('Add item to cart on click of *item title* if there is only one pricetier for a menu item:', 'wppizza-admin'), |
| 102 |
'description'=>array() |
| 103 |
)); |
| 104 |
$field = 'jquery_fb_add_to_cart'; |
| 105 |
$settings['fields'][$this->section_key][$field] = array( __('Briefly display text in place of price when adding item to cart', 'wppizza-admin') , array( |
| 106 |
'value_key'=>$field, |
| 107 |
'option_key'=>$this->settings_page, |
| 108 |
'label'=>__('Replace item price with customised text when adding an item to cart [set/edit text in localization]', 'wppizza-admin'), |
| 109 |
'description'=>array() |
| 110 |
)); |
| 111 |
$field = 'suppress_loop_headers'; |
| 112 |
$settings['fields'][$this->section_key][$field] = array( __('Suppress category header', 'wppizza-admin') , array( |
| 113 |
'value_key'=>$field, |
| 114 |
'option_key'=>$this->settings_page, |
| 115 |
'label'=>__('Globally suppress category header and description above list of menu items (same as setting noheader=1 in each shortcode)', 'wppizza-admin'), |
| 116 |
'description'=>array() |
| 117 |
)); |
| 118 |
$field = 'category_accordion'; |
| 119 |
$settings['fields'][$this->section_key][$field] = array( __('Categories accordion', 'wppizza-admin') , array( |
| 120 |
'value_key'=>$field, |
| 121 |
'option_key'=>$this->settings_page, |
| 122 |
'label'=>__('Display of multiple categories in an accordion type style, using category title as clickable element to expand list of menu items.', 'wppizza-admin'), |
| 123 |
'description'=>array() |
| 124 |
)); |
| 125 |
$field = 'category_accordion_style'; |
| 126 |
$settings['fields'][$this->section_key][$field] = array( __('Accordion style', 'wppizza-admin') , array( |
| 127 |
'value_key'=>$field, |
| 128 |
'option_key'=>$this->settings_page, |
| 129 |
'label'=>__('Which style would you like to use for the accordion', 'wppizza-admin'), |
| 130 |
'description'=>array() |
| 131 |
)); |
| 132 |
$field = 'hide_cart_icon'; |
| 133 |
$settings['fields'][$this->section_key][$field] = array( __('Hide cart icon next to prices', 'wppizza-admin') , array( |
| 134 |
'value_key'=>$field, |
| 135 |
'option_key'=>$this->settings_page, |
| 136 |
'label'=>'', |
| 137 |
'description'=>array() |
| 138 |
)); |
| 139 |
$field = 'hide_single_pricetier'; |
| 140 |
$settings['fields'][$this->section_key][$field] = array( __('Hide size name and cart icon if item has only one size', 'wppizza-admin') , array( |
| 141 |
'value_key'=>$field, |
| 142 |
'option_key'=>$this->settings_page, |
| 143 |
'label'=>'', |
| 144 |
'description'=>array() |
| 145 |
)); |
| 146 |
$field = 'prettify_js_alerts'; |
| 147 |
$settings['fields'][$this->section_key][$field] = array( __('Stylable javascript alerts', 'wppizza-admin') , array( |
| 148 |
'value_key'=>$field, |
| 149 |
'option_key'=>$this->settings_page, |
| 150 |
'label'=>__('Convert browser native javascript popup alert boxes to css stylable modal windows (this will not work for "OK/Cancel" type confirm popups)', 'wppizza-admin'), |
| 151 |
'description'=>array() |
| 152 |
)); |
| 153 |
|
| 154 |
} |
| 155 |
|
| 156 |
return $settings; |
| 157 |
} |
| 158 |
/*------------------------------------------------------------------------------ |
| 159 |
# [output option fields - setting page] |
| 160 |
# @since 3.0 |
| 161 |
# @return array() |
| 162 |
------------------------------------------------------------------------------*/ |
| 163 |
function admin_options_fields_settings($wppizza_options, $options_key, $field, $label, $description){ |
| 164 |
|
| 165 |
if($field=='add_to_cart_on_title_click' ){ |
| 166 |
print'<label>'; |
| 167 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options['layout'][$field],true,false)." value='1' />"; |
| 168 |
print'' . $label . ''; |
| 169 |
print'</label>'; |
| 170 |
print'' . $description . ''; |
| 171 |
} |
| 172 |
if($field=='jquery_fb_add_to_cart'){ |
| 173 |
print'<label>'; |
| 174 |
echo "<input id='' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />"; |
| 175 |
print'' . $label . ''; |
| 176 |
print'</label>'; |
| 177 |
print'' . $description . ''; |
| 178 |
|
| 179 |
print'<br />'; |
| 180 |
print'<label>'; |
| 181 |
echo "<input id='' name='".WPPIZZA_SLUG."[".$options_key."][jquery_fb_add_to_cart_ms]' size='4' type='text' value='".$wppizza_options[$options_key]['jquery_fb_add_to_cart_ms']."' />"; |
| 182 |
echo" ".__('How long is it visible for before reverting back to displaying price [in ms]', 'wppizza-admin').""; |
| 183 |
print'</label>'; |
| 184 |
} |
| 185 |
if($field=='suppress_loop_headers'){ |
| 186 |
print'<label>'; |
| 187 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />"; |
| 188 |
print'' . $label . ''; |
| 189 |
print'</label>'; |
| 190 |
print'' . $description . ''; |
| 191 |
} |
| 192 |
if($field=='category_accordion'){ |
| 193 |
print'<label>'; |
| 194 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />"; |
| 195 |
print'' . $label . ''; |
| 196 |
print'</label>'; |
| 197 |
print'' . $description . ''; |
| 198 |
} |
| 199 |
if($field=='category_accordion_style'){ |
| 200 |
print'<label>'; |
| 201 |
echo "<select name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' class='wppizza_".$field."'>"; |
| 202 |
foreach(wppizza_ui_styles() as $k=>$style){ |
| 203 |
echo "<option value='".$style."' ".selected($wppizza_options[$options_key][$field],$style,false).">".$style."</option>"; |
| 204 |
} |
| 205 |
echo "<option value='' ".selected($wppizza_options[$options_key][$field],'',false).">".__('a (themeroller) style is already loaded / I provide my own style', 'wppizza-admin')."</option>"; |
| 206 |
echo "</select>"; |
| 207 |
print'' . $label . ''; |
| 208 |
print'</label>'; |
| 209 |
} |
| 210 |
if($field=='hide_cart_icon'){ |
| 211 |
print'<label>'; |
| 212 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />"; |
| 213 |
print'' . $label . ''; |
| 214 |
print'</label>'; |
| 215 |
print'' . $description . ''; |
| 216 |
} |
| 217 |
if($field=='hide_single_pricetier'){ |
| 218 |
print'<label>'; |
| 219 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />"; |
| 220 |
print'' . $label . ''; |
| 221 |
print'</label>'; |
| 222 |
print'' . $description . ''; |
| 223 |
} |
| 224 |
if($field=='prettify_js_alerts'){ |
| 225 |
print'<label>'; |
| 226 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />"; |
| 227 |
print'' . $label . ''; |
| 228 |
print'</label>'; |
| 229 |
print'' . $description . ''; |
| 230 |
} |
| 231 |
|
| 232 |
} |
| 233 |
|
| 234 |
/**************************************************************** |
| 235 |
* |
| 236 |
* [insert default option on install] |
| 237 |
* $parameter $options array() | filter passing on filtered options |
| 238 |
* @since 3.0 |
| 239 |
* @return array() |
| 240 |
* |
| 241 |
****************************************************************/ |
| 242 |
function options_default($options){ |
| 243 |
|
| 244 |
$options[$this->settings_page]['add_to_cart_on_title_click'] = false; |
| 245 |
$options[$this->settings_page]['jquery_fb_add_to_cart'] = true; |
| 246 |
$options[$this->settings_page]['jquery_fb_add_to_cart_ms'] = 1000; |
| 247 |
$options[$this->settings_page]['suppress_loop_headers'] = false; |
| 248 |
$options[$this->settings_page]['category_accordion'] = false; |
| 249 |
$options[$this->settings_page]['category_accordion_style'] = 'smoothness'; |
| 250 |
$options[$this->settings_page]['hide_cart_icon'] = false; |
| 251 |
$options[$this->settings_page]['hide_single_pricetier'] = false; |
| 252 |
$options[$this->settings_page]['prettify_js_alerts'] = false; |
| 253 |
|
| 254 |
return $options; |
| 255 |
} |
| 256 |
|
| 257 |
/*------------------------------------------------------------------------------ |
| 258 |
# [validate options on save/update] |
| 259 |
# |
| 260 |
# @since 3.0 |
| 261 |
# @return array() |
| 262 |
------------------------------------------------------------------------------*/ |
| 263 |
function options_validate($options, $input){ |
| 264 |
/**make sure we get the full array on install/update**/ |
| 265 |
if ( empty( $_POST['_wp_http_referer'] ) ) { |
| 266 |
return $input; |
| 267 |
} |
| 268 |
if(isset($_POST[''.WPPIZZA_SLUG.'_'.$this->settings_page.''])){ |
| 269 |
|
| 270 |
$options[$this->settings_page]['add_to_cart_on_title_click'] = !empty($input[$this->settings_page]['add_to_cart_on_title_click']) ? true : false; |
| 271 |
$options[$this->settings_page]['jquery_fb_add_to_cart'] = !empty($input[$this->settings_page]['jquery_fb_add_to_cart']) ? true : false; |
| 272 |
$options[$this->settings_page]['jquery_fb_add_to_cart_ms']=absint($input[$this->settings_page]['jquery_fb_add_to_cart_ms']); |
| 273 |
$options[$this->settings_page]['suppress_loop_headers'] = !empty($input[$this->settings_page]['suppress_loop_headers']) ? true : false; |
| 274 |
$options[$this->settings_page]['category_accordion'] = !empty($input[$this->settings_page]['category_accordion']) ? true : false; |
| 275 |
$options[$this->settings_page]['category_accordion_style']=wppizza_validate_string($input[$this->settings_page]['category_accordion_style']); |
| 276 |
$options[$this->settings_page]['hide_cart_icon'] = !empty($input[$this->settings_page]['hide_cart_icon']) ? true : false; |
| 277 |
$options[$this->settings_page]['hide_single_pricetier'] = !empty($input[$this->settings_page]['hide_single_pricetier']) ? true : false; |
| 278 |
$options[$this->settings_page]['prettify_js_alerts'] = !empty($input[$this->settings_page]['prettify_js_alerts']) ? true : false; |
| 279 |
|
| 280 |
|
| 281 |
/* force suppress_loop_headers to be off if using accordion */ |
| 282 |
if($options[$this->settings_page]['category_accordion']) { |
| 283 |
$options[$this->settings_page]['suppress_loop_headers'] = false; |
| 284 |
} |
| 285 |
} |
| 286 |
|
| 287 |
return $options; |
| 288 |
} |
| 289 |
} |
| 290 |
/*************************************************************** |
| 291 |
* |
| 292 |
* [ini] |
| 293 |
* |
| 294 |
***************************************************************/ |
| 295 |
$WPPIZZA_MODULE_LAYOUT_MISCELLANEOUS = new WPPIZZA_MODULE_LAYOUT_MISCELLANEOUS(); |
| 296 |
?> |