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

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

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