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

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

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