| 1 |
<?php /** |
| 2 |
* @version 1.0 |
| 3 |
* @package Booking Manager |
| 4 |
* @category Content of Settings page |
| 5 |
* @author wpdevelop |
| 6 |
* |
| 7 |
* @web-site https://oplugins.com/ |
| 8 |
* @email info@oplugins.com |
| 9 |
* |
| 10 |
* @modified 2015-11-02 |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 14 |
|
| 15 |
|
| 16 |
/** Show Content |
| 17 |
* Update Content |
| 18 |
* Define Slug |
| 19 |
* Define where to show |
| 20 |
*/ |
| 21 |
class WPBM_Page_SettingsGeneral extends WPBM_Page_Structure { |
| 22 |
|
| 23 |
private $settings_api = false; |
| 24 |
|
| 25 |
public function in_page() { |
| 26 |
|
| 27 |
return 'oplugins';// 'wpbm-settings'; |
| 28 |
} |
| 29 |
|
| 30 |
/** Get Settings API class - define, show, update "Fields". |
| 31 |
* |
| 32 |
* @return object Settings API |
| 33 |
*/ |
| 34 |
public function settings_api(){ |
| 35 |
|
| 36 |
if ( $this->settings_api === false ) |
| 37 |
$this->settings_api = new WPBM_Settings_API_General(); |
| 38 |
|
| 39 |
return $this->settings_api; |
| 40 |
} |
| 41 |
|
| 42 |
public function tabs() { |
| 43 |
|
| 44 |
$tabs = array(); |
| 45 |
|
| 46 |
$tabs[ 'wpbm-settings' ] = array( |
| 47 |
'title' => __( 'Settings', 'booking-manager' ) // Title of TAB |
| 48 |
, 'page_title' => __( 'Settings', 'booking-manager' ) // Title of Page |
| 49 |
, 'hint' => __( 'Settings', 'booking-manager' ) // Hint |
| 50 |
, 'link' => '' // Can be skiped, then generated link based on Page and Tab tags. Or can be extenral link |
| 51 |
, 'position' => '' // 'left' || 'right' || '' |
| 52 |
, 'css_classes' => '' // CSS class(es) |
| 53 |
, 'icon' => '' // Icon - link to the real PNG img |
| 54 |
, 'font_icon' => 'glyphicon glyphicon-cog' // CSS definition of forn Icon |
| 55 |
, 'default' => ! true // Is this tab activated by default or not: true || false. |
| 56 |
); |
| 57 |
|
| 58 |
$subtabs = array(); |
| 59 |
|
| 60 |
/* |
| 61 |
$subtabs['wpbm-settings-listing'] = array( 'type' => 'goto-link' |
| 62 |
, 'title' => __('Misc', 'booking-manager') |
| 63 |
, 'show_section' => 'wpbm_general_settings_wpbm_misc_metabox' |
| 64 |
); |
| 65 |
|
| 66 |
$subtabs['wpbm-settings-menu-access'] = array( 'type' => 'goto-link' |
| 67 |
, 'title' => __('Plugin Menu', 'booking-manager') |
| 68 |
, 'show_section' => 'wpbm_general_settings_permissions_metabox' |
| 69 |
); |
| 70 |
|
| 71 |
$subtabs['wpbm-settings-uninstall'] = array( 'type' => 'goto-link' |
| 72 |
, 'title' => __('Uninstall', 'booking-manager') |
| 73 |
, 'show_section' => 'wpbm_general_settings_uninstall_metabox' |
| 74 |
); |
| 75 |
|
| 76 |
$subtabs['wpbm-settings-advanced'] = array( 'type' => 'goto-link' |
| 77 |
, 'title' => __('Advanced', 'booking-manager') |
| 78 |
, 'show_section' => 'wpbm_general_settings_advanced_metabox' |
| 79 |
); |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
$subtabs['form-save'] = array( |
| 84 |
'type' => 'button' |
| 85 |
, 'title' => __('Save Changes', 'booking-manager') |
| 86 |
, 'form' => 'wpbm_general_settings_form' |
| 87 |
); |
| 88 |
*/ |
| 89 |
|
| 90 |
$subtabs['general'] = array( |
| 91 |
'type' => 'subtab' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html' |
| 92 |
, 'title' => __('General Settings' , 'booking-manager') // Title of TAB |
| 93 |
, 'page_title' => __('General Settings', 'booking-manager') // Title of Page |
| 94 |
, 'hint' => __('General Settings' , 'booking-manager') // Hint |
| 95 |
, 'link' => '' // link |
| 96 |
, 'position' => '' // 'left' || 'right' || '' |
| 97 |
, 'css_classes' => '' // CSS class(es) |
| 98 |
//, 'icon' => 'http://.../icon.png' // Icon - link to the real PNG img |
| 99 |
//, 'font_icon' => 'glyphicon glyphicon-envelope' // CSS definition of Font Icon |
| 100 |
, 'default' => true // Is this sub tab activated by default or not: true || false. |
| 101 |
, 'disabled' => false // Is this sub tab deactivated: true || false. |
| 102 |
, 'checkbox' => false // or definition array for specific checkbox: array( 'checked' => true, 'name' => 'feature1_active_status' ) //, 'checkbox' => array( 'checked' => $is_checked, 'name' => 'enabled_active_status' ) |
| 103 |
, 'content' => 'content' // Function to load as conten of this TAB |
| 104 |
); |
| 105 |
|
| 106 |
$tabs[ 'wpbm-settings' ]['subtabs'] = $subtabs; |
| 107 |
|
| 108 |
return $tabs; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
public function content() { |
| 113 |
|
| 114 |
// Checking //////////////////////////////////////////////////////////// |
| 115 |
|
| 116 |
if ( ! $this->can_manage_settings() ) { |
| 117 |
wp_die( |
| 118 |
esc_html__( 'Sorry, you are not allowed to manage Booking Manager settings.', 'booking-manager' ) |
| 119 |
, esc_html__( 'Forbidden', 'booking-manager' ) |
| 120 |
, array( 'response' => 403 ) |
| 121 |
); |
| 122 |
} |
| 123 |
|
| 124 |
do_action( 'wpbm_hook_settings_page_header', array( 'page' => $this->in_page() ) ); // Define Notices Section and show some static messages, if needed. |
| 125 |
|
| 126 |
$is_can = apply_wpbm_filter('recheck_version', true); if ( ! $is_can ) { ?><script type="text/javascript"> jQuery(document).ready(function(){ jQuery( '.wpdvlp-sub-tabs').remove(); }); </script><?php return; } |
| 127 |
|
| 128 |
|
| 129 |
// Init Settings API & Get Data from DB //////////////////////////////// |
| 130 |
$this->settings_api(); // Define all fields and get values from DB |
| 131 |
|
| 132 |
// Submit ///////////////////////////////////////////////////////////// |
| 133 |
|
| 134 |
$submit_form_name = 'wpbm_general_settings_form'; // Define form name |
| 135 |
|
| 136 |
if ( isset( $_POST['is_form_sbmitted_'. $submit_form_name ] ) ) { |
| 137 |
|
| 138 |
// Nonce checking {Return false if invalid, 1 if generated between, 0-12 hours ago, 2 if generated between 12-24 hours ago. } |
| 139 |
$nonce_gen_time = check_admin_referer( 'wpbm_settings_page_' . $submit_form_name ); // Its stop show anything on submiting, if its not refear to the original page |
| 140 |
|
| 141 |
// Save Changes |
| 142 |
$this->update(); |
| 143 |
} |
| 144 |
//$wpbm_user_role_master = get_wpbm_option( 'wpbm_user_role_master' ); // O L D W A Y: Get Fields Data |
| 145 |
|
| 146 |
|
| 147 |
// JavaScript: Tooltips, Popover, Datepick (js & css) ////////////////// |
| 148 |
echo '<span class="wpdevelop">'; |
| 149 |
wpbm_js_for_items_page(); |
| 150 |
echo '</span>'; |
| 151 |
|
| 152 |
|
| 153 |
?><div class="clear"></div><?php |
| 154 |
|
| 155 |
if ( 1 ) { |
| 156 |
// Scroll links //////////////////////////////////////////////////////// |
| 157 |
?> |
| 158 |
<div class="wpdvlp-sub-tabs" style="background:none;border:none;box-shadow: none;padding:0;"><span class="nav-tabs" style="text-align:right;"> |
| 159 |
<a onclick="javascript:wpbm_scroll_to('#wpbm_general_settings_wpbm_misc_metabox' );" href="javascript:void(0);" original-title="" class="nav-tab go-to-link"><span><?php |
| 160 |
echo ucwords( __('Misc', 'booking-manager') ); ?></span></a> |
| 161 |
</span> |
| 162 |
<span class="nav-tabs" style="text-align:right;"> |
| 163 |
<a onclick="javascript:wpbm_scroll_to('#wpbm_general_settings_permissions_metabox' );" href="javascript:void(0);" original-title="" class="nav-tab go-to-link"><span><?php |
| 164 |
echo ucwords( __('Plugin Menu', 'booking-manager') ); ?></span></a> |
| 165 |
</span><span class="nav-tabs" style="text-align:right;"> |
| 166 |
<a onclick="javascript:wpbm_scroll_to('#wpbm_general_settings_uninstall_metabox' );" href="javascript:void(0);" original-title="" class="nav-tab go-to-link"><span><?php |
| 167 |
echo ucwords( __('Uninstall', 'booking-manager') ); ?></span></a> |
| 168 |
</span><span class="nav-tabs" style="text-align:right;"> |
| 169 |
<a onclick="javascript:wpbm_scroll_to('#wpbm_general_settings_advanced_metabox' );" href="javascript:void(0);" original-title="" class="nav-tab go-to-link"><span><?php |
| 170 |
echo ucwords( __('Advanced', 'booking-manager') ); ?></span></a> |
| 171 |
</span></div> |
| 172 |
<?php |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
// Content //////////////////////////////////////////////////////////// |
| 177 |
?> |
| 178 |
<div class="clear" style="margin-bottom:10px;"></div> |
| 179 |
<span class="metabox-holder"> |
| 180 |
<form name="<?php echo $submit_form_name; ?>" id="<?php echo $submit_form_name; ?>" action="" method="post"> |
| 181 |
<?php |
| 182 |
// N o n c e field, and key for checking S u b m i t |
| 183 |
wp_nonce_field( 'wpbm_settings_page_' . $submit_form_name ); |
| 184 |
?><input type="hidden" name="is_form_sbmitted_<?php echo $submit_form_name; ?>" id="is_form_sbmitted_<?php echo $submit_form_name; ?>" value="1" /> |
| 185 |
|
| 186 |
<div class="wpbm_settings_row wpbm_settings_row_left" > |
| 187 |
|
| 188 |
<?php // wpbm_open_meta_box_section( 'wpbm_general_settings_calendar', __('General', 'booking-manager') ); ?> |
| 189 |
|
| 190 |
<?php // $this->settings_api()->show( 'general' ); ?> |
| 191 |
|
| 192 |
<?php // wpbm_close_meta_box_section(); ?> |
| 193 |
|
| 194 |
|
| 195 |
<?php wpbm_open_meta_box_section( 'wpbm_general_settings_wpbm_misc', __('Miscellaneous', 'booking-manager') ); ?> |
| 196 |
|
| 197 |
<?php $this->settings_api()->show( 'wpbm_listing' ); ?> |
| 198 |
|
| 199 |
<?php wpbm_close_meta_box_section(); ?> |
| 200 |
|
| 201 |
|
| 202 |
<?php wpbm_open_meta_box_section( 'wpbm_general_settings_permissions', __('Plugin Menu', 'booking-manager') ); ?> |
| 203 |
|
| 204 |
<?php $this->settings_api()->show( 'permissions' ); ?> |
| 205 |
|
| 206 |
<?php wpbm_close_meta_box_section(); ?> |
| 207 |
|
| 208 |
|
| 209 |
<?php wpbm_open_meta_box_section( 'wpbm_general_settings_uninstall', __('Uninstall / deactivation', 'booking-manager') ); ?> |
| 210 |
|
| 211 |
<?php $this->settings_api()->show( 'uninstall' ); ?> |
| 212 |
|
| 213 |
<?php wpbm_close_meta_box_section(); ?> |
| 214 |
|
| 215 |
</div> |
| 216 |
<div class="wpbm_settings_row wpbm_settings_row_right"> |
| 217 |
|
| 218 |
<?php wpbm_open_meta_box_section( 'wpbm_general_settings_information', __('Information', 'booking-manager') ); ?> |
| 219 |
|
| 220 |
<?php $this->settings_api()->show( 'information' ); ?> |
| 221 |
|
| 222 |
<?php wpbm_close_meta_box_section(); ?> |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
<?php wpbm_open_meta_box_section( 'wpbm_general_settings_advanced', __('Advanced', 'booking-manager') ); ?> |
| 228 |
|
| 229 |
<?php $this->settings_api()->show( 'advanced' ); ?> |
| 230 |
|
| 231 |
<?php wpbm_close_meta_box_section(); ?> |
| 232 |
|
| 233 |
</div> |
| 234 |
<div class="clear"></div> |
| 235 |
<input type="submit" value="<?php _e('Save Changes', 'booking-manager'); ?>" class="button button-primary wpbm_submit_button" /> |
| 236 |
</form> |
| 237 |
<?php if ( ( isset( $_GET['system_info'] ) ) && ( $_GET['system_info'] == 'show' ) ) { ?> |
| 238 |
|
| 239 |
<div class="clear" style="height:30px;"></div> |
| 240 |
|
| 241 |
<?php wpbm_open_meta_box_section( 'wpbm_general_settings_system_info', 'System Info' ); ?> |
| 242 |
|
| 243 |
<?php wpbm_system_info(); ?> |
| 244 |
|
| 245 |
<?php wpbm_close_meta_box_section(); ?> |
| 246 |
|
| 247 |
<?php } ?> |
| 248 |
|
| 249 |
</span> |
| 250 |
<?php |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
do_action( 'wpbm_hook_settings_page_footer', 'general_settings' ); |
| 255 |
|
| 256 |
//debuge( 'Content <strong>' . basename(__FILE__ ) . '</strong> <span style="font-size:9px;">' . __FILE__ . '</span>'); |
| 257 |
} |
| 258 |
|
| 259 |
|
| 260 |
public function update() { |
| 261 |
|
| 262 |
if ( ! $this->can_manage_settings() ) { |
| 263 |
wp_die( |
| 264 |
esc_html__( 'Sorry, you are not allowed to manage Booking Manager settings.', 'booking-manager' ) |
| 265 |
, esc_html__( 'Forbidden', 'booking-manager' ) |
| 266 |
, array( 'response' => 403 ) |
| 267 |
); |
| 268 |
} |
| 269 |
|
| 270 |
//debuge($_POST); |
| 271 |
$validated_fields = $this->settings_api()->validate_post(); // Get Validated Settings fields in $_POST request. |
| 272 |
|
| 273 |
$validated_fields = apply_filters( 'wpbm_settings_validate_fields_before_saving', $validated_fields ); //Hook for validated fields. |
| 274 |
//debuge($validated_fields); |
| 275 |
// Skip saving specific option, for example in Demo mode. |
| 276 |
// unset($validated_fields['wpbm_start_day_weeek']); |
| 277 |
|
| 278 |
$this->settings_api()->save_to_db( $validated_fields ); // Save fields to DB |
| 279 |
wpbm_show_changes_saved_message(); |
| 280 |
|
| 281 |
//debuge( basename(__FILE__), 'UPDATE', $_POST, $validated_fields); |
| 282 |
|
| 283 |
// O L D W A Y: Saving Fields Data |
| 284 |
// update_wpbm_option( 'wpbm_is_delete_if_deactive' |
| 285 |
// , WPBM_Settings_API::validate_checkbox_post('wpbm_is_delete_if_deactive') ); |
| 286 |
// ( (isset( $_POST['wpbm_is_delete_if_deactive'] ))?'On':'Off') ); |
| 287 |
|
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
/** |
| 292 |
* Settings are global plugin options and require administrator-level access. |
| 293 |
* |
| 294 |
* @return bool |
| 295 |
*/ |
| 296 |
private function can_manage_settings() { |
| 297 |
|
| 298 |
return current_user_can( 'manage_options' ); |
| 299 |
} |
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
//if ( $is_other_tab ) { |
| 305 |
// |
| 306 |
// if ( ( ! isset( $_GET['tab'] ) ) || ( $_GET['tab'] == 'general' ) ) { // If tab was not selected or selected default, then redirect it to the "form" tab. |
| 307 |
// $_GET['tab'] = 'form'; |
| 308 |
// } |
| 309 |
//} else { |
| 310 |
// add_action('wpbm_menu_created', array( new WPBM_Page_SettingsGeneral() , '__construct') ); // Executed after creation of Menu |
| 311 |
//} |
| 312 |
|
| 313 |
add_action('wpbm_menu_created', array( new WPBM_Page_SettingsGeneral() , '__construct') ); // Executed after creation of Menu |
| 314 |
|
| 315 |
|