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 / subpages / subpage.openingtimes.php

subpage.openingtimes.php in WPPizza – A Restaurant Plugin 3.20, at classes/subpages/subpage.openingtimes.php

401 lines 14.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPPIZZA_OPENINGTIMES Class
4 *
5 * @package WPPIZZA
6 * @subpackage Submenu Pages / Classes / Opening Times
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 * WPPIZZA_OPENINGTIMES
19 *
20 *
21 ************************************************************************************************************************/
22 class WPPIZZA_OPENINGTIMES{
23 /*
24 * class ident
25 * @var str
26 * @since 3.0
27 */
28 private $class_key='openingtimes';/*to help consistency throughout class in various places*/
29
30 /*
31 * titles/lables
32 * @var str
33 * @since 3.0
34 */
35 private $submenu_page_header;
36 private $submenu_page_title;
37 private $submenu_caps_title;
38 private $submenu_link_label;
39 private $submenu_priority = 30;
40 function __construct() {
41
42 /*titles/labels throughout class*/
43 add_action('init', array( $this, 'init_admin_lables') );
44
45 /** registering submenu page **/
46 add_action( 'admin_menu', array( $this, 'wppizza_register_submenu_page'), $this->submenu_priority );
47
48 /**add settings sections on this submenu page**/
49 add_action('current_screen', array( $this, 'wppizza_admin_settings_sections'));
50
51 /*register capabilities for this page*/
52 add_filter('wppizza_filter_define_caps', array( $this, 'wppizza_filter_define_caps'), $this->submenu_priority);
53
54 /*execute some helper functions once to use their return multiple times */
55 add_action('current_screen', array( $this, 'wppizza_add_helpers') );
56 /**admin ajax**/
57 add_action('wp_ajax_wppizza_admin_'.$this->class_key.'_ajax', array($this, 'set_admin_ajax') );
58 }
59
60 /******************
61 * @since 3.0.26
62 * [admin ajax include file]
63 *******************/
64 public function init_admin_lables(){
65 /*titles/labels throughout class*/
66 $this->submenu_page_header = apply_filters('wppizza_filter_admin_label_page_header_'.$this->class_key.'', __('Opening Times','wppizza-admin'));
67 $this->submenu_page_title = apply_filters('wppizza_filter_admin_label_page_title_'.$this->class_key.'', __('Manage Opening Times','wppizza-admin'));
68 $this->submenu_caps_title = apply_filters('wppizza_filter_admin_label_caps_title_'.$this->class_key.'', __('Opening Times','wppizza-admin'));
69 $this->submenu_link_label = apply_filters('wppizza_filter_admin_label_link_label_'.$this->class_key.'', __('&middot; Opening Times','wppizza-admin'));
70 }
71
72 /*********************************************************
73 *
74 * [add global helpers and enque js]
75 * @since 3.0
76 *
77 *********************************************************/
78 public function wppizza_add_helpers($current_screen){
79
80
81 if($current_screen->id == 'options' && isset($_POST[''.WPPIZZA_POST_TYPE.'_'.$this->class_key.''])){
82 /** return capabilities when saving options **/
83 add_filter( 'option_page_capability_'.WPPIZZA_SLUG.'', array($this, 'admin_option_page_capability' ));
84 }
85
86 if($current_screen->id == ''.WPPIZZA_POST_TYPE.'_page_'.$this->class_key.'' && $current_screen->post_type == WPPIZZA_POST_TYPE){
87 /***enqueue scripts and styles***/
88 add_action('admin_enqueue_scripts', array( $this, 'wppizza_enqueue_admin_scripts_and_styles'));
89
90 }
91 }
92 /*********************************************************
93 *
94 * [enqueue]
95 * @since 3.0
96 *
97 *********************************************************/
98 public function wppizza_enqueue_admin_scripts_and_styles($hook) {
99 global $wp_scripts, $wppizza_options;
100 /* Get the WP built-in jquery-ui-core version to use for jquery ui*/
101 $jquery_ui_core_version = $wp_scripts->registered['jquery-ui-core']->ver;
102
103 /************
104 css
105 ***********/
106
107 /** chosen **/
108 wp_register_style(WPPIZZA_SLUG.'-chosen', plugins_url( 'css/wppizza-chosen.min.css', WPPIZZA_PLUGIN_PATH ), array(), WPPIZZA_VERSION);
109 wp_enqueue_style(WPPIZZA_SLUG.'-chosen');
110
111 /*
112 datepicker / timepicker css
113 load a localised (gdpr) version (currently only smoothness supported) here too if we load it in the frontend
114 */
115 $ui_style = $wppizza_options['order_settings']['order_page_quantity_change_style'];
116 $isLocal = substr($ui_style, -5) == '.gdpr' ? true : false ;
117 $stylePath = $isLocal ? ''. WPPIZZA_URL . 'css/ui/smoothness.css' : '//code.jquery.com/ui/'.$jquery_ui_core_version .'/themes/smoothness/jquery-ui.min.css';
118 wp_enqueue_style('jquery-style', $stylePath, array(), $jquery_ui_core_version);
119
120 /************
121 js
122 ***********/
123
124 /** chosen **/
125 wp_register_script(WPPIZZA_SLUG.'-chosen', plugins_url( 'js/chosen.jquery.min.js', WPPIZZA_PLUGIN_PATH ), array('jquery'), WPPIZZA_VERSION ,true);
126 wp_enqueue_script(WPPIZZA_SLUG.'-chosen');
127
128 wp_enqueue_script('jquery-ui-datepicker');
129
130 wp_register_script(WPPIZZA_SLUG.'-timepicker', plugins_url( 'js/jquery.ui.timepicker.js', WPPIZZA_PLUGIN_PATH ), array('jquery'), WPPIZZA_VERSION ,true);
131 wp_enqueue_script(WPPIZZA_SLUG.'-timepicker');
132
133 wp_register_script(WPPIZZA_SLUG.'_'.$this->class_key.'', plugins_url( 'js/scripts.admin.'.$this->class_key.'.js', WPPIZZA_PLUGIN_PATH ), array('jquery'), WPPIZZA_VERSION ,true);
134 wp_enqueue_script(WPPIZZA_SLUG.'_'.$this->class_key.'');
135 }
136
137 /******************
138 * @since 3.0
139 * [admin ajax include file]
140 *******************/
141 public function set_admin_ajax(){
142 require(WPPIZZA_PATH.'ajax/admin.ajax.wppizza.php');
143 die();
144 }
145 /*********************************************************
146 *
147 * [register submenu page]
148 * @since 3.0
149 *
150 *********************************************************/
151 public function wppizza_register_submenu_page(){
152
153 $submenu_page= array(
154 'url' => 'edit.php?post_type='.WPPIZZA_SLUG.'',
155 'title' => ''.WPPIZZA_NAME.' '.$this->submenu_page_title,
156 'link_label' => $this->submenu_link_label,
157 'caps' => 'wppizza_cap_'.$this->class_key.'',
158 'key' => $this->class_key,
159 'callback' => array($this, 'wppizza_admin_manage_sections')
160 );
161 /**add submenu page**/
162 $wppizza_submenu_page=add_submenu_page($submenu_page['url'], $submenu_page['title'], $submenu_page['link_label'], $submenu_page['caps'], $submenu_page['key'], $submenu_page['callback']);
163 /**add contextual help**/
164 add_action('load-'.$wppizza_submenu_page.'', array($this, 'wppizza_submenu_page_contextual_help'));
165 }
166 /*********************************************************
167 *
168 * [add settings section(s) and fields]
169 *
170 * @since 3.0
171 * @return void
172 *
173 *********************************************************/
174 function wppizza_admin_settings_sections(){
175 global $current_screen;
176 if($current_screen->id == ''.WPPIZZA_POST_TYPE.'_page_'.$this->class_key.'' && $current_screen->post_type == WPPIZZA_POST_TYPE){
177 /** get settings sections and fields **/
178 $settings=$this->wppizza_get_settings(true, true);
179
180 /**iterate through sections*/
181 foreach($settings['sections'] as $sections_key=>$sections_label){
182 /**add section**/
183 add_settings_section($sections_key, $sections_label, array( $this, 'wppizza_admin_settings_section_header'), $sections_key);
184
185 /**add section fields**/
186 foreach($settings['fields'][$sections_key] as $fields_key=>$field_values){
187 add_settings_field($fields_key, $field_values[0], array( $this, 'wppizza_admin_settings_section_fields'), $sections_key, $sections_key, $field_values[1]);
188 }
189 }
190
191 }
192 }
193 /*********************************************************
194 *
195 * [echo setting section(s) fields]
196 *
197 *********************************************************/
198 public function wppizza_admin_settings_section_fields($args){
199 /** wppizza options set **/
200 global $wppizza_options;
201
202
203 /**option key - array key of parent option set in options table**/
204 $options_key = !empty($args['option_key']) ? $args['option_key'] : false;
205 /**value key - array key of option set in options table (subkey of options_key)**/
206 $field = !empty($args['value_key']) ? $args['value_key'] : false;
207 /**label (if any)**/
208 $label = !empty($args['label']) ? $args['label'] : '' ;
209 /**description (if any)**/
210 $description = !empty($args['description']) ? '<br /><span class="description description_'.$field.'">'.implode('</span><br /><span class="description description_'.$field.'">',$args['description']).'</span>' : '' ;
211
212 /********************************
213 * [add action for modules to hook into, also providing full args list if needed somewhere]
214 ********************************/
215 do_action('wppizza_admin_settings_section_fields_'.$this->class_key.'', $wppizza_options, $options_key, $field, $label, $description, $args);
216 }
217
218 /*********************************************************
219 *
220 * [add setting section(s) headers]
221 *
222 * @param array
223 * @return str
224 *
225 *********************************************************/
226 public function wppizza_admin_settings_section_header($arg){
227 /*might come in useful somewhere*/
228 static $section_count=0;$section_count++;
229 /**add more text headers if required*/
230 do_action('wppizza_settings_sections_header_'.$this->class_key.'', $arg, $section_count);
231 }
232 /*********************************************************
233 *
234 * [add contextual help to submenu page]
235 * @since 3.0
236 *
237 *********************************************************/
238 function wppizza_submenu_page_contextual_help(){
239
240 $screen = get_current_screen();
241 /** get settings sections and fields **/
242 $settings=$this->wppizza_get_settings(true, false, false, true);
243
244 foreach($settings['sections'] as $section_key=>$section_label){
245 /**only add tab if there is actually any help to display**/
246 if(!empty($settings['help'][$section_key])){
247 /**initialize content for this tab**/
248 $help_content='';
249 foreach($settings['help'][$section_key] as $help_info){
250 /*add label*/
251 if(!empty($help_info['label'])){
252 $help_content.='<h3>'.$help_info['label'].'</h3>';
253 }
254 /*add description*/
255 if(!empty($help_info['description']) && is_array($help_info['description'])){
256 foreach($help_info['description'] as $description){
257 $help_content.='<p>'.$description.'</p>';
258 }
259 }
260 }
261 /**add help tabs with content**/
262 $screen->add_help_tab( array('id' => 'wppizza_'.$this->class_key.'_'.$section_key.'', 'title' => $section_label, 'content' => '<div class="wppizza_admin_context_help">'.$help_content.'</div>'));
263 }
264 }
265
266 }
267 /*********************************************************
268 *
269 * [echo manage settings]
270 *
271 * wrap settings sections into div->form
272 * add uniquely identifiable id's / classes
273 * add h2 text
274 * add uniquely identifiable hidden input
275 * add submit button
276 *
277 * @since 3.0
278 * @return str
279 *
280 *********************************************************/
281 public function wppizza_admin_manage_sections(){
282
283 /*
284 wppizza post type only
285 */
286 $screen = get_current_screen();
287 if($screen->post_type != WPPIZZA_POST_TYPE){return;}
288
289
290 /** get sections settings**/
291 $settings=$this->wppizza_get_settings(true);
292
293 /**wrap settings sections into div->form */
294 echo'<div id="'.WPPIZZA_SLUG.'-'.$this->class_key.'" class="'.WPPIZZA_SLUG.'-wrap '.WPPIZZA_SLUG.'-'.$this->class_key.'-wrap">';
295
296
297 echo"<div class='".WPPIZZA_SLUG."-admin-pageheader'>";
298
299 echo"<h2>";
300 /*help icon*/
301 echo"<a href='javascript:void(0)' class='wppizza-dashicons-admin button'><span class='dashicons dashicons-editor-help wppizza-show-admin-help'></span></a>";
302 echo"<span id='".WPPIZZA_SLUG."-header'>".WPPIZZA_NAME." ".$this->submenu_page_header."</span>";
303 echo"</h2>";
304
305 /*help text*/
306 echo"<span class='wppizza-help-hint'>".__('Note: Some options will have more details in the <a href="javascript:void(0)" class="wppizza-show-admin-help">help screen</a>','wppizza-admin')."</span>";
307
308 echo"</div>";
309
310 /**update info / errors etc*/
311 settings_errors();
312
313
314 echo'<form action="options.php" method="post">';
315 echo'<input type="hidden" name="'.WPPIZZA_SLUG.'_'.$this->class_key.'" value="1" />';
316
317 /**echo wppizza settings field*/
318 settings_fields(WPPIZZA_SLUG);
319
320 /**echo settings sections**/
321 foreach($settings['sections'] as $sections_key => $sections_label){
322 echo'<div class="wppizza-section wppizza-section-'.$sections_key.'">';
323 do_settings_sections($sections_key);
324 echo'</div>';
325 }
326
327 /**echo submit button or diabled button*/
328 if(WPPIZZA_DEV_ADMIN_NO_SAVE){
329 print '<input type="button" class="'.WPPIZZA_PREFIX.'-save-disabled" value="'.__('Saving Disabled', 'wppizza-admin').'">';
330 }else{
331 submit_button( __('Save Changes', 'wppizza-admin') );
332 }
333
334 echo'</form>';
335 echo'</div>';
336 }
337
338 /*********************************************************
339 *
340 * [set settings section(s)]
341 * @parameter $sections bool -> return sections
342 * @parameter $fields bool -> return fields
343 * @since 3.0
344 * @return array
345 *
346 *********************************************************/
347 private function wppizza_get_settings($sections=true, $fields=false, $inputs=false, $help=false){
348 /**ini settings array to splice into**/
349 $settings=array();
350 if($sections){
351 $settings['sections']=array();
352 }
353 if($fields){
354 $settings['fields']=array();
355 }
356 if($help){
357 $settings['help']=array();
358 }
359
360
361 /**
362 allow filtering of settings sections
363 to add additional if required
364 **/
365 $settings=apply_filters('wppizza_filter_settings_sections_'.$this->class_key.'', $settings, $sections, $fields, $inputs, $help);
366
367 return $settings;
368 }
369
370 /*********************************************************
371 *
372 * [define caps]
373 * @since 3.0
374 *
375 *********************************************************/
376 function wppizza_filter_define_caps($caps){
377
378 /**add editing capability for this page**/
379 $caps[$this->class_key]=array('name'=>$this->submenu_caps_title ,'cap'=>'wppizza_cap_'.$this->class_key.'');
380
381 return $caps;
382 }
383 /*********************************************************
384 *
385 * [set required capability for this page]
386 * @since 3.0
387 *
388 *********************************************************/
389 function admin_option_page_capability($capability) {
390 $capability = 'wppizza_cap_'.$this->class_key.'';
391 return $capability;
392 }
393 }
394
395 /***************************************************************
396 *
397 * [ini]
398 *
399 ***************************************************************/
400 $WPPIZZA_OPENINGTIMES = new WPPIZZA_OPENINGTIMES();
401 ?>