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

328 lines 15.1 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 'hide_import_btn' => array(
97 'type' => 'switch',
98 'label' => __('Hide Import Button', 'ultimate-post'),
99 'default' => '',
100 'desc' => __('Hide Import Layout Button from the Gutenberg Editor.', 'ultimate-post')
101 ),
102 'disable_image_size' => array(
103 'type' => 'switch',
104 'label' => __('Disable Image Size', 'ultimate-post'),
105 'default' => '',
106 'desc' => __('Disable Image Size of the Plugins.', 'ultimate-post')
107 ),
108 )
109 )
110 ));
111 }
112
113
114 /**
115 * Changelog Data
116 */
117 public function get_changelog_data() {
118 $html = '';
119 $resource_data = file_get_contents(ULTP_PATH.'/readme.txt', "r");
120 $data = array();
121 if ($resource_data) {
122 $resource_data = explode('== Changelog ==', $resource_data);
123 if (isset($resource_data[1])) {
124 $resource_data = $resource_data[1];
125 $resource_data = explode("\n", $resource_data);
126 $inner = false;
127 $count = -1;
128
129 foreach ($resource_data as $element) {
130 if ($element){
131 if (substr_count($element, '=') > 1) {
132 $count++;
133 $temp = trim(str_replace('=', '', $element));
134 if (strpos($temp, '-') !== false) {
135 $temp = explode('-', $temp);
136 $data[$count]['date'] = trim($temp[1]);
137 $data[$count]['version'] = trim($temp[0]);
138 }
139 }
140 if (strpos($element, '* New:') !== false) {
141 $data[$count]['new'][] = trim(str_replace('* New:', '', $element));
142 }
143 if (strpos($element, '* Fix:') !== false) {
144 $data[$count]['fix'][] = trim(str_replace('* Fix:', '', $element));
145 }
146 if (strpos($element, '* Update:') !== false) {
147 $data[$count]['update'][] = trim(str_replace('* Update:', '', $element));
148 }
149 }
150 }
151 }
152 }
153 if (!empty($data)) {
154 foreach ($data as $k => $inner_data) {
155 $html .= '<div class="ultp-changelog-wrap">';
156 foreach ($inner_data as $key => $changelog) {
157 if ($key == 'date') {
158 $html .= '<div class="ultp-changelog-date">'.__('Released on ', 'ultimate-post').' '.date_i18n( 'd F Y', strtotime($changelog) ).'</div>';
159 } elseif($key == 'version') {
160 $html .= '<div class="ultp-changelog-version">'.__('Version', 'ultimate-post').' : '.$changelog.'</div>';
161 } else {
162 foreach ($changelog as $keyword => $val) {
163 $html .= '<div class="ultp-changelog-title"><span class="changelog-'.$key.'">'.$key.'</span>'.$val.'</div>';
164 }
165 }
166 }
167 $html .= '</div>';
168 }
169 }
170 echo $html;
171 }
172
173
174 /**
175 * Settings page output
176 */
177 public function get_settings_data( $data ) {
178 $html = '';
179 $option_data = ultimate_post()->get_setting();
180
181 foreach ($data as $key => $value) {
182 if ($value['type'] == 'hidden') {
183 $html .= '<input type="hidden" name="ultp_options['.$key.']" value="'.$value['value'].'"/>';
184 } else {
185 if ($value['type'] == 'heading') {
186 $html .= '<h2 class="ultp-settings-heading">'.$value['label'].'</h2>';
187 if ( isset($value['desc']) ) {
188 $html .= '<div class="ultp-settings-subheading">'.$value['desc'].'</div>';
189 }
190 }
191 $html .= '<div class="ultp-settings-wrap">';
192 if ($value['type'] != 'heading') {
193 if (isset($value['label'])) {
194 $html .= '<div class="ultp-settings-label">'.$value['label'].'</div>';
195 }
196 }
197 $html .= '<div class="ultp-settings-field-wrap">';
198 switch ($value['type']) {
199 case 'select':
200 $html .= '<div class="ultp-settings-field">';
201 $val = isset($option_data[$key]) ? $option_data[$key] : (isset($value['default']) ? $value['default'] : '');
202 $html .= '<select name="ultp_options['.$key.']">';
203 foreach ( $value['options'] as $id => $label ) {
204 $html .= '<option value="'.$id.'" '.( $val == $id ? ' selected="selected"':'').'>';
205 $html .= strip_tags( $label );
206 $html .= '</option>';
207 }
208 $html .= '</select>';
209 $html .= '<p class="description">'.$value['desc'].'</p>';
210 $html .= '</div>';
211 break;
212
213 case 'color':
214 $html .= '<div class="ultp-settings-field">';
215 $val = isset($option_data[$key]) ? $option_data[$key] : (isset($value['default']) ? $value['default'] : '');
216 $html .= '<input name="ultp_options['.$key.']" value="'.$val.'" class="ultp-color-picker" />';
217 $html .= '<p class="description">'.$value['desc'].'</p>';
218 $html .= '</div>';
219 break;
220
221 case 'number':
222 $html .= '<div class="ultp-settings-field">';
223 $val = isset($option_data[$key]) ? $option_data[$key] : (isset($value['default']) ? $value['default'] : '');
224 $html .= '<input type="number" name="ultp_options['.$key.']" value="'.$val.'"/>';
225 $html .= '<p class="description">'.$value['desc'].'</p>';
226 $html .= '</div>';
227 break;
228
229 case 'switch':
230 $html .= '<div class="ultp-settings-field ultp-settings-field-inline">';
231 $val = isset($option_data[$key]) ? $option_data[$key] : (isset($value['default']) ? $value['default'] : '');
232 $html .= '<input type="checkbox" value="yes" name="ultp_options['.$key.']" '.($val == 'yes' ? 'checked' : '').' />';
233 $html .= '<p class="description">'.$value['desc'].'</p>';
234 $html .= '</div>';
235 break;
236
237 case 'multiselect':
238 $html .= '<div class="ultp-settings-field">';
239 $saved_val = isset($option_data[$key]) ? $option_data[$key] : (isset($value['default']) ? $value['default'] : []);
240 $html .= '<select style="height:190px;" name="ultp_options['.$key.'][]" multiple>';
241 if (!empty($value['options'])) {
242 foreach ($value['options'] as $val) {
243 if (!empty($saved_val) && is_array($saved_val)) {
244 $html .= '<option value="'.$val.'" '.(in_array( $val , $saved_val ) ? 'selected' : '' ).'>'.$val.'</option>';
245 } else {
246 $html .= '<option value="'.$val.'">'.$val.'</option>';
247 }
248 }
249 }
250 $html .= ' </select>';
251 $html .= '</div>';
252 break;
253
254 default:
255 # code...
256 break;
257 }
258 $html .= '</div>';
259 $html .= '</div>';
260 }
261 }
262
263 echo $html;
264 }
265
266 /**
267 * Settings page output
268 */
269 public function create_admin_page() {
270 $data = self::get_option_settings();
271 ?>
272 <div class="ultp-option-body">
273
274 <?php require_once ULTP_PATH . 'classes/options/Heading.php'; ?>
275
276 <?php $section = isset($_GET['tab']) ? $_GET['tab'] :'general'; ?>
277 <div class="ultp-tab-wrap">
278 <div class="ultp-tab-title-wrap">
279 <?php foreach ($data as $key => $value) {
280 if (isset($value['label'])) { ?>
281 <div data-title="<?php echo $key; ?>" class="ultp-tab-title<?php if($section == $key){ echo ' active'; } ?>"><?php echo $value['label']; ?></div>
282 <?php }
283 } ?>
284 <div data-title="changelog" class="ultp-tab-title<?php if($section == 'changelog'){ echo ' active'; } ?>"><?php _e('Changelog', 'ultimate-post'); ?></div>
285 </div>
286 <div class="ultp-content-wrap">
287 <form method="post" action="options.php">
288 <div class="ultp-settings">
289 <input type="hidden" name="option_page" value="ultp_options" />
290 <input type="hidden" name="action" value="update" />
291 <?php echo wp_nonce_field( "ultp_options-options" ); ?>
292 <?php foreach ($data as $key => $value) {
293 if (isset($value['attr'])) { ?>
294 <div class="ultp-tab-content<?php if($section == $key){ echo ' active'; } ?>">
295 <div class="ultp-tab-overview">
296 <?php $this->get_settings_data( $value['attr'] ); ?>
297 </div>
298 </div>
299 <?php }
300 } ?>
301 <div class="ultp-tab-content<?php if($section == 'changelog'){ echo ' active'; } ?>"><!-- #Changelog Content -->
302 <?php $this->get_changelog_data(); ?>
303 </div>
304 <div class="ultp-settings-wrap ultp-submit-button">
305 <div></div><?php echo get_submit_button(); ?>
306 </div>
307 </div>
308 </form>
309 </div>
310 </div>
311
312 <script type="text/javascript">
313 jQuery( document ).ready(function() {
314 jQuery( document ).on( "click", '.ultp-tab-title', function(e){
315 jQuery(this).closest('.ultp-tab-wrap').find('.ultp-tab-title').removeClass('active').eq(jQuery(this).index()).addClass('active')
316 jQuery(this).closest('.ultp-tab-wrap').find('.ultp-tab-content').removeClass('active').eq(jQuery(this).index()).addClass('active');
317 let refresh = window.location.protocol + "//" + window.location.host + window.location.pathname + '?page=ultp-option-settings&tab='+jQuery(this).data('title');
318 window.history.pushState({ path: refresh }, '', refresh);
319 jQuery('input[name=_wp_http_referer]').val(window.location.pathname + '?page=ultp-option-settings&tab=general');
320 });
321 });
322 </script>
323 </div>
324
325 <?php }
326
327
328 }