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

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