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

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

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