| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPPIZZA_MODULE_ALLERGENS Class |
| 4 |
* |
| 5 |
* @package WPPIZZA |
| 6 |
* @subpackage WPPIZZA_MODULE_ALLERGENS |
| 7 |
* @copyright Copyright (c) 2015, Oliver Bach |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 3.12.14 |
| 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_ALLERGENS{ |
| 24 |
|
| 25 |
private $settings_page = 'additives';/* which admin subpage (identified there by this->class_key) are we adding this to */ |
| 26 |
|
| 27 |
|
| 28 |
private $section_key = 'allergens';/* 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'), 10, 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 |
/**metaboxes sizes/prices - priority same as submenu page **/ |
| 45 |
add_filter('wppizza_filter_admin_metaboxes', array( $this, 'wppizza_filter_admin_add_metaboxes'), 60, 4); |
| 46 |
add_filter('wppizza_filter_admin_save_metaboxes',array( $this, 'wppizza_filter_admin_save_metaboxes'), 10, 3); |
| 47 |
/** admin ajax **/ |
| 48 |
add_action('wppizza_ajax_admin_'.$this->settings_page.'', array( $this, 'admin_ajax')); |
| 49 |
} |
| 50 |
} |
| 51 |
/******************************************************************************************************************************************************* |
| 52 |
* |
| 53 |
* [admin ajax] |
| 54 |
* |
| 55 |
********************************************************************************************************************************************************/ |
| 56 |
function admin_ajax($wppizza_options){ |
| 57 |
|
| 58 |
//need right caps for access |
| 59 |
if( !current_user_can('wppizza_cap_'.$this->settings_page.'')){ |
| 60 |
echo '<div class="wppizza-highlight">'.__('Access Denied', 'wppizza-admin').' ['.$this->section_key.']</div>'; |
| 61 |
exit(); |
| 62 |
} |
| 63 |
|
| 64 |
/***************************************************** |
| 65 |
[adding new allergen] |
| 66 |
*****************************************************/ |
| 67 |
if($_POST['vars']['field']==$this->section_key && isset($_POST['vars']['setKeys']) ){ |
| 68 |
|
| 69 |
/**get next highest key available**/ |
| 70 |
$nextKey=0; |
| 71 |
if(isset($_POST['vars']['setKeys']) && is_array($_POST['vars']['setKeys'])){ |
| 72 |
$currentKeys=array(); |
| 73 |
foreach($_POST['vars']['setKeys'] as $key_exists){ |
| 74 |
$currentKeys[$key_exists['value']]=$key_exists['value']; |
| 75 |
} |
| 76 |
$highestKey=max($currentKeys); |
| 77 |
$nextKey=$highestKey+1; |
| 78 |
} |
| 79 |
|
| 80 |
/** create some (albeit empty) default values */ |
| 81 |
$default_values['sort'] = ''; |
| 82 |
$default_values['name'] = ''; |
| 83 |
$default_values['icon'] = ''; |
| 84 |
|
| 85 |
|
| 86 |
$output = $this->wppizza_admin_section_options($_POST['vars']['field'], $nextKey, $default_values); |
| 87 |
|
| 88 |
print"".$output.""; |
| 89 |
exit(); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
/******************************************************************************************************************************************************* |
| 95 |
* |
| 96 |
* |
| 97 |
* |
| 98 |
* [frontend filters] |
| 99 |
* |
| 100 |
* |
| 101 |
* |
| 102 |
********************************************************************************************************************************************************/ |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
/******************************************************************************************************************************************************* |
| 107 |
* |
| 108 |
* |
| 109 |
* |
| 110 |
* [add admin page options] |
| 111 |
* |
| 112 |
* |
| 113 |
* |
| 114 |
********************************************************************************************************************************************************/ |
| 115 |
/********************************************************* |
| 116 |
* |
| 117 |
* [add metaboxes] |
| 118 |
* @since 3.0 |
| 119 |
* |
| 120 |
*********************************************************/ |
| 121 |
function wppizza_filter_admin_add_metaboxes($wppizza_meta_box, $meta_values, $meal_sizes, $wppizza_options){ |
| 122 |
|
| 123 |
if(!empty($wppizza_options[$this->section_key])){ |
| 124 |
/*->*** which allergens in item ***/ |
| 125 |
$wppizza_meta_box[$this->section_key]=''; |
| 126 |
$wppizza_meta_box[$this->section_key].="<div class='".WPPIZZA_SLUG."_option_meta ".WPPIZZA_SLUG."_option_meta_".$this->section_key."'>"; |
| 127 |
|
| 128 |
$wppizza_meta_box[$this->section_key].="<label class='".WPPIZZA_SLUG."-meta-label'>".__('Allergens', 'wppizza-admin').": </label>"; |
| 129 |
|
| 130 |
|
| 131 |
$wppizza_meta_box[$this->section_key].="<div>";/* wrapper div needed to make css->display:flex work here */ |
| 132 |
|
| 133 |
asort($wppizza_options[$this->section_key]);//sort but keep index |
| 134 |
|
| 135 |
/* |
| 136 |
if we perhaps ever want to use chosen.js instead of the below buttons (but must be enabled in subpage.post and admin.common js too if we do) |
| 137 |
Note:saving of values would need to be checked still |
| 138 |
*/ |
| 139 |
// $wppizza_meta_box[$this->section_key] .= '<select id="'.WPPIZZA_PREFIX.'-meta-'.$this->section_key.'" name="'.WPPIZZA_SLUG.'['.$this->section_key.']" class="'.WPPIZZA_PREFIX.'-meta-'.$this->section_key.'" multiple="multiple" >'; |
| 140 |
// foreach($wppizza_options[$this->section_key] as $key=>$value){ |
| 141 |
// $wppizza_meta_box[$this->section_key] .= '<option value="'.$key.'" '.selected(in_array($key, $meta_values[$this->section_key]), true ,false).' >'.$value['name'].'</option>'; |
| 142 |
// } |
| 143 |
// $wppizza_meta_box[$this->section_key].="</select>"; |
| 144 |
|
| 145 |
|
| 146 |
foreach($wppizza_options[$this->section_key] as $key=>$value){ |
| 147 |
$wppizza_meta_box[$this->section_key].="<label class='button'>"; |
| 148 |
$wppizza_meta_box[$this->section_key].="<input name='".WPPIZZA_SLUG."[".$this->section_key."][".$key."]' size='5' type='checkbox' ". checked((isset($meta_values[$this->section_key]) && in_array($key,$meta_values[$this->section_key])),true,false)." value='".$key."' /> ".$value['name'].""; |
| 149 |
$wppizza_meta_box[$this->section_key].="</label>"; |
| 150 |
} |
| 151 |
|
| 152 |
$wppizza_meta_box[$this->section_key].="</div>"; |
| 153 |
|
| 154 |
$wppizza_meta_box[$this->section_key].="</div>"; |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
return $wppizza_meta_box; |
| 159 |
} |
| 160 |
|
| 161 |
/********************************************************* |
| 162 |
* |
| 163 |
* [save metaboxes values] |
| 164 |
* @since 3.0 |
| 165 |
* |
| 166 |
*********************************************************/ |
| 167 |
function wppizza_filter_admin_save_metaboxes($itemMeta, $item_id, $wppizza_options){ |
| 168 |
|
| 169 |
//**allergens**// |
| 170 |
$itemMeta[$this->section_key]=array(); |
| 171 |
if(isset($_POST[WPPIZZA_SLUG][$this->section_key])){ |
| 172 |
foreach($_POST[WPPIZZA_SLUG][$this->section_key] as $key=>$val){ |
| 173 |
$itemMeta[$this->section_key][$key] = (int)$_POST[WPPIZZA_SLUG][$this->section_key][$key]; |
| 174 |
}} |
| 175 |
|
| 176 |
return $itemMeta; |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
/*------------------------------------------------------------------------------ |
| 181 |
# |
| 182 |
# |
| 183 |
# [settings page] |
| 184 |
# |
| 185 |
# |
| 186 |
------------------------------------------------------------------------------*/ |
| 187 |
|
| 188 |
/*------------------------------------------------------------------------------ |
| 189 |
# [settings section - setting page] |
| 190 |
# @since 3.0 |
| 191 |
# @return array() |
| 192 |
------------------------------------------------------------------------------*/ |
| 193 |
function admin_options_settings($settings, $sections, $fields, $inputs, $help){ |
| 194 |
|
| 195 |
/*section*/ |
| 196 |
if($sections){ |
| 197 |
$settings['sections'][$this->section_key] = __('Allergens', 'wppizza-admin'); |
| 198 |
} |
| 199 |
/*help*/ |
| 200 |
if($help){ |
| 201 |
$settings['help'][$this->section_key][] = array( |
| 202 |
'label'=>__('Manage Allergens', 'wppizza-admin'), |
| 203 |
'description'=>array( |
| 204 |
__('Some meals or beverages may - or may not - contain allergens.', 'wppizza-admin'), |
| 205 |
__('Add any allergens here and select them at any meal / beverage that contains these allergens, or indeed distinctly indicate any menu item that does not contain an allergen.', 'wppizza-admin'), |
| 206 |
__('Allergens will be listed before additives.', 'wppizza-admin'), |
| 207 |
__('If you wish you can additionally add an icon in front of the allergens in the list of additives/allergens added to the footnotes on each page.', 'wppizza-admin'), |
| 208 |
__('If "icon in title" is enabled, associated icons will also be displayed in the title of the menu item instead of its textual ident.', 'wppizza-admin'), |
| 209 |
__('By default, allergens will be sorted alphabetically.', 'wppizza-admin'), |
| 210 |
__('However, you can use the "sort" field to customise the sortorder. If you do, your choosen sort id will be used to identify the allergens in the frontend so you want to make sure to have unique identifiers/sort id\'s.', 'wppizza-admin'), |
| 211 |
) |
| 212 |
); |
| 213 |
|
| 214 |
} |
| 215 |
/*fields*/ |
| 216 |
if($fields){ |
| 217 |
$field = $this->section_key; |
| 218 |
$settings['fields'][$this->section_key][$field] = array( '', array( |
| 219 |
'value_key'=>$field, |
| 220 |
'option_key'=>$this->settings_page, |
| 221 |
'label'=> '', |
| 222 |
'description'=>array() |
| 223 |
)); |
| 224 |
} |
| 225 |
|
| 226 |
|
| 227 |
return $settings; |
| 228 |
} |
| 229 |
/*------------------------------------------------------------------------------ |
| 230 |
# [output option fields - setting page] |
| 231 |
# @since 3.0 |
| 232 |
# @return array() |
| 233 |
------------------------------------------------------------------------------*/ |
| 234 |
function admin_options_fields_settings($wppizza_options, $options_key, $field, $label, $description){ |
| 235 |
|
| 236 |
if($field==$this->section_key){ |
| 237 |
|
| 238 |
echo"<div id='wppizza_".$field."_options' class='wppizza_admin_options'>";/*new sizes will be appended to this div's id by ajax*/ |
| 239 |
|
| 240 |
if(!empty($wppizza_options[$field])){ |
| 241 |
asort($wppizza_options[$field]);//sort but keep index |
| 242 |
/* get allergens that are in use */ |
| 243 |
$allergens_in_use = wppizza_options_in_use($field); |
| 244 |
foreach($wppizza_options[$field] as $key=>$values){ |
| 245 |
echo"".$this->wppizza_admin_section_options($field, $key, $values, $allergens_in_use[$field]); |
| 246 |
} |
| 247 |
} |
| 248 |
echo"</div>"; |
| 249 |
/** add new button **/ |
| 250 |
echo"<div id='wppizza-".$field."-add' class='wppizza_admin_add'>"; |
| 251 |
echo "<input type='button' id='wppizza_add_".$field."' class='button' value='".__('add allergen', 'wppizza-admin')."' />"; |
| 252 |
echo"</div>"; |
| 253 |
} |
| 254 |
} |
| 255 |
|
| 256 |
|
| 257 |
/** |
| 258 |
[available sizes of meal items or add new via ajax] |
| 259 |
**/ |
| 260 |
private function wppizza_admin_section_options($field, $key, $values=null, $allergens_in_use=null){ |
| 261 |
|
| 262 |
$str=''; |
| 263 |
|
| 264 |
$str.="<div class='wppizza_option wppizza_".$this->section_key."_option'>"; |
| 265 |
|
| 266 |
/* |
| 267 |
for easy checking for existing keys when adding new |
| 268 |
*/ |
| 269 |
$str.="<input id='wppizza_".$field."_".$key."' class='wppizza-getkey' name='wppizza-getkey[".$key."]' type='hidden' value='".$key."'>"; |
| 270 |
|
| 271 |
$str.="<span class='wppizza_label_50'>"; |
| 272 |
$str.="ID: ".$key.""; |
| 273 |
$str.="</span>"; |
| 274 |
|
| 275 |
$str.="<span>"; |
| 276 |
$str.="".__('sort', 'wppizza-admin')."/".__('ident', 'wppizza-admin').":"; |
| 277 |
$str.="<input name='".WPPIZZA_SLUG."[".$field."][".$key."][sort]' size='3' type='text' value='". $values['sort'] ."' placeholder=''/>"; |
| 278 |
$str.="</span>"; |
| 279 |
|
| 280 |
$str.="<span>"; |
| 281 |
$str.="".__('name', 'wppizza-admin').":"; |
| 282 |
$str.="<input name='".WPPIZZA_SLUG."[".$field."][".$key."][name]' size='30' type='text' value='". $values['name'] ."' placeholder=''/>"; |
| 283 |
$str.="</span>"; |
| 284 |
|
| 285 |
$str.="<span>"; |
| 286 |
$str.="".__('icon', 'wppizza-admin').":"; |
| 287 |
|
| 288 |
|
| 289 |
$str.="<select name='".WPPIZZA_SLUG."[".$field."][".$key."][icon]'>"; |
| 290 |
/* default option */ |
| 291 |
$str.="<option value=''> === ".__('No Icon', 'wppizza-admin')." === </option>"; |
| 292 |
|
| 293 |
/* icons etc */ |
| 294 |
$icon_options = array(); |
| 295 |
|
| 296 |
$icon_options['allergens'] = array( |
| 297 |
'label' => __('Allergens', 'wppizza-admin') , |
| 298 |
'items' => array( |
| 299 |
'gluten' => __('Gluten', 'wppizza-admin'), |
| 300 |
'lupin' => __('Lupin', 'wppizza-admin'), |
| 301 |
'celery' => __('Celery', 'wppizza-admin'), |
| 302 |
'crustaceans' => __('Crustaceans', 'wppizza-admin'), |
| 303 |
'milk' => __('Milk/Lactose', 'wppizza-admin'), |
| 304 |
'sulphites' => __('Sulphites', 'wppizza-admin'), |
| 305 |
'sesame' => __('Sesame', 'wppizza-admin'), |
| 306 |
'molluscs' => __('Molluscs', 'wppizza-admin'), |
| 307 |
'mustard' => __('Mustard', 'wppizza-admin'), |
| 308 |
'nuts' => __('Nuts', 'wppizza-admin'), |
| 309 |
'eggs' => __('Eggs', 'wppizza-admin'), |
| 310 |
'fish' => __('Fish', 'wppizza-admin'), |
| 311 |
'soybeans' => __('Soybeans', 'wppizza-admin'), |
| 312 |
'peanuts' => __('Peanuts', 'wppizza-admin'), |
| 313 |
) |
| 314 |
); |
| 315 |
|
| 316 |
$icon_options['no_allergens'] = array( |
| 317 |
'label' => __('Excl. Allergens', 'wppizza-admin') , |
| 318 |
'items' => array( |
| 319 |
'no_gluten' => __('No Gluten', 'wppizza-admin'), |
| 320 |
'no_lupin' => __('No Lupin', 'wppizza-admin'), |
| 321 |
'no_celery' => __('No Celery', 'wppizza-admin'), |
| 322 |
'no_crustaceans' => __('No Crustaceans', 'wppizza-admin'), |
| 323 |
'no_milk' => __('No Milk/Lactose', 'wppizza-admin'), |
| 324 |
'no_sulphites' => __('No Sulphites', 'wppizza-admin'), |
| 325 |
'no_sesame' => __('No Sesame', 'wppizza-admin'), |
| 326 |
'no_molluscs' => __('No Molluscs', 'wppizza-admin'), |
| 327 |
'no_mustard' => __('No Mustard', 'wppizza-admin'), |
| 328 |
'no_nuts' => __('No Nuts', 'wppizza-admin'), |
| 329 |
'no_eggs' => __('No Eggs', 'wppizza-admin'), |
| 330 |
'no_fish' => __('No Fish', 'wppizza-admin'), |
| 331 |
'no_soybeans' => __('No Soybeans', 'wppizza-admin'), |
| 332 |
'no_peanuts' => __('No Peanuts', 'wppizza-admin'), |
| 333 |
) |
| 334 |
); |
| 335 |
|
| 336 |
|
| 337 |
foreach($icon_options as $ident => $aGroup){ |
| 338 |
$str.="<optgroup label=' -- ".$aGroup['label']." -- '>"; |
| 339 |
|
| 340 |
//sort if it's not a "spice" group |
| 341 |
if(!in_array($ident , array('spice') )){ |
| 342 |
asort($aGroup['items']); |
| 343 |
} |
| 344 |
|
| 345 |
foreach($aGroup['items'] as $k => $v ) { |
| 346 |
$str.="<option value='".$k."' ".selected($values['icon'], $k ,false)." > ".$v." </option>"; |
| 347 |
} |
| 348 |
|
| 349 |
} |
| 350 |
|
| 351 |
$str.="</select>"; |
| 352 |
|
| 353 |
$str.="</span>"; |
| 354 |
|
| 355 |
/* |
| 356 |
show icon in title too as well as in legend |
| 357 |
*/ |
| 358 |
$str.="<span>"; |
| 359 |
$str.="<label>"; |
| 360 |
$str.="".__('icon in title', 'wppizza-admin').":"; |
| 361 |
$str.="<input name='".WPPIZZA_SLUG."[".$field."][".$key."][iconintitle]' type='checkbox' value='1' ".checked(!empty($values['iconintitle']),true,false)." />"; |
| 362 |
$str.="</label>"; |
| 363 |
$str.="</span>"; |
| 364 |
|
| 365 |
|
| 366 |
$str.="<span class='".WPPIZZA_SLUG."-option-inuse ".WPPIZZA_SLUG."-".$field."-inuse'>"; |
| 367 |
if(!isset($allergens_in_use[$key])){ |
| 368 |
$str.="<a href='javascript:void(0);' class='".WPPIZZA_SLUG."-delete ".$field." ".WPPIZZA_SLUG."-dashicons dashicons-trash' title='".__('delete', 'wppizza-admin')."'></a>"; |
| 369 |
}else{ |
| 370 |
$str.="".__('in use', 'wppizza-admin').""; |
| 371 |
} |
| 372 |
$str.="</span>"; |
| 373 |
|
| 374 |
$str.="</div>"; |
| 375 |
|
| 376 |
return $str; |
| 377 |
} |
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
/**************************************************************** |
| 382 |
* |
| 383 |
* [insert default option on install] |
| 384 |
* $parameter $options array() | filter passing on filtered options |
| 385 |
* @since 3.0 |
| 386 |
* @return array() |
| 387 |
* |
| 388 |
****************************************************************/ |
| 389 |
function options_default($options){ |
| 390 |
|
| 391 |
/* |
| 392 |
default allergens |
| 393 |
*/ |
| 394 |
$options[$this->section_key] = array( |
| 395 |
0=>array( 'sort'=>'A', 'name'=>wppizza_textdomain('Gluten', 'wppizza'), 'icon' => 'gluten'), |
| 396 |
1=>array( 'sort'=>'A*', 'name'=>wppizza_textdomain('Gluten Free', 'wppizza'), 'icon' => 'no_gluten'), |
| 397 |
2=>array( 'sort'=>'B', 'name'=>wppizza_textdomain('Crustaceans', 'wppizza'), 'icon' => 'crustaceans'), |
| 398 |
3=>array( 'sort'=>'B*', 'name'=>wppizza_textdomain('Crustacean Free', 'wppizza'), 'icon' => 'no_crustaceans'), |
| 399 |
4=>array( 'sort'=>'C', 'name'=>wppizza_textdomain('Eggs', 'wppizza'), 'icon' => 'eggs'), |
| 400 |
5=>array( 'sort'=>'C*', 'name'=>wppizza_textdomain('Egg Free', 'wppizza'), 'icon' => 'no_eggs'), |
| 401 |
6=>array( 'sort'=>'D', 'name'=>wppizza_textdomain('Fish', 'wppizza'), 'icon' => 'fish'), |
| 402 |
7=>array( 'sort'=>'D*', 'name'=>wppizza_textdomain('Fish Free', 'wppizza'), 'icon' => 'no_fish'), |
| 403 |
8=>array( 'sort'=>'E', 'name'=>wppizza_textdomain('Peanuts', 'wppizza'), 'icon' => 'peanuts'), |
| 404 |
9=>array( 'sort'=>'E*', 'name'=>wppizza_textdomain('Peanut Free', 'wppizza'), 'icon' => 'no_peanuts'), |
| 405 |
10=>array( 'sort'=>'F', 'name'=>wppizza_textdomain('Soybeans', 'wppizza'), 'icon' => 'soybeans'), |
| 406 |
11=>array( 'sort'=>'F*', 'name'=>wppizza_textdomain('Soybean Free', 'wppizza'), 'icon' => 'no_soybeans'), |
| 407 |
12=>array( 'sort'=>'G', 'name'=>wppizza_textdomain('Milk / Lactose', 'wppizza'), 'icon' => 'milk'), |
| 408 |
13=>array( 'sort'=>'G*', 'name'=>wppizza_textdomain('Milk / Lactose Free', 'wppizza'), 'icon' => 'no_milk'), |
| 409 |
14=>array( 'sort'=>'H', 'name'=>wppizza_textdomain('Nuts', 'wppizza'), 'icon' => 'nuts'), |
| 410 |
15=>array( 'sort'=>'H*', 'name'=>wppizza_textdomain('Free from Nuts', 'wppizza'), 'icon' => 'no_nuts'), |
| 411 |
16=>array( 'sort'=>'L', 'name'=>wppizza_textdomain('Celery', 'wppizza'), 'icon' => 'celery'), |
| 412 |
17=>array( 'sort'=>'L*', 'name'=>wppizza_textdomain('Free from Celery', 'wppizza'), 'icon' => 'no_celery'), |
| 413 |
18=>array( 'sort'=>'M', 'name'=>wppizza_textdomain('Mustard', 'wppizza'), 'icon' => 'mustard'), |
| 414 |
19=>array( 'sort'=>'M*', 'name'=>wppizza_textdomain('No Mustard', 'wppizza'), 'icon' => 'no_mustard'), |
| 415 |
20=>array( 'sort'=>'N', 'name'=>wppizza_textdomain('Sesame', 'wppizza'), 'icon' => 'sesame'), |
| 416 |
21=>array( 'sort'=>'N*', 'name'=>wppizza_textdomain('Sesame Free', 'wppizza'), 'icon' => 'no_sesame'), |
| 417 |
22=>array( 'sort'=>'O', 'name'=>wppizza_textdomain('Sulphites', 'wppizza'), 'icon' => 'sulphites'), |
| 418 |
23=>array( 'sort'=>'O*', 'name'=>wppizza_textdomain('Sulphite Free', 'wppizza'), 'icon' => 'no_sulphites'), |
| 419 |
24=>array( 'sort'=>'P', 'name'=>wppizza_textdomain('Lupin', 'wppizza'), 'icon' => 'lupin'), |
| 420 |
25=>array( 'sort'=>'P*', 'name'=>wppizza_textdomain('Lupin Free', 'wppizza'), 'icon' => 'no_lupin'), |
| 421 |
26=>array( 'sort'=>'R', 'name'=>wppizza_textdomain('Molluscs', 'wppizza'), 'icon' => 'molluscs'), |
| 422 |
27=>array( 'sort'=>'R*', 'name'=>wppizza_textdomain('No Molluscs', 'wppizza'), 'icon' => 'no_molluscs'), |
| 423 |
); |
| 424 |
/* |
| 425 |
allow filtering |
| 426 |
*/ |
| 427 |
$options[$this->section_key] = apply_filters('wppizza_filter_install_default_allergens', $options[$this->section_key]); |
| 428 |
|
| 429 |
return $options; |
| 430 |
} |
| 431 |
|
| 432 |
/*------------------------------------------------------------------------------ |
| 433 |
# [validate options on save/update] |
| 434 |
# |
| 435 |
# @since 3.0 |
| 436 |
# @return array() |
| 437 |
------------------------------------------------------------------------------*/ |
| 438 |
function options_validate($options, $input){ |
| 439 |
/**make sure we get the full array on install/update**/ |
| 440 |
if ( empty( $_POST['_wp_http_referer'] ) ) { |
| 441 |
return $input; |
| 442 |
} |
| 443 |
/******************************** |
| 444 |
* [validate] |
| 445 |
********************************/ |
| 446 |
if(isset($_POST[''.WPPIZZA_SLUG.'_'.$this->settings_page.''])){ |
| 447 |
|
| 448 |
$options[$this->section_key] = array();//initialize as empty array |
| 449 |
if(!empty($input[$this->section_key])){ |
| 450 |
|
| 451 |
foreach($input[$this->section_key] as $key=>$values){ |
| 452 |
|
| 453 |
if(trim($values['name'])!=''){ |
| 454 |
|
| 455 |
$sort = ($values['sort']!='' ) ? preg_replace("/[^a-zA-Z0-9\-_+*:]/","", $values['sort'] ) : ''; |
| 456 |
|
| 457 |
$options[$this->section_key][$key] = array( |
| 458 |
'sort' => $sort, |
| 459 |
'name' => wppizza_validate_string($values['name']), |
| 460 |
'icon' => wppizza_validate_string($values['icon']), |
| 461 |
'iconintitle' => (!empty($values['iconintitle']) ? true : false ) , |
| 462 |
); |
| 463 |
|
| 464 |
} |
| 465 |
|
| 466 |
} |
| 467 |
|
| 468 |
} |
| 469 |
|
| 470 |
/* |
| 471 |
in case someone does something really daft (editing post pages and sizes at the same time in 2 different windows).... |
| 472 |
make sure we do not delete something that really should be there. |
| 473 |
*/ |
| 474 |
global $wppizza_options; |
| 475 |
|
| 476 |
$allergens_in_use = wppizza_options_in_use($this->section_key); |
| 477 |
|
| 478 |
if(!empty($allergens_in_use[$this->section_key])){ |
| 479 |
foreach($allergens_in_use[$this->section_key] as $allergen_key){ |
| 480 |
|
| 481 |
if(!isset($options[$this->section_key][$allergen_key])){ |
| 482 |
$options[$this->section_key][$allergen_key] = $wppizza_options[$this->section_key][$allergen_key]; |
| 483 |
} |
| 484 |
|
| 485 |
}} |
| 486 |
} |
| 487 |
|
| 488 |
return $options; |
| 489 |
} |
| 490 |
} |
| 491 |
/*************************************************************** |
| 492 |
* |
| 493 |
* [ini] |
| 494 |
* |
| 495 |
***************************************************************/ |
| 496 |
$WPPIZZA_MODULE_ALLERGENS = new WPPIZZA_MODULE_ALLERGENS(); |
| 497 |
?> |