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

265 lines 12.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();
22 foreach ($settings as $key => $setting) {
23 if (!empty($key)) {
24 $options[$key] = isset($options[$key]) ? sanitize_text_field($options[$key]) : '';
25 }
26 }
27 $default = ultimate_post()->get_setting();
28 if(!empty($default)){
29 $options = array_merge($default, $options);
30 }
31 }
32 return $options;
33 }
34
35 /**
36 * Settings Field Return
37 */
38 public function get_option_settings(){
39 return apply_filters('ultp_settings', array(
40 'css_save_as' => array(
41 'type' => 'select',
42 'label' => __('CSS Add Via', 'ultimate-post'),
43 'options' => array(
44 'wp_head' => __( 'Header - (Internal)','ultimate-post' ),
45 'filesystem' => __( 'File System - (External)','ultimate-post' ),
46 ),
47 'default' => 'wp_head',
48 'desc' => __('Select where you want to save CSS.', 'ultimate-post')
49 ),
50 'preloader_style' => array(
51 'type' => 'select',
52 'label' => __('Preloader Style', 'ultimate-post'),
53 'options' => array(
54 'style1' => __( 'Preloader Style 1','ultimate-post' ),
55 'style2' => __( 'Preloader Style 2','ultimate-post' ),
56 ),
57 'default' => 'style1',
58 'desc' => __('Select Preloader Style.', 'ultimate-post')
59 ),
60 'container_width' => array(
61 'type' => 'number',
62 'label' => __('Container Width', 'ultimate-post'),
63 'default' => '1140',
64 'desc' => __('Change Container Width of the Page Template(Gutenberg Post Blocks Template).', 'ultimate-post')
65 ),
66 'editor_container' => array(
67 'type' => 'select',
68 'label' => __('Editor Container', 'ultimate-post'),
69 'options' => array(
70 'full_width' => __( 'Full Width','ultimate-post' ),
71 'theme_default' => __( 'Theme Default','ultimate-post' )
72 ),
73 'default' => 'full_width',
74 'desc' => __('Select Editor Container Width.', 'ultimate-post')
75 ),
76 'hide_import_btn' => array(
77 'type' => 'switch',
78 'label' => __('Hide Import Button', 'ultimate-post'),
79 'default' => '',
80 'desc' => __('Hide Import Layout Button from the Gutenberg Editor.', 'ultimate-post')
81 ),
82 'disable_image_size' => array(
83 'type' => 'switch',
84 'label' => __('Disable Image Size', 'ultimate-post'),
85 'default' => '',
86 'desc' => __('Disable Image Size of the Plugins.', 'ultimate-post')
87 ),
88 ));
89 }
90
91
92 /**
93 * Changelog Data
94 */
95 public function get_changelog_data() {
96 $html = '';
97 $resource_data = file_get_contents(ULTP_PATH.'/readme.txt', "r");
98 $data = array();
99 if ($resource_data) {
100 $resource_data = explode('== Changelog ==', $resource_data);
101 if (isset($resource_data[1])) {
102 $resource_data = $resource_data[1];
103 $resource_data = explode("\n", $resource_data);
104 $inner = false;
105 $count = -1;
106
107 foreach ($resource_data as $element) {
108 if ($element){
109 if (substr_count($element, '=') > 1) {
110 $count++;
111 $temp = trim(str_replace('=', '', $element));
112 if (strpos($temp, '-') !== false) {
113 $temp = explode('-', $temp);
114 $data[$count]['date'] = trim($temp[1]);
115 $data[$count]['version'] = trim($temp[0]);
116 }
117 }
118 if (strpos($element, '* New:') !== false) {
119 $data[$count]['new'][] = trim(str_replace('* New:', '', $element));
120 }
121 if (strpos($element, '* Fix:') !== false) {
122 $data[$count]['fix'][] = trim(str_replace('* Fix:', '', $element));
123 }
124 if (strpos($element, '* Update:') !== false) {
125 $data[$count]['update'][] = trim(str_replace('* Update:', '', $element));
126 }
127 }
128 }
129 }
130 }
131 if (!empty($data)) {
132 foreach ($data as $k => $inner_data) {
133 $html .= '<div class="ultp-changelog-wrap">';
134 foreach ($inner_data as $key => $changelog) {
135 if ($key == 'date') {
136 $html .= '<div class="ultp-changelog-date">'.__('Released on ', 'ultimate-post').' '.$changelog.'</div>';
137 } elseif($key == 'version') {
138 $html .= '<div class="ultp-changelog-version">'.__('Version', 'ultimate-post').' : '.$changelog.'</div>';
139 } else {
140 foreach ($changelog as $keyword => $val) {
141 $html .= '<div class="ultp-changelog-title"><span class="changelog-'.$key.'">'.$key.'</span>'.$val.'</div>';
142 }
143 }
144 }
145 $html .= '</div>';
146 }
147 }
148 echo $html;
149 }
150
151
152 /**
153 * Settings page output
154 */
155 public function get_settings_data() {
156 $html = '';
157 $option_data = ultimate_post()->get_setting();
158 $data = $this->get_option_settings();
159 $html .= '<div class="ultp-settings">';
160 $html .= '<input type="hidden" name="option_page" value="ultp_options" />';
161 $html .= '<input type="hidden" name="action" value="update" />';
162 $html .= wp_nonce_field( "ultp_options-options" );
163 foreach ($data as $key => $value) {
164 $html .= '<div class="ultp-settings-wrap">';
165 $html .= '<div class="ultp-settings-label">'.$value['label'].'</div>';
166 $html .= '<div class="ultp-settings-field-wrap">';
167 switch ($value['type']) {
168
169 case 'select':
170 $html .= '<div class="ultp-settings-field">';
171 $val = isset($option_data[$key]) ? $option_data[$key] : (isset($value['default']) ? $value['default'] : '');
172 $html .= '<select name="ultp_options['.$key.']">';
173 foreach ( $value['options'] as $id => $label ) {
174 $html .= '<option value="'.$id.'" '.( $val == $id ? ' selected="selected"':'').'>';
175 $html .= strip_tags( $label );
176 $html .= '</option>';
177 }
178 $html .= '</select>';
179 $html .= '<p class="description">'.$value['desc'].'</p>';
180 $html .= '</div>';
181 break;
182
183 case 'color':
184 $html .= '<div class="ultp-settings-field">';
185 $val = isset($option_data[$key]) ? $option_data[$key] : (isset($value['default']) ? $value['default'] : '');
186 $html .= '<input name="ultp_options['.$key.']" value="'.$val.'" class="ultp-color-picker" />';
187 $html .= '<p class="description">'.$value['desc'].'</p>';
188 $html .= '</div>';
189 break;
190
191 case 'number':
192 $html .= '<div class="ultp-settings-field">';
193 $val = isset($option_data[$key]) ? $option_data[$key] : (isset($value['default']) ? $value['default'] : '');
194 $html .= '<input type="number" name="ultp_options['.$key.']" value="'.$val.'"/>';
195 $html .= '<p class="description">'.$value['desc'].'</p>';
196 $html .= '</div>';
197 break;
198
199 case 'switch':
200 $html .= '<div class="ultp-settings-field ultp-settings-field-inline">';
201 $val = isset($option_data[$key]) ? $option_data[$key] : (isset($value['default']) ? $value['default'] : '');
202 $html .= '<input type="checkbox" value="yes" name="ultp_options['.$key.']" '.($val == 'yes' ? 'checked' : '').' />';
203 $html .= '<p class="description">'.$value['desc'].'</p>';
204 $html .= '</div>';
205 break;
206
207 default:
208 # code...
209 break;
210
211 }
212 $html .= '</div>';
213 $html .= '</div>';
214 }
215 $html .= '<div class="ultp-settings-wrap ultp-submit-button">';
216 $html .= '<div></div>'.get_submit_button();
217 $html .= '</div>';
218
219 $html .= '</div>';
220 echo '<form method="post" action="options.php">'.$html.'</form>';
221 }
222
223 /**
224 * Settings page output
225 */
226 public function create_admin_page() { ?>
227 <div class="ultp-option-body">
228
229 <?php require_once ULTP_PATH . 'classes/options/Heading.php'; ?>
230
231 <?php $section = isset($_GET['tab']) ? $_GET['tab'] :'settings'; ?>
232 <div class="ultp-tab-wrap">
233 <div class="ultp-tab-title-wrap">
234 <div data-title="settings" class="ultp-tab-title<?php if($section == 'settings'){ echo ' active'; } ?>"><?php _e('General Settings', 'ultimate-post'); ?></div>
235 <div data-title="changelog" class="ultp-tab-title<?php if($section == 'changelog'){ echo ' active'; } ?>"><?php _e('Changelog', 'ultimate-post'); ?></div>
236 </div>
237 <div class="ultp-content-wrap">
238 <div class="ultp-tab-content<?php if($section == 'settings'){ echo ' active'; } ?>"><!-- #Settings Content -->
239 <div class="ultp-overview"><!-- #Settings Content -->
240 <?php $this->get_settings_data(); ?>
241 </div>
242 </div>
243 <div class="ultp-tab-content<?php if($section == 'changelog'){ echo ' active'; } ?>"><!-- #Changelog Content -->
244 <?php $this->get_changelog_data(); ?>
245 </div>
246 </div>
247 </div>
248
249 <script type="text/javascript">
250 jQuery( document ).ready(function() {
251 jQuery( document ).on( "click", '.ultp-tab-title', function(e){
252 jQuery(this).closest('.ultp-tab-wrap').find('.ultp-tab-title').removeClass('active').eq(jQuery(this).index()).addClass('active')
253 jQuery(this).closest('.ultp-tab-wrap').find('.ultp-tab-content').removeClass('active').eq(jQuery(this).index()).addClass('active');
254 let refresh = window.location.protocol + "//" + window.location.host + window.location.pathname + '?page=ultp-settings&tab='+jQuery(this).data('title');
255 window.history.pushState({ path: refresh }, '', refresh);
256 jQuery('input[name=_wp_http_referer]').val(window.location.pathname + '?page=ultp-settings&tab=settings');
257 });
258 });
259 </script>
260 </div>
261
262 <?php }
263
264
265 }