PluginProbe
Post Grid Gutenberg Blocks – PostX / 2.4.26
Post Grid Gutenberg Blocks – PostX v2.4.26
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.26, at classes/options/Settings.php

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