PluginProbe
Post Grid Gutenberg Blocks – PostX / 2.4.5
Post Grid Gutenberg Blocks – PostX v2.4.5
5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 5.0.17 2.1.1 2.1.2 All 237 releases
ultimate-post / classes / options / Settings.php

Settings.php in Post Grid Gutenberg Blocks – PostX 2.4.5, at classes/options/Settings.php

331 lines 15.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ULTP;
3
4 defined('ABSPATH') || exit;
5
6 class Options_Settings{
7 public function __construct() {
8 add_submenu_page('ultp-settings', 'Settings', 'Settings', 'manage_options', 'ultp-option-settings', array( $this, 'create_admin_page'), 15);
9 add_action( 'admin_init', array( $this, 'register_settings' ) );
10 }
11
12 public function register_settings() {
13 register_setting( 'ultp_options', 'ultp_options', array( $this, 'sanitize' ) );
14 }
15
16 /**
17 * Sanitization callback
18 */
19 public function sanitize( $options ) {
20 if ($options) {
21 $settings = $this->get_option_settings_keys();
22 foreach ($settings as $key) {
23 $options[$key] = isset($options[$key]) ? $options[$key] : '';
24 }
25 $old_data = ultimate_post()->get_setting();
26 $options = array_merge($old_data, $options);
27 }
28 return $options;
29 }
30
31
32 /**
33 * Settings Fields Key Return
34 */
35 public function get_option_settings_keys() {
36 $attr = array();
37 $data = $this->get_option_settings();
38 if (!empty($data)) {
39 foreach ($data as $key => $inner_data) {
40 if (isset($inner_data['attr'])) {
41 foreach ($inner_data['attr'] as $k => $val) {
42 $attr[] = $k;
43 }
44 }
45 }
46 }
47 return $attr;
48 }
49
50
51 /**
52 * Settings Field Return
53 */
54 public function get_option_settings(){
55 return apply_filters('ultp_settings', array(
56 'general' => array(
57 'label' => __('General Settings', 'ultimate-post'),
58 'attr' => array(
59 'general_heading' => array(
60 'type' => 'heading',
61 'label' => __('General Settings', 'ultimate-post'),
62 ),
63 'css_save_as' => array(
64 'type' => 'select',
65 'label' => __('CSS Add Via', 'ultimate-post'),
66 'options' => array(
67 'wp_head' => __( 'Header - (Internal)','ultimate-post' ),
68 'filesystem' => __( 'File System - (External)','ultimate-post' ),
69 ),
70 'default' => 'wp_head',
71 'desc' => __('Select where you want to save CSS.', 'ultimate-post')
72 ),
73 'preloader_style' => array(
74 'type' => 'select',
75 'label' => __('Preloader Style', 'ultimate-post'),
76 'options' => array(
77 'style1' => __( 'Preloader Style 1','ultimate-post' ),
78 'style2' => __( 'Preloader Style 2','ultimate-post' ),
79 ),
80 'default' => 'style1',
81 'desc' => __('Select Preloader Style.', 'ultimate-post')
82 ),
83 'container_width' => array(
84 'type' => 'number',
85 'label' => __('Container Width', 'ultimate-post'),
86 'default' => '1140',
87 'desc' => __('Change Container Width of the Page Template(PostX Template).', 'ultimate-post')
88 ),
89 'editor_container' => array(
90 'type' => 'select',
91 'label' => __('Editor Container', 'ultimate-post'),
92 'options' => array(
93 'full_width' => __( 'Full Width','ultimate-post' ),
94 'theme_default' => __( 'Theme Default','ultimate-post' )
95 ),
96 'default' => 'full_width',
97 'desc' => __('Select Editor Container Width.', 'ultimate-post')
98 ),
99 'hide_import_btn' => array(
100 'type' => 'switch',
101 'label' => __('Hide Import Button', 'ultimate-post'),
102 'default' => '',
103 'desc' => __('Hide Import Layout Button from the Gutenberg Editor.', 'ultimate-post')
104 ),
105 'disable_image_size' => array(
106 'type' => 'switch',
107 'label' => __('Disable Image Size', 'ultimate-post'),
108 'default' => '',
109 'desc' => __('Disable Image Size of the Plugins.', 'ultimate-post')
110 ),
111 )
112 )
113 ));
114 }
115
116
117 /**
118 * Changelog Data
119 */
120 public function get_changelog_data() {
121 $html = '';
122 $resource_data = file_get_contents(ULTP_PATH.'/readme.txt', "r");
123 $data = array();
124 if ($resource_data) {
125 $resource_data = explode('== Changelog ==', $resource_data);
126 if (isset($resource_data[1])) {
127 $resource_data = $resource_data[1];
128 $resource_data = explode("\n", $resource_data);
129 $inner = false;
130 $count = -1;
131
132 foreach ($resource_data as $element) {
133 if ($element){
134 if (substr_count($element, '=') > 1) {
135 $count++;
136 $temp = trim(str_replace('=', '', $element));
137 if (strpos($temp, '-') !== false) {
138 $temp = explode('-', $temp);
139 $data[$count]['date'] = trim($temp[1]);
140 $data[$count]['version'] = trim($temp[0]);
141 }
142 }
143 if (strpos($element, '* New:') !== false) {
144 $data[$count]['new'][] = trim(str_replace('* New:', '', $element));
145 }
146 if (strpos($element, '* Fix:') !== false) {
147 $data[$count]['fix'][] = trim(str_replace('* Fix:', '', $element));
148 }
149 if (strpos($element, '* Update:') !== false) {
150 $data[$count]['update'][] = trim(str_replace('* Update:', '', $element));
151 }
152 }
153 }
154 }
155 }
156 if (!empty($data)) {
157 foreach ($data as $k => $inner_data) {
158 $html .= '<div class="ultp-changelog-wrap">';
159 foreach ($inner_data as $key => $changelog) {
160 if ($key == 'date') {
161 $html .= '<div class="ultp-changelog-date">'.__('Released on ', 'ultimate-post').' '.$changelog.'</div>';
162 } elseif($key == 'version') {
163 $html .= '<div class="ultp-changelog-version">'.__('Version', 'ultimate-post').' : '.$changelog.'</div>';
164 } else {
165 foreach ($changelog as $keyword => $val) {
166 $html .= '<div class="ultp-changelog-title"><span class="changelog-'.$key.'">'.$key.'</span>'.$val.'</div>';
167 }
168 }
169 }
170 $html .= '</div>';
171 }
172 }
173 echo $html;
174 }
175
176
177 /**
178 * Settings page output
179 */
180 public function get_settings_data( $data ) {
181 $html = '';
182 $option_data = ultimate_post()->get_setting();
183
184 foreach ($data as $key => $value) {
185 if ($value['type'] == 'hidden') {
186 $html .= '<input type="hidden" name="ultp_options['.$key.']" value="'.$value['value'].'"/>';
187 } else {
188 if ($value['type'] == 'heading') {
189 $html .= '<h2 class="ultp-settings-heading">'.$value['label'].'</h2>';
190 if ( isset($value['desc']) ) {
191 $html .= '<div class="ultp-settings-subheading">'.$value['desc'].'</div>';
192 }
193 }
194 $html .= '<div class="ultp-settings-wrap">';
195 if ($value['type'] != 'heading') {
196 if (isset($value['label'])) {
197 $html .= '<div class="ultp-settings-label">'.$value['label'].'</div>';
198 }
199 }
200 $html .= '<div class="ultp-settings-field-wrap">';
201 switch ($value['type']) {
202 case 'select':
203 $html .= '<div class="ultp-settings-field">';
204 $val = isset($option_data[$key]) ? $option_data[$key] : (isset($value['default']) ? $value['default'] : '');
205 $html .= '<select name="ultp_options['.$key.']">';
206 foreach ( $value['options'] as $id => $label ) {
207 $html .= '<option value="'.$id.'" '.( $val == $id ? ' selected="selected"':'').'>';
208 $html .= strip_tags( $label );
209 $html .= '</option>';
210 }
211 $html .= '</select>';
212 $html .= '<p class="description">'.$value['desc'].'</p>';
213 $html .= '</div>';
214 break;
215
216 case 'color':
217 $html .= '<div class="ultp-settings-field">';
218 $val = isset($option_data[$key]) ? $option_data[$key] : (isset($value['default']) ? $value['default'] : '');
219 $html .= '<input name="ultp_options['.$key.']" value="'.$val.'" class="ultp-color-picker" />';
220 $html .= '<p class="description">'.$value['desc'].'</p>';
221 $html .= '</div>';
222 break;
223
224 case 'number':
225 $html .= '<div class="ultp-settings-field">';
226 $val = isset($option_data[$key]) ? $option_data[$key] : (isset($value['default']) ? $value['default'] : '');
227 $html .= '<input type="number" name="ultp_options['.$key.']" value="'.$val.'"/>';
228 $html .= '<p class="description">'.$value['desc'].'</p>';
229 $html .= '</div>';
230 break;
231
232 case 'switch':
233 $html .= '<div class="ultp-settings-field ultp-settings-field-inline">';
234 $val = isset($option_data[$key]) ? $option_data[$key] : (isset($value['default']) ? $value['default'] : '');
235 $html .= '<input type="checkbox" value="yes" name="ultp_options['.$key.']" '.($val == 'yes' ? 'checked' : '').' />';
236 $html .= '<p class="description">'.$value['desc'].'</p>';
237 $html .= '</div>';
238 break;
239
240 case 'multiselect':
241 $html .= '<div class="ultp-settings-field">';
242 $saved_val = isset($option_data[$key]) ? $option_data[$key] : (isset($value['default']) ? $value['default'] : []);
243 $html .= '<select style="height:190px;" name="ultp_options['.$key.'][]" multiple>';
244 if (!empty($value['options'])) {
245 foreach ($value['options'] as $val) {
246 if (!empty($saved_val) && is_array($saved_val)) {
247 $html .= '<option value="'.$val.'" '.(in_array( $val , $saved_val ) ? 'selected' : '' ).'>'.$val.'</option>';
248 } else {
249 $html .= '<option value="'.$val.'">'.$val.'</option>';
250 }
251 }
252 }
253 $html .= ' </select>';
254 $html .= '</div>';
255 break;
256
257 default:
258 # code...
259 break;
260 }
261 $html .= '</div>';
262 $html .= '</div>';
263 }
264 }
265
266 echo $html;
267 }
268
269 /**
270 * Settings page output
271 */
272 public function create_admin_page() {
273 $data = self::get_option_settings();
274 ?>
275 <div class="ultp-option-body">
276
277 <?php require_once ULTP_PATH . 'classes/options/Heading.php'; ?>
278
279 <?php $section = isset($_GET['tab']) ? $_GET['tab'] :'general'; ?>
280 <div class="ultp-tab-wrap">
281 <div class="ultp-tab-title-wrap">
282 <?php foreach ($data as $key => $value) {
283 if (isset($value['label'])) { ?>
284 <div data-title="<?php echo $key; ?>" class="ultp-tab-title<?php if($section == $key){ echo ' active'; } ?>"><?php echo $value['label']; ?></div>
285 <?php }
286 } ?>
287 <div data-title="changelog" class="ultp-tab-title<?php if($section == 'changelog'){ echo ' active'; } ?>"><?php _e('Changelog', 'ultimate-post'); ?></div>
288 </div>
289 <div class="ultp-content-wrap">
290 <form method="post" action="options.php">
291 <div class="ultp-settings">
292 <input type="hidden" name="option_page" value="ultp_options" />
293 <input type="hidden" name="action" value="update" />
294 <?php echo wp_nonce_field( "ultp_options-options" ); ?>
295 <?php foreach ($data as $key => $value) {
296 if (isset($value['attr'])) { ?>
297 <div class="ultp-tab-content<?php if($section == $key){ echo ' active'; } ?>">
298 <div class="ultp-tab-overview">
299 <?php $this->get_settings_data( $value['attr'] ); ?>
300 </div>
301 </div>
302 <?php }
303 } ?>
304 <div class="ultp-tab-content<?php if($section == 'changelog'){ echo ' active'; } ?>"><!-- #Changelog Content -->
305 <?php $this->get_changelog_data(); ?>
306 </div>
307 <div class="ultp-settings-wrap ultp-submit-button">
308 <div></div><?php echo get_submit_button(); ?>
309 </div>
310 </div>
311 </form>
312 </div>
313 </div>
314
315 <script type="text/javascript">
316 jQuery( document ).ready(function() {
317 jQuery( document ).on( "click", '.ultp-tab-title', function(e){
318 jQuery(this).closest('.ultp-tab-wrap').find('.ultp-tab-title').removeClass('active').eq(jQuery(this).index()).addClass('active')
319 jQuery(this).closest('.ultp-tab-wrap').find('.ultp-tab-content').removeClass('active').eq(jQuery(this).index()).addClass('active');
320 let refresh = window.location.protocol + "//" + window.location.host + window.location.pathname + '?page=ultp-option-settings&tab='+jQuery(this).data('title');
321 window.history.pushState({ path: refresh }, '', refresh);
322 jQuery('input[name=_wp_http_referer]').val(window.location.pathname + '?page=ultp-option-settings&tab=general');
323 });
324 });
325 </script>
326 </div>
327
328 <?php }
329
330
331 }