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.settings.general.php

mod.settings.general.php in WPPizza – A Restaurant Plugin 3.20, at classes/modules/mod.settings.general.php

462 lines 18.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPPIZZA_MODULE_SETTINGS_GENERAL Class
4 *
5 * @package WPPIZZA
6 * @subpackage WPPIZZA_MODULE_SETTINGS_GENERAL
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_GENERAL{
24
25 private $settings_page = 'settings';/* which admin subpage (identified there by this->class_key) are we adding this to */
26 private $section_key = 'settings_general';/* must be unique */
27
28
29 function __construct() {
30 /**********************************************************
31 [add settings to admin]
32 ***********************************************************/
33 if(is_admin()){
34 /* add admin options settings page*/
35 add_filter('wppizza_filter_settings_sections_'.$this->settings_page.'', array($this, 'admin_options_settings'), 10, 5);
36 /* add admin options settings page fields */
37 add_action('wppizza_admin_settings_section_fields_'.$this->settings_page.'', array($this, 'admin_options_fields_settings'), 10, 5);
38 /**add default options **/
39 add_filter('wppizza_filter_setup_default_options', array( $this, 'options_default'));
40 /**validate options**/
41 add_filter('wppizza_filter_options_validate', array( $this, 'options_validate'), 10, 2 );
42 }
43 /**********************************************************
44 [filter/actions depending on settings]
45 ***********************************************************/
46 /* mail_type wppizza_filter_mail_type deosnt actually exist anywhere so the filter below does not do anything - yet */
47 //add_filter('wppizza_filter_mail_type', array( $this, 'mail_type'));
48
49 /* post_single_template */
50 add_filter('the_permalink', array( $this, 'search_results_permalink'));/**change the permalink of any wppizza menu item to use loop template for single item instead of having to create a different template*/
51 add_filter('pre_get_posts', array( $this, 'single_items'));/**change the loop query when dealing with single menu items**//**use loop template to also display single items**/
52 /* using_cache_plugin */
53 add_filter('wppizza_filter_using_cache_plugin', array( $this, 'using_cache_plugin'));
54 /* ssl on checkout */
55 add_filter('wppizza_filter_ssl_on_checkout', array( $this, 'ssl_on_checkout'));
56 /* js in footer */
57 add_filter('wppizza_filter_js_in_footer', array( $this, 'js_in_footer'));
58 /* dis/enable gutenberg */
59 add_filter('wppizza_filter_cpt_args', array( $this, 'disable_gutenberg'));
60 /* dis/enable gutenberg */
61 add_filter('wppizza_filter_ctx_args', array( $this, 'disable_gutenberg_taxonomy'));
62 /* dis/enable wppizza tags */
63 add_filter('wppizza_register_tags', array( $this, 'enable_tags'));
64 }
65
66 /*******************************************************************************************************************************************************
67 *
68 *
69 *
70 * [frontend filters]
71 *
72 *
73 *
74 ********************************************************************************************************************************************************/
75 /*************************************
76
77 set general mail type ?
78
79 **************************************/
80 // function mail_type($mail_type = 'wp_mail'){
81 // global $wppizza_options;
82 // /* get available mail options */
83 // $options_available = wppizza_admin_mail_delivery_options(false, false, false, false, true);
84 // /* set mail type in options */
85 // $set_mail_type = $wppizza_options[$this->settings_page]['mail_type'];
86 //
87 // /** return selected mailtype if exists, or default to 'wp_mail' */
88 // $mail_type = isset($options_available[$set_mail_type]) ? $set_mail_type : $mail_type;
89 //
90 // return $mail_type;
91 // }
92 /***************************************************************
93 filter loop when using single item (for example a link from
94 searchresults) to only display this single item
95 if not using dedicated single-wppizza.php template
96 ****************************************************************/
97 function single_items($query){/**add relevant filters*/
98 global $post, $wppizza_options;
99 /* skip if not set */
100 if(empty($wppizza_options[$this->settings_page]['post_single_template'])){
101 return $query;
102 }
103 if(isset($_GET[WPPIZZA_SINGLE_PERMALINK_VAR]) && $query->is_main_query()){
104 add_filter('wppizza_filter_loop_args', array( $this, 'loop_args_single_item'));
105 add_filter('the_content', array( $this, 'single_item_content'),0);
106 }
107 return $query;
108 }
109 /**run the filter on loop query **/
110 function loop_args_single_item($args){
111 if(isset($_GET[WPPIZZA_SINGLE_PERMALINK_VAR])){
112 $args=array(
113 'name' => wppizza_validate_string($_GET[WPPIZZA_SINGLE_PERMALINK_VAR]),
114 'post_type' => WPPIZZA_POST_TYPE,
115 'post_status' => 'publish',
116 'numberposts' => 1
117 );
118 $menuItem = get_posts($args);
119 if( $menuItem ) {
120 $args['post__in']=array($menuItem[0]->ID);
121 unset($args['tax_query']);
122 }
123 }
124 return $args;
125 }
126 /*filter content*/
127 function single_item_content($content){
128 global $post, $wppizza_options;
129 /*replace the content od this page with relevant shortcode*/
130 if($post->ID==$wppizza_options[$this->settings_page]['post_single_template']){
131 ob_start();
132 $content='';
133 echo do_shortcode( '[wppizza noheader=1]' );/*no need to add any other atts as the query takes care of the rest*/
134 $content = ob_get_clean();
135 }
136
137 return $content;
138 }
139
140
141 /*******************************************************
142 [wppizza modify permalink in search results to use
143 wppizza loop template when clicking on link instead
144 of normal blog layout - only used when no proper single-wppizza.php
145 template is in use]
146 ******************************************************/
147 function search_results_permalink($url) {
148 global $wppizza_options;
149 /* skip if not set */
150 if(empty($wppizza_options[$this->settings_page]['post_single_template'])){
151 return $url;
152 }
153 if(is_search() && get_post_type()==WPPIZZA_POST_TYPE){
154 /*get slug**/
155 $post_data = get_post(get_the_ID(), ARRAY_A);
156 $slug = $post_data['post_name'];
157 /*set args**/
158 $args=array();
159 $args['page_id']=$wppizza_options[$this->settings_page]['post_single_template'];/*use selected page to display things in to keep layout*/
160 $args['wppizza']=false;
161 $args[WPPIZZA_SINGLE_PERMALINK_VAR]=''.$slug.'';
162 /**amend permalink**/
163 return esc_url_raw(add_query_arg($args, $url));
164 }else{
165 return $url;
166 }
167 }
168 /*************************************
169
170 using_cache_plugin ?
171
172 **************************************/
173 function using_cache_plugin($bool){
174 global $wppizza_options;
175 $bool = !empty($wppizza_options[$this->settings_page]['using_cache_plugin']) ? true : false;
176 return $bool;
177 }
178
179 /*************************************
180
181 ssl_on_checkout ?
182
183 **************************************/
184 function ssl_on_checkout($bool){
185 global $wppizza_options;
186 $bool = !empty($wppizza_options[$this->settings_page]['ssl_on_checkout']) ? true : false;
187 return $bool;
188 }
189 /*************************************
190
191 js_in_footer ?
192
193 **************************************/
194 function js_in_footer($bool){
195 global $wppizza_options;
196 $bool = !empty($wppizza_options[$this->settings_page]['js_in_footer']) ? true : false;
197 return $bool;
198 }
199
200 /*************************************
201
202 enable gutenberg
203 @ since 3.8.2
204 **************************************/
205 function disable_gutenberg($args){
206 global $wppizza_options;
207 $args['show_in_rest'] = !empty($wppizza_options[$this->settings_page]['disable_gutenberg']) ? false : true;
208 return $args;
209 }
210 /*************************************
211
212 enable cpt taxonomies in gutenberg
213 @ since 3.10
214 **************************************/
215 function disable_gutenberg_taxonomy($args){
216 global $wppizza_options;
217 $args['show_in_rest'] = !empty($wppizza_options[$this->settings_page]['disable_gutenberg']) ? false : true;
218 return $args;
219 }
220
221 /*************************************
222
223 enable "tags" taxonomy
224 @ since 3.15
225 **************************************/
226 function enable_tags($bool){
227 global $wppizza_options;
228 $bool = !empty($wppizza_options[$this->settings_page]['taxonomy_tags']) ? true : false;
229 return $bool;
230 }
231
232 /*******************************************************************************************************************************************************
233 *
234 *
235 *
236 * [add admin page options]
237 *
238 *
239 *
240 ********************************************************************************************************************************************************/
241
242 /*------------------------------------------------------------------------------
243 #
244 #
245 # [settings page]
246 #
247 #
248 ------------------------------------------------------------------------------*/
249
250 /*------------------------------------------------------------------------------
251 # [settigs section - setting page]
252 # @since 3.0
253 # @return array()
254 ------------------------------------------------------------------------------*/
255 function admin_options_settings($settings, $sections, $fields, $inputs, $help){
256 global $wp_version;
257 /********************************
258 * [general ]
259 ********************************/
260 /*section*/
261 if($sections){
262 $settings['sections'][$this->section_key] = __('General', 'wppizza-admin');
263 }
264 /*help*/
265 if($help){
266 $settings['help'][$this->section_key][] = array(
267 'label'=>__('General', 'wppizza-admin'),
268 'description'=>array(
269 __('Please adjust settings as appropriate according to the information provided next to each individual option.', 'wppizza-admin')
270 )
271 );
272 }
273 /*fields*/
274 if($fields){
275 // $field = 'mail_type';
276 // $settings['fields'][$this->section_key][$field] = array( __('Select Type of Mail Delivery', 'wppizza-admin'), array(
277 // 'value_key'=>$field,
278 // 'option_key'=>$this->settings_page,
279 // 'label'=>__('might be worth changing if you have trouble when sending/receiving orders with the default settings or prefer html emails', 'wppizza-admin'),
280 // 'description'=>array(
281 // __('if using PHPMailer function you probably want to edit the html template. To do so, move "wppizza-order-html-email.php" from the wppizza template directory to your theme folder and edit as required', 'wppizza-admin')
282 // )
283 // ));
284 $field = 'post_single_template';
285 $settings['fields'][$this->section_key][$field] = array( __('Single menu items display', 'wppizza-admin'), array(
286 'value_key'=>$field,
287 'option_key'=>$this->settings_page,
288 'label'=>__('you could also leave this off and use the wppizza widget/shortcode for a dedicated search box', 'wppizza-admin'),
289 'description'=>array(
290 /* Translators: 1: URL to applicable documentation */
291 sprintf(__('please see the <a href="%s">faq\'s -> single wppizza menu items display</a> for details as to how this works', 'wppizza-admin'), 'https://docs.wp-pizza.com/developers/?section=wppizza-markup-single-single-php')
292 )
293 ));
294 $field = 'using_cache_plugin';
295 $settings['fields'][$this->section_key][$field] = array( __('I am using a caching plugin', 'wppizza-admin'), array(
296 'value_key'=>$field,
297 'option_key'=>$this->settings_page,
298 'label'=>__('ALWAYS load the cart dynamically via ajax.', 'wppizza-admin'),
299 'description'=>array(
300 __('Especially useful if your caching plugin does not support the exclusion of only parts of a page.', 'wppizza-admin'),
301 __('Note: you still want to exclude your entire *order page* - or at least the main content of that page - from being cached in your cache plugin (please see the documentation for your choosen cache plugin for how to do this).', 'wppizza-admin'),
302 __('After you enable this, clear your cache.', 'wppizza-admin'),
303 __('*MUST* be enabled if you are using a caching plugin or another caching solution, but also *CAN* be enabled, if you are not', 'wppizza-admin'),
304 )
305 ));
306 $field = 'ssl_on_checkout';
307 $settings['fields'][$this->section_key][$field] = array( __('SSL on checkout', 'wppizza-admin'), array(
308 'value_key'=>$field,
309 'option_key'=>$this->settings_page,
310 'label'=>__('set your order page to be https (you must have an SSL certificate installed)', 'wppizza-admin'),
311 'description'=>array()
312 ));
313 $field = 'js_in_footer';
314 $settings['fields'][$this->section_key][$field] = array( __('Javascript in Footer', 'wppizza-admin'), array(
315 'value_key'=>$field,
316 'option_key'=>$this->settings_page,
317 'label'=>__('combines all jsVars in one tidy place, but requires wp_footer in theme', 'wppizza-admin'),
318 'description'=>array()
319 ));
320 if (version_compare($wp_version, "5", ">=")) {
321 $field = 'disable_gutenberg';
322 $settings['fields'][$this->section_key][$field] = array( __('Disable Gutenberg Editor', 'wppizza-admin'), array(
323 'value_key'=>$field,
324 'option_key'=>$this->settings_page,
325 'label'=>__('By default (for now) the Gutenberg editor integrated into WP 5+ has been disabled on menu items. Un-check this box if you would like to use it.', 'wppizza-admin'),
326 'description'=>array()
327 ));
328 }
329 $field = 'taxonomy_tags';
330 $settings['fields'][$this->section_key][$field] = array( __('Enable Tags', 'wppizza-admin'), array(
331 'value_key'=>$field,
332 'option_key'=>$this->settings_page,
333 'label'=>__('enable adding of "Tags" to menu items - will be added as class name to surrounding article elements of menu items', 'wppizza-admin'),
334 'description'=>array()
335 ));
336
337 }
338
339
340 return $settings;
341 }
342 /*------------------------------------------------------------------------------
343 # [output option fields - setting page]
344 # @since 3.0
345 # @return array()
346 ------------------------------------------------------------------------------*/
347 function admin_options_fields_settings($wppizza_options, $options_key, $field, $label, $description){
348 global $wp_version;
349 // if($field=='mail_type'){
350 // echo "<label>";
351 // echo"".wppizza_admin_mail_delivery_options(''.WPPIZZA_SLUG.'['.$options_key.'][mail_type]', $wppizza_options[$options_key]['mail_type'])."";
352 // echo "" . $label . "";
353 // echo "</label>";
354 // echo"".$description."";
355 // }
356
357 if($field=='post_single_template'){
358 echo "<label>";
359 /**which single post template ?*/
360 echo "<select name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' />";
361 echo"<option value=''>".__('default or custom template [single-wppizza.php if exists]', 'wppizza-admin')."</option>";
362 foreach(wppizza_get_wordpress_pages() as $k=>$v){
363 if(isset($wppizza_options[$options_key]['post_single_template']) && $wppizza_options[$options_key]['post_single_template']==$v->ID){$sel=' selected="selected"';}else{$sel='';}
364 echo"<option value='".$v->ID."' ".$sel.">".$v->post_title."</option>";
365 }
366 echo "</select>";
367 echo "" . $label . "";
368 echo "</label>";
369 echo"".$description."";
370 }
371
372 if($field=='using_cache_plugin'){
373 echo "<label>";
374 echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />";
375 echo "" . $label . "";
376 echo "</label>";
377 echo"".$description."";
378 }
379
380 if($field=='ssl_on_checkout'){
381 echo "<label>";
382 echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />";
383 echo "" . $label . "";
384 echo "</label>";
385 echo"".$description."";
386 }
387
388 if($field=='js_in_footer'){
389 echo "<label>";
390 echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />";
391 echo "" . $label . "";
392 echo "</label>";
393 echo"".$description."";
394 }
395
396 /* wordpress 5 only */
397 if (version_compare($wp_version, "5", ">=")) {
398 if($field=='disable_gutenberg'){
399 echo "<label>";
400 echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />";
401 echo "" . $label . "";
402 echo "</label>";
403 echo"".$description."";
404 }}
405 if($field=='taxonomy_tags'){
406 echo "<label>";
407 echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />";
408 echo "" . $label . "";
409 echo "</label>";
410 echo"".$description."";
411 }
412 }
413 /*------------------------------------------------------------------------------
414 # [insert default option on install]
415 # $parameter $options array() | filter passing on filtered options
416 # @since 3.0
417 # @return array()
418 ------------------------------------------------------------------------------*/
419 function options_default($options){
420 //$options[$this->settings_page]['mail_type'] = 'wp_mail';
421 $options[$this->settings_page]['post_single_template'] = array();
422 $options[$this->settings_page]['using_cache_plugin'] = true;
423 $options[$this->settings_page]['ssl_on_checkout'] = false;
424 $options[$this->settings_page]['js_in_footer'] = true;
425 $options[$this->settings_page]['disable_gutenberg'] = true;
426 $options[$this->settings_page]['taxonomy_tags'] = false;
427 return $options;
428 }
429
430 /*------------------------------------------------------------------------------
431 # [validate options on save/update]
432 #
433 # @since 3.0
434 # @return array()
435 ------------------------------------------------------------------------------*/
436 function options_validate($options, $input){
437 /**make sure we get the full array on install/update**/
438 if ( empty( $_POST['_wp_http_referer'] ) ) {
439 return $input;
440 }
441 /********************************
442 * [validate]
443 ********************************/
444 if(isset($_POST[''.WPPIZZA_SLUG.'_'.$this->settings_page.''])){
445 //$options[$this->settings_page]['mail_type'] = wppizza_validate_alpha_only($input[$this->settings_page]['mail_type']);
446 $options[$this->settings_page]['post_single_template'] = !empty($input[$this->settings_page]['post_single_template']) ? (int)$input[$this->settings_page]['post_single_template'] : '';
447 $options[$this->settings_page]['using_cache_plugin'] = !empty($input[$this->settings_page]['using_cache_plugin']) ? true : false;
448 $options[$this->settings_page]['ssl_on_checkout'] = !empty($input[$this->settings_page]['ssl_on_checkout']) ? true : false;
449 $options[$this->settings_page]['js_in_footer'] = !empty($input[$this->settings_page]['js_in_footer']) ? true : false;
450 $options[$this->settings_page]['disable_gutenberg'] = !empty($input[$this->settings_page]['disable_gutenberg']) ? true : false;
451 $options[$this->settings_page]['taxonomy_tags'] = !empty($input[$this->settings_page]['taxonomy_tags']) ? true : false;
452 }
453 return $options;
454 }
455 }
456 /***************************************************************
457 *
458 * [ini]
459 *
460 ***************************************************************/
461 $WPPIZZA_MODULE_SETTINGS_GENERAL = new WPPIZZA_MODULE_SETTINGS_GENERAL();
462 ?>