| 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 = get_option( 'ultp_options' ); |
| 143 |
if(!$option_data){ |
| 144 |
$option_data = ultimate_post()->init_set_data(); |
| 145 |
} |
| 146 |
$data = self::get_option_settings(); |
| 147 |
$html .= '<div class="ultp-settings">'; |
| 148 |
$html .= '<input type="hidden" name="option_page" value="ultp_options" />'; |
| 149 |
$html .= '<input type="hidden" name="action" value="update" />'; |
| 150 |
$html .= wp_nonce_field( "ultp_options-options" ); |
| 151 |
foreach ($data as $key => $value) { |
| 152 |
$html .= '<div class="ultp-settings-wrap">'; |
| 153 |
$html .= '<div class="ultp-settings-label">'.$value['label'].'</div>'; |
| 154 |
$html .= '<div class="ultp-settings-field-wrap">'; |
| 155 |
switch ($value['type']) { |
| 156 |
|
| 157 |
case 'select': |
| 158 |
$html .= '<div class="ultp-settings-field">'; |
| 159 |
$val = isset($option_data[$key]) ? $option_data[$key] : (isset($value['default']) ? $value['default'] : ''); |
| 160 |
$html .= '<select name="ultp_options['.$key.']">'; |
| 161 |
foreach ( $value['options'] as $id => $label ) { |
| 162 |
$html .= '<option value="'.$id.'" '.( $val == $id ? ' selected="selected"':'').'>'; |
| 163 |
$html .= strip_tags( $label ); |
| 164 |
$html .= '</option>'; |
| 165 |
} |
| 166 |
$html .= '</select>'; |
| 167 |
$html .= '<p class="description">'.$value['desc'].'</p>'; |
| 168 |
$html .= '</div>'; |
| 169 |
break; |
| 170 |
|
| 171 |
case 'color': |
| 172 |
$html .= '<div class="ultp-settings-field">'; |
| 173 |
$val = isset($option_data[$key]) ? $option_data[$key] : (isset($value['default']) ? $value['default'] : ''); |
| 174 |
$html .= '<input name="ultp_options['.$key.']" value="'.$val.'" class="ultp-color-picker" />'; |
| 175 |
$html .= '<p class="description">'.$value['desc'].'</p>'; |
| 176 |
$html .= '</div>'; |
| 177 |
break; |
| 178 |
|
| 179 |
case 'number': |
| 180 |
$html .= '<div class="ultp-settings-field">'; |
| 181 |
$val = isset($option_data[$key]) ? $option_data[$key] : (isset($value['default']) ? $value['default'] : ''); |
| 182 |
$html .= '<input type="number" name="ultp_options['.$key.']" value="'.$val.'"/>'; |
| 183 |
$html .= '<p class="description">'.$value['desc'].'</p>'; |
| 184 |
$html .= '</div>'; |
| 185 |
break; |
| 186 |
|
| 187 |
case 'switch': |
| 188 |
$html .= '<div class="ultp-settings-field ultp-settings-field-inline">'; |
| 189 |
$val = isset($option_data[$key]) ? $option_data[$key] : (isset($value['default']) ? $value['default'] : ''); |
| 190 |
$html .= '<input type="checkbox" value="yes" name="ultp_options['.$key.']" '.($val == 'yes' ? 'checked' : '').' />'; |
| 191 |
$html .= '<p class="description">'.$value['desc'].'</p>'; |
| 192 |
$html .= '</div>'; |
| 193 |
break; |
| 194 |
|
| 195 |
default: |
| 196 |
# code... |
| 197 |
break; |
| 198 |
|
| 199 |
} |
| 200 |
$html .= '</div>'; |
| 201 |
$html .= '</div>'; |
| 202 |
} |
| 203 |
$html .= '<div class="ultp-settings-wrap ultp-submit-button">'; |
| 204 |
$html .= '<div></div>'.get_submit_button(); |
| 205 |
$html .= '</div>'; |
| 206 |
|
| 207 |
$html .= '</div>'; |
| 208 |
echo '<form method="post" action="options.php">'.$html.'</form>'; |
| 209 |
} |
| 210 |
|
| 211 |
/** |
| 212 |
* Settings page output |
| 213 |
*/ |
| 214 |
public static function create_admin_page() { ?> |
| 215 |
<div class="ultp-option-body"> |
| 216 |
|
| 217 |
<?php require_once ULTP_PATH . 'classes/options/Heading.php'; ?> |
| 218 |
|
| 219 |
<?php $section = isset($_GET['tab']) ? $_GET['tab'] :'settings'; ?> |
| 220 |
<div class="ultp-tab-wrap"> |
| 221 |
<div class="ultp-tab-title-wrap"> |
| 222 |
<div data-title="settings" class="ultp-tab-title<?php if($section == 'settings'){ echo ' active'; } ?>"><?php _e('General Settings', 'ultimate-post'); ?></div> |
| 223 |
<div data-title="changelog" class="ultp-tab-title<?php if($section == 'changelog'){ echo ' active'; } ?>"><?php _e('Changelog', 'ultimate-post'); ?></div> |
| 224 |
</div> |
| 225 |
<div class="ultp-content-wrap"> |
| 226 |
<div class="ultp-tab-content<?php if($section == 'settings'){ echo ' active'; } ?>"><!-- #Settings Content --> |
| 227 |
<div class="ultp-overview"><!-- #Settings Content --> |
| 228 |
<?php self::get_settings_data(); ?> |
| 229 |
</div> |
| 230 |
</div> |
| 231 |
<div class="ultp-tab-content<?php if($section == 'changelog'){ echo ' active'; } ?>"><!-- #Changelog Content --> |
| 232 |
<?php self::get_changelog_data(); ?> |
| 233 |
</div> |
| 234 |
</div> |
| 235 |
</div> |
| 236 |
|
| 237 |
<script type="text/javascript"> |
| 238 |
jQuery( document ).ready(function() { |
| 239 |
jQuery( document ).on( "click", '.ultp-tab-title', function(e){ |
| 240 |
jQuery(this).closest('.ultp-tab-wrap').find('.ultp-tab-title').removeClass('active').eq(jQuery(this).index()).addClass('active') |
| 241 |
jQuery(this).closest('.ultp-tab-wrap').find('.ultp-tab-content').removeClass('active').eq(jQuery(this).index()).addClass('active'); |
| 242 |
let refresh = window.location.protocol + "//" + window.location.host + window.location.pathname + '?page=ultp-settings&tab='+jQuery(this).data('title'); |
| 243 |
window.history.pushState({ path: refresh }, '', refresh); |
| 244 |
jQuery('input[name=_wp_http_referer]').val(window.location.pathname + '?page=ultp-settings&tab=settings'); |
| 245 |
}); |
| 246 |
}); |
| 247 |
</script> |
| 248 |
</div> |
| 249 |
|
| 250 |
<?php } |
| 251 |
|
| 252 |
|
| 253 |
} |