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.order_settings.php

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

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