PluginProbe
WPPizza – A Restaurant Plugin / 3.20
WPPizza – A Restaurant Plugin v3.20
trunk 2.16.11.28 3.19 3.19.1 3.19.2 3.19.3 3.19.4 3.19.5 3.19.6 3.19.7 3.19.7.1 3.19.7.2 3.19.7.3 3.19.7.4 3.19.8 3.19.8.1 3.19.8.2 3.19.8.3 3.19.9 3.20 3.20.1
wppizza / classes / modules / mod.tools.miscellaneous.various.php

mod.tools.miscellaneous.various.php in WPPizza – A Restaurant Plugin 3.20, at classes/modules/mod.tools.miscellaneous.various.php

502 lines 20.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPPIZZA_MODULE_TOOLS_MISCELLANEOUS Class
4 *
5 * @package WPPIZZA
6 * @subpackage WPPIZZA_MODULE_TOOLS_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_TOOLS_MISCELLANEOUS{
24
25 private $settings_page = 'tools';/* which admin subpage (identified there by this->class_key) are we adding this to */
26 private $tab_key = 'miscellaneous';/* must be unique within this admin page*/
27 private $section_key = 'various';
28
29 function __construct() {
30 /**********************************************************
31 [add settings to admin]
32 ***********************************************************/
33 if(is_admin()){
34 /*** add to a specific tab ***/
35 add_filter('wppizza_filter_admin_tabs_'.$this->settings_page.'', array($this, 'admin_tabs'), 10);
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 /**add text header*/
45 // //add_action('wppizza_settings_sections_header_'.$this->settings_page.'', array( $this, 'sections_header'), 10, 2 );
46 }
47 /* disable email sending if set */
48 add_filter('wppizza_filter_send_emails', array( $this, 'filter_send_emails'), 10);
49
50 /*** force opening of shop for specific user id ip address **/
51 add_filter( 'wppizza_shop_is_open', array( $this, 'force_shop_open_for_user'), 1000);
52
53 }
54
55 /*******************************************************************************************************************************************************
56 *
57 *
58 *
59 * [frontend filters]
60 *
61 *
62 *
63 ********************************************************************************************************************************************************/
64 /*
65 disable email sending if set
66 */
67 function filter_send_emails($bool){
68 global $wppizza_options;
69 $bool = empty($wppizza_options[$this->settings_page]['disable_emails']) ? true : false;
70 return $bool;
71 }
72
73 /*
74 keep shop open for user id / ipaddress
75 @since 3.12.4
76 */
77 function force_shop_open_for_user($bool){
78
79 global $wppizza_options;
80 /*
81 as-is, if always_open_for_user is empty or user is not logged in (i.e user id == 0)
82 */
83 if(empty($wppizza_options[$this->settings_page]['always_open_for_user']) || empty(get_current_user_id()) ){
84 return $bool;
85 }
86 /*
87 check if always_open_for_user applies
88 */
89 /* explode comma separated str to array */
90 $always_open_for_user = explode(',', $wppizza_options[$this->settings_page]['always_open_for_user']);
91 if( in_array(get_current_user_id(), $always_open_for_user) || in_array($_SERVER['REMOTE_ADDR'], $always_open_for_user)){
92 $bool = true;
93 }
94
95 /* or filter as you please, provided 'always_open_for_user' is not empty */
96 $bool = apply_filters('wppizza_filter_always_open_for_user', $bool);
97
98 //override or as is
99 return $bool;
100 }
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 [add section to a particular tab]
122 *********************************************************/
123 function admin_tabs($tabs){
124 $tabs['tab'][$this->tab_key]['sections'][] = $this->section_key;
125 return $tabs;
126 }
127 /*------------------------------------------------------------------------------
128 # [settings section - setting page]
129 # @since 3.0
130 # @return array()
131 ------------------------------------------------------------------------------*/
132 function admin_options_settings($settings, $sections, $fields, $inputs, $help){
133
134 /*section*/
135 if($sections){
136 $settings['sections'][$this->section_key] = __('Miscellaneous', 'wppizza-admin');
137 }
138
139 /*help*/
140 if($help){
141 $settings['help'][$this->section_key][] = array(
142 'label'=>__('Miscellaneous', 'wppizza-admin'),
143 'description'=>array(
144 __('Please adjust settings as appropriate according to the information provided next to each individual option.', 'wppizza-admin')
145 )
146 );
147 }
148
149 /*fields*/
150 if($fields){
151
152 $field = 'disable_emails';
153 $settings['fields'][$this->section_key][$field] = array(__('Disable email sending', 'wppizza-admin') , array(
154 'value_key'=>$field,
155 'option_key'=>$this->settings_page,
156 'label'=>__('Check this box to stop sending emails. If you want to test things without actually sending any emails', 'wppizza-admin'),
157 'description'=>array()
158 ));
159
160 $field = 'always_open_for_user';
161 $settings['fields'][$this->section_key][$field] = array(__('Always open shop for UserID', 'wppizza-admin') , array(
162 'value_key'=>$field,
163 'option_key'=>$this->settings_page,
164 'label'=>__('Enter a user defined by their UserID [Integer!] or IP-Address for whom the shop should always be open. (Separate by comma for multiple UserIDs / IP-Addresses. User must be logged in. )', 'wppizza-admin'),
165 'description'=>array(
166 __('Useful if an administrator wants to test things, without allowing regular users to order outside opening hours.', 'wppizza-admin'),
167 )
168 ));
169
170 $field = 'continue_order_on_mail_error';
171 $settings['fields'][$this->section_key][$field] = array( __('Continue order on mail error', 'wppizza-admin'), array(
172 'value_key'=>$field,
173 'option_key'=>$this->settings_page,
174 /* Translators: 1: WPPizza Name as defined by constant */
175 'label'=>sprintf(__('Do not mark an order as "FAILED" if there are errors sending emails to the *shops* email address as set in "%s -> Order Settings" ["Prepaid" i.e Credit Card etc orders only]', 'wppizza-admin'), WPPIZZA_NAME),
176 'description'=>array(
177 '<span class="wppizza-highlight">'.__('If you receive notifications at your Wordpress admin email address, that emails of orders to the shop failed, enable this option to still have those orders appear in your "Order History".','wppizza-admin').'</span>',
178 '<span class="wppizza-highlight">'.__('However, you would be well advised to only temporarily enable this option while the underlying email problems are being fixed as per the error messages received.','wppizza-admin').'</span>',
179 /* Translators: 1: WPPizza Name as defined by constant */
180 '<span>'.sprintf(__('Details of the error encountered can also be found in the "logs/" directory of the %s plugin as well as in your Wordpress/Server debug/error log', 'wppizza-admin'), WPPIZZA_NAME).'</span>',
181 )
182 ));
183
184 $field = 'empty_category_and_items';
185 $settings['fields'][$this->section_key][$field] = array(__('Delete Categories/Items/Tags/Images', 'wppizza-admin') , array(
186 'value_key'=>$field,
187 'option_key'=>$this->settings_page,
188 'label'=>__('Delete ALL Categories, Items and Tags','wppizza-admin'),
189 'description'=>array(
190 '<span class="wppizza-highlight">'.__('use with care','wppizza-admin').'</span>',
191 '<span class="wppizza-highlight">'.__('if you select "delete images too", all featured images used for any menu items will be deleted too','wppizza-admin').'</span>',
192 '<span class="wppizza-highlight">'.__('if you use these images elsewhere, you should not select this !','wppizza-admin').'</span>'
193 )
194 ));
195
196 $field = 'debug';
197 $settings['fields'][$this->section_key][$field] = array(__('Enable debug', 'wppizza-admin') , array(
198 'value_key'=>$field,
199 'option_key'=>$this->settings_page,
200 'label'=>__('Set your debug configuration in your wp-config.php like so:','wppizza-admin'),
201 'description'=>array(
202 '<pre>define("WP_DEBUG", true);<br />define("WP_DEBUG_LOG", true);<br />define("WP_DEBUG_DISPLAY", false);/*this should NEVER be true for production sites*/</pre>',
203 __('REPLACING your current wp-config.php debug settings if different','wppizza-admin'),
204 '<b>'.__('Make sure these constants are added/set BEFORE /* That\'s all, stop editing! Happy blogging. */','wppizza-admin').'</b>',
205 '<br>'.__('your debug log will be located at wp-content/debug.log','wppizza-admin'),
206 )
207 ));
208
209 $field = 'category_repair';
210 $settings['fields'][$this->section_key][$field] = array(__('Repair categories', 'wppizza-admin') , array(
211 'value_key'=>$field,
212 'option_key'=>$this->settings_page,
213 'label'=>__('Enable and save to repair', 'wppizza-admin'),
214 'description'=>array(
215 __('There exists an (as yet) unknown sequence of events related to saving/adding/editing/deleting categories of this plugin that may result in the last category being repeated when using the category=!all shortcode attribute and/or not all categories showing up in the admin of the plugin.', 'wppizza-admin'),
216 __('If this should be the case, you can try repairing this by checking the box above and saving once.', 'wppizza-admin'),
217 '<span class="wppizza-highlight">'.__('If you use this function, categories will be re-set using default alphabetical sort order, so please ensure your category order is still as required as you might have to re-sort - i.e drag and drop - categories again.', 'wppizza-admin').'</span>',
218 __('In case this does not solve the issue, please contact me, letting me know anything you did before this issue occured if possible.', 'wppizza-admin')
219 )
220 ));
221
222 $field = 'default_templates_reset';
223 $settings['fields'][$this->section_key][$field] = array(__('Reset default templates', 'wppizza-admin') , array(
224 'value_key'=>$field,
225 'option_key'=>$this->settings_page,
226 'label'=>__('Enable and save to reset the *default* email and print templates', 'wppizza-admin'),
227 'description'=>array(
228 '<span class="wppizza-highlight">'.__('Note: any additional templates added will remain unaffected. Current css declarations will be preserved.', 'wppizza-admin').'</span>',
229 )
230 ));
231
232 $field = 'compat_legacy_checkout';
233 $settings['fields'][$this->section_key][$field] = array(__('Legacy type checkout', 'wppizza-admin') , array(
234 'value_key'=>$field,
235 'option_key'=>$this->settings_page,
236 'label'=>__('Use full orderpage reload on payment gateway / delivery type change.', 'wppizza-admin'),
237 'description'=>array(
238 '<span>'.__('As of version 3.13+ WPPizza now uses AJAX to update the order page when needed. For a limited time, this setting here will allow you to revert to using a full page reload as previously, in case you experience unexpected issues.', 'wppizza-admin').'</span>',
239 )
240 ));
241
242 }
243 return $settings;
244 }
245 /*------------------------------------------------------------------------------
246 # [output option fields - setting page]
247 # @since 3.0
248 # @return array()
249 ------------------------------------------------------------------------------*/
250 function admin_options_fields_settings($wppizza_options, $options_key, $field, $label, $description){
251
252 if($field=='disable_emails'){
253 print'<label>';
254 print "<input name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />";
255 print'' . $label . '';
256 print'</label>';
257 print'' . $description . '';
258 }
259
260 if($field=='always_open_for_user'){
261 print'<label>';
262 print "<input name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='text' value='".$wppizza_options[$options_key][$field]."' />";
263 print'' . $label . '';
264 print'</label>';
265 print'' . $description . '';
266 }
267
268 if($field=='continue_order_on_mail_error'){
269 echo "<label>";
270 echo "<input name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />";
271 echo "" . $label . "";
272 echo "</label>";
273 echo"".$description."";
274 }
275
276 if($field=='empty_category_and_items'){
277 print'<label>';
278 print "<input name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' value='1' />";
279 print'' . $label . '';
280 print'</label>';
281
282 print"<br />";
283 print"<label>";
284 print"<input id='empty_category_and_items_delete_attachments' name='".WPPIZZA_SLUG."[".$options_key."][delete_attachments]' type='checkbox' value='1' />".__('Delete images too', 'wppizza-admin')."</label>";
285 print'' . $description . '';
286 }
287
288 if($field=='category_repair'){
289 print'<label>';
290 print "<input name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' value='1' />";
291 print'' . $label . '';
292 print'</label>';
293 print'' . $description . '';
294 }
295
296 if($field=='default_templates_reset'){
297 print'<label>';
298 print "<input name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' value='1' />";
299 print'' . $label . '';
300 print'</label>';
301 print'' . $description . '';
302 }
303
304 if($field=='debug'){
305 print'<label>';
306 print'' . $label . '';
307 print'</label>';
308 print'' . $description . '';
309 }
310
311 if($field=='compat_legacy_checkout'){
312 print'<label>';
313 print "<input name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />";
314 print'' . $label . '';
315 print'</label>';
316 print'' . $description . '';
317 }
318 }
319
320 /****************************************************************
321 *
322 * [insert default option on install]
323 * $parameter $options array() | filter passing on filtered options
324 * @since 3.0
325 * @return array()
326 *
327 ****************************************************************/
328 function options_default($options){
329 $options[$this->settings_page]['disable_emails'] = false;
330 $options[$this->settings_page]['always_open_for_user'] = '';
331 $options[$this->settings_page]['continue_order_on_mail_error'] = false;
332 $options[$this->settings_page]['compat_legacy_checkout'] = false;
333 return $options;
334 }
335
336 /*------------------------------------------------------------------------------
337 # [validate options on save/update]
338 #
339 # @since 3.0
340 # @return array()
341 ------------------------------------------------------------------------------*/
342 function options_validate($options, $input){
343 /**make sure we get the full array on install/update**/
344 if ( empty( $_POST['_wp_http_referer'] ) ) {
345 return $input;
346 }
347 if(isset($_POST[''.WPPIZZA_SLUG.'_'.$this->settings_page.'_'.$this->tab_key.''])){
348
349 $options[$this->settings_page]['disable_emails'] = !empty($input[$this->settings_page]['disable_emails']) ? true : false;
350 $options[$this->settings_page]['always_open_for_user'] = wppizza_validate_ip_or_userid($input[$this->settings_page]['always_open_for_user']);
351 $options[$this->settings_page]['continue_order_on_mail_error'] = !empty($input[$this->settings_page]['continue_order_on_mail_error']) ? true : false;
352 $options[$this->settings_page]['compat_legacy_checkout'] = !empty($input[$this->settings_page]['compat_legacy_checkout']) ? true : false;
353
354 /*********************************
355 repair categories if enabled,
356 skip if deleting all anyway
357 *********************************/
358 if(!empty($input[$this->settings_page]['category_repair']) && empty($input[$this->settings_page]['empty_category_and_items']) ){
359 $category_sort_reset = WPPIZZA() -> categories -> wppizza_get_cats_hierarchy();
360 /***overwrite old vars**/
361 $options['layout']['category_sort_hierarchy']=$category_sort_reset;
362 }
363
364 /*********************************
365 reset default email/print templates,
366 *********************************/
367 if(!empty($input[$this->settings_page]['default_templates_reset']) ){
368
369 /***************************
370 get default email/print templates
371 ***************************/
372 $TEMPLATES = new WPPIZZA_MANAGE_TEMPLATES();
373 $templates_default = $TEMPLATES -> set_default_templates();
374
375 /**************************
376 add template defaults
377 **************************/
378 foreach($templates_default as $tplKey => $template_options){
379 $template_option_name = WPPIZZA_SLUG.'_'.$tplKey.'';
380 $template_options = get_option($template_option_name);
381
382 /* get current */
383 $current_defaults = $template_options[0];
384
385 /* override [0] (default) key with ini vars */
386 $template_options[0] = $templates_default[$tplKey][0];
387
388 /* re-apply current|old css settings */
389 $template_options[0]['global_styles'] = $current_defaults['global_styles'];
390 foreach($current_defaults['sections'] as $sKey=>$sVal){
391 $template_options[0]['sections'][$sKey]['style'] = $sVal['style'] ;
392 }
393 /* update resetting defualt option */
394 update_option($template_option_name, $template_options, false);
395 }
396
397 }
398
399
400 /************************************
401 delete wppizza posts, categories
402 and - possibly - images/attachments
403 ************************************/
404 if(!empty($input[$this->settings_page]['empty_category_and_items'])){
405 /**delete cats and posts**/
406 $this->wppizza_empty_taxonomy_posts(!empty($input[$this->settings_page]['delete_attachments']) ? true : false);
407 /***reset cat sort (as we will have deleted all categories)**/
408 $options['layout']['category_sort_hierarchy']=array();
409 }
410
411 }
412
413 return $options;
414 }
415
416 /*********************************************************
417 *
418 * [delete wppizza categories, tags, posts with/out attachments]
419 * @since 3.0 (update v3.15 to include tags)
420 *
421 *********************************************************/
422 function wppizza_empty_taxonomy_posts($deleteAttachments=false){
423 $terms = get_terms(''.WPPIZZA_TAXONOMY.'', array('hide_empty' => false));
424
425 if(count($terms)>0){
426 /*************************************************************************************************
427 *
428 * [first get all posts and make an array of all post we have to use in attachment/post delete]
429 *
430 *************************************************************************************************/
431 $postids=array();
432 $args = array('post_type'=> WPPIZZA_SLUG ,'posts_per_page'=>-1);
433 $the_query = new WP_Query( $args );
434 if($the_query->have_posts()) {
435 $posts=$the_query->posts;
436 }
437 if(isset($posts) && is_array($posts)){
438 foreach($posts as $k=>$v){
439 $postids[]=$v->ID;
440 }}
441 /*************************************************************************************************
442 *
443 * [as attachments parents get set to 0 when a post is deleted , delete attachments first (ifset)]
444 *
445 *************************************************************************************************/
446 if($deleteAttachments){
447 if(isset($postids) && is_array($postids)){
448 foreach($postids as $k=>$v){
449 $args = array(
450 'post_parent' => $v,
451 'post_status' => null,
452 'post_type' => 'attachment'
453 );
454 $attachments = get_children( $args );
455 foreach($attachments as $attachment){
456 wp_delete_attachment( $attachment->ID,true );
457 }
458 }}
459 }
460 /*************************************************************************************************
461 *
462 * [now lets delete all posts]
463 *
464 *************************************************************************************************/
465 if(isset($postids) && is_array($postids)){
466 foreach($postids as $k=>$v){
467 wp_delete_post( $v, true );
468 }}
469
470
471 /*************************************************************************************************
472 *
473 * [now lets delete all terms (categories)]
474 *
475 *************************************************************************************************/
476 foreach( $terms as $term ){
477 wp_delete_term( $term->term_id, WPPIZZA_TAXONOMY );
478 }
479 }
480
481 /*************************************************************************************************
482 *
483 * [now lets also delete all wppizza tags]
484 *
485 *************************************************************************************************/
486 $tags = get_terms(''.WPPIZZA_TAGS.'', array('hide_empty' => false));
487 if(is_array($tags) && count($tags)>0){
488 foreach( $tags as $tag ){
489 wp_delete_term( $tag->term_id, WPPIZZA_TAGS );
490 }}
491
492 }
493
494
495 }
496 /***************************************************************
497 *
498 * [ini]
499 *
500 ***************************************************************/
501 $WPPIZZA_MODULE_TOOLS_MISCELLANEOUS = new WPPIZZA_MODULE_TOOLS_MISCELLANEOUS();
502 ?>