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

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

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