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 / modules / mod.layout.custom_css.php

mod.layout.custom_css.php in WPPizza – A Restaurant Plugin 3.20, at classes/modules/mod.layout.custom_css.php

216 lines 7.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPPIZZA_MODULE_LAYOUT_CUSTOM_CSS Class
4 *
5 * @package WPPIZZA
6 * @subpackage WPPIZZA_MODULE_LAYOUT_CUSTOM_CSS
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 *
19 *
20 *
21 *
22 ************************************************************************************************************************/
23 class WPPIZZA_MODULE_LAYOUT_CUSTOM_CSS{
24
25 private $settings_page = 'layout';/* which admin subpage (identified there by this->class_key) are we adding this to */
26 private $section_key = 'custom_css';/* must be unique */
27 private $module_priority = 21;/* display order (priority) of settings in subpage */
28
29 function __construct() {
30 /**********************************************************
31 [add settings to admin]
32 ***********************************************************/
33 if(is_admin()){
34 /* add admin options settings page*/
35 add_filter('wppizza_filter_settings_sections_'.$this->settings_page.'', array($this, 'admin_options_settings'), $this->module_priority, 5);
36 /* add admin options settings page fields */
37 add_action('wppizza_admin_settings_section_fields_'.$this->settings_page.'', array($this, 'admin_options_fields_settings'), 10, 5);
38 /**add default options **/
39 add_filter('wppizza_filter_setup_default_options', array( $this, 'options_default'));
40 /**validate options**/
41 add_filter('wppizza_filter_options_validate', array( $this, 'options_validate'), 10, 2 );
42 }
43 }
44
45 /*******************************************************************************************************************************************************
46 *
47 *
48 *
49 * [frontend filters]
50 *
51 *
52 *
53 ********************************************************************************************************************************************************/
54
55
56
57 /*******************************************************************************************************************************************************
58 *
59 *
60 *
61 * [add admin page options]
62 *
63 *
64 *
65 ********************************************************************************************************************************************************/
66
67 /*------------------------------------------------------------------------------
68 #
69 #
70 # [settings page]
71 #
72 #
73 ------------------------------------------------------------------------------*/
74
75 /*------------------------------------------------------------------------------
76 # [settings section - setting page]
77 # @since 3.0
78 # @return array()
79 ------------------------------------------------------------------------------*/
80 function admin_options_settings($settings, $sections, $fields, $inputs, $help){
81
82 /*section*/
83 if($sections){
84 $settings['sections'][$this->section_key] = __('Custom CSS', 'wppizza-admin');
85 }
86 /*fields*/
87 if($fields){
88
89 $field = 'custom_css';
90 $settings['fields'][$this->section_key][$field] = array( __('Enter your Custom CSS', 'wppizza-admin') , array(
91 'value_key'=>$field,
92 'option_key'=>$this->settings_page,
93 'label'=>'',
94 'description'=>array()
95 ));
96 }
97
98 /*help*/
99 if($help){
100 $settings['help'][$this->section_key][] = array(
101 'label'=>__('Custom CSS', 'wppizza-admin'),
102 'description'=>array(
103 __('Enter any custom css declaration. The created css file (or added &#60;style&#62; declarations if creation of the file fails due to server restrictions) will be loaded after any/all other wppizza css or omitted if empty', 'wppizza-admin'),
104 )
105 );
106 }
107
108
109 return $settings;
110 }
111 /*------------------------------------------------------------------------------
112 # [output option fields - setting page]
113 # @since 3.0
114 # @return array()
115 ------------------------------------------------------------------------------*/
116 function admin_options_fields_settings($wppizza_options, $options_key, $field, $label, $description){
117
118
119 if($field=='custom_css'){
120 $custom_css = get_option(WPPIZZA_SLUG.'_custom_css','');
121 print'<label>';
122 print'<div>' . $label . '</div>';
123 print "<textarea id='".$field."' rows='10' cols='75' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]'>". esc_textarea($custom_css)."</textarea>";
124 print'</label>';
125 print'' . $description . '';
126 }
127 }
128
129 /****************************************************************
130 *
131 * [insert default option on install]
132 * $parameter $options array() | filter passing on filtered options
133 * @since 3.0
134 * @return array()
135 *
136 ****************************************************************/
137 function options_default($options){
138
139 /*
140 current set custom css settings - if any
141 */
142 $current_custom_css = get_option(WPPIZZA_SLUG.'_custom_css', false);
143
144 /*
145 custom css option
146 */
147 $user_css = empty($current_custom_css) ? '' : $current_custom_css ;
148 $update_user_css = update_option(WPPIZZA_SLUG.'_custom_css', $user_css, false);
149
150 /*
151 last update and loading type
152 */
153 $options[$this->settings_page]['custom_css_version'] = time();
154 $options[$this->settings_page]['custom_css_type'] = 'none';
155
156 return $options;
157 }
158
159 /*------------------------------------------------------------------------------
160 # [validate options on save/update]
161 #
162 # @since 3.0
163 # @return array()
164 ------------------------------------------------------------------------------*/
165 function options_validate($options, $input){
166 /**make sure we get the full array on install/update**/
167 if ( empty( $_POST['_wp_http_referer'] ) ) {
168 return $input;
169 }
170 if(isset($_POST[''.WPPIZZA_SLUG.'_'.$this->settings_page.''])){
171
172
173 $custom_css_file_path = WPPIZZA_PATH.'css/'.WPPIZZA_PREFIX.'.style.css';
174 $saved_css = get_option(WPPIZZA_SLUG.'_custom_css', '');
175 $update_css = trim(str_replace('}','}'.PHP_EOL,sanitize_text_field($input[$this->settings_page]['custom_css'])));
176
177
178 /** only if old css != new css */
179 if($saved_css != $update_css){
180
181 /** css not empty */
182 if(!empty($update_css)){
183 @file_put_contents($custom_css_file_path, $update_css);
184 }
185 /** css set is empty and file exists - unlink file */
186 if(empty($update_css)){
187 @unlink($custom_css_file_path);
188 }
189 /*
190 set css type [none|file|inline]
191 */
192 /** css set is empty == none, css set is NOT empty check if file exists 'file' else 'inline' **/
193 $custom_css_type = (empty($update_css)) ? 'none' : ((file_exists($custom_css_file_path)) ? 'file' : 'inline');
194
195 /* update custom css option */
196
197 $update_user_css = update_option(WPPIZZA_SLUG.'_custom_css', $update_css, false);
198
199 /*
200 last update and loading type
201 */
202 $options[$this->settings_page]['custom_css_version'] = time();
203 $options[$this->settings_page]['custom_css_type'] = $custom_css_type;
204 }
205 }
206
207 return $options;
208 }
209 }
210 /***************************************************************
211 *
212 * [ini]
213 *
214 ***************************************************************/
215 $WPPIZZA_MODULE_LAYOUT_CUSTOM_CSS = new WPPIZZA_MODULE_LAYOUT_CUSTOM_CSS();
216 ?>