| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly! |
| 4 |
} |
| 5 |
|
| 6 |
if ( ! class_exists( 'WPSC_Appearence_Dashboard' ) ) : |
| 7 |
|
| 8 |
final class WPSC_Appearence_Dashboard { |
| 9 |
|
| 10 |
/** |
| 11 |
* Initialize this class |
| 12 |
* |
| 13 |
* @return void |
| 14 |
*/ |
| 15 |
public static function init() { |
| 16 |
|
| 17 |
// user interface. |
| 18 |
add_action( 'wp_ajax_wpsc_get_ap_dashboard', array( __CLASS__, 'load_settings_ui' ) ); |
| 19 |
add_action( 'wp_ajax_wpsc_set_ap_dashboard', array( __CLASS__, 'save_settings' ) ); |
| 20 |
add_action( 'wp_ajax_wpsc_reset_ap_dashboard', array( __CLASS__, 'reset_settings' ) ); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Reset settings |
| 25 |
* |
| 26 |
* @return void |
| 27 |
*/ |
| 28 |
public static function reset() { |
| 29 |
|
| 30 |
update_option( |
| 31 |
'wpsc-ap-dashboard', |
| 32 |
array( |
| 33 |
'card-body-bg-color' => '#f9f9f9', |
| 34 |
'card-body-svg-color' => '#777', |
| 35 |
'card-body-text-color' => '#2c3e50', |
| 36 |
'widget-body-bg-color' => '#f9f9f9', |
| 37 |
'widget-body-svg-color' => '#777', |
| 38 |
'widget-body-text-color' => '#2c3e50', |
| 39 |
|
| 40 |
) |
| 41 |
); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Get general settings |
| 46 |
* |
| 47 |
* @return void |
| 48 |
*/ |
| 49 |
public static function load_settings_ui() { |
| 50 |
|
| 51 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 52 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 53 |
} |
| 54 |
|
| 55 |
$settings = get_option( 'wpsc-ap-dashboard' ); |
| 56 |
?> |
| 57 |
<form action="#" onsubmit="return false;" class="wpsc-frm-ap-dash"> |
| 58 |
|
| 59 |
<div class="wpsc-input-group"> |
| 60 |
<div class="label-container"> |
| 61 |
<label for=""><?php esc_attr_e( 'Cards', 'supportcandy' ); ?></label> |
| 62 |
</div> |
| 63 |
<table class="wpsc-ap-table"> |
| 64 |
<tr> |
| 65 |
<td><?php esc_attr_e( 'Background color', 'supportcandy' ); ?></td> |
| 66 |
<td><?php esc_attr_e( 'Text color', 'supportcandy' ); ?></td> |
| 67 |
<td><?php esc_attr_e( 'Svg color', 'supportcandy' ); ?></td> |
| 68 |
</tr> |
| 69 |
<tr> |
| 70 |
<td><input class="wpsc-color-picker" type="text" name="card-body-bg-color" value="<?php echo esc_attr( $settings['card-body-bg-color'] ); ?>"></td> |
| 71 |
<td><input class="wpsc-color-picker" type="text" name="card-body-text-color" value="<?php echo esc_attr( $settings['card-body-text-color'] ); ?>"></td> |
| 72 |
<td><input class="wpsc-color-picker" type="text" name="card-body-svg-color" value="<?php echo esc_attr( $settings['card-body-svg-color'] ); ?>"></td> |
| 73 |
</tr> |
| 74 |
</table> |
| 75 |
</div> |
| 76 |
|
| 77 |
<div class="wpsc-input-group"> |
| 78 |
<div class="label-container"> |
| 79 |
<label for=""><?php esc_attr_e( 'Widget', 'supportcandy' ); ?></label> |
| 80 |
</div> |
| 81 |
<table class="wpsc-ap-table"> |
| 82 |
<tr> |
| 83 |
<td><?php esc_attr_e( 'Background color', 'supportcandy' ); ?></td> |
| 84 |
<td><?php esc_attr_e( 'Text color', 'supportcandy' ); ?></td> |
| 85 |
<td><?php esc_attr_e( 'Svg color', 'supportcandy' ); ?></td> |
| 86 |
</tr> |
| 87 |
<tr> |
| 88 |
<td><input class="wpsc-color-picker" type="text" name="widget-body-bg-color" value="<?php echo esc_attr( $settings['widget-body-bg-color'] ); ?>"></td> |
| 89 |
<td><input class="wpsc-color-picker" type="text" name="widget-body-text-color" value="<?php echo esc_attr( $settings['widget-body-text-color'] ); ?>"></td> |
| 90 |
<td><input class="wpsc-color-picker" type="text" name="widget-body-svg-color" value="<?php echo esc_attr( $settings['widget-body-svg-color'] ); ?>"></td> |
| 91 |
</tr> |
| 92 |
</table> |
| 93 |
</div> |
| 94 |
|
| 95 |
<input type="hidden" name="action" value="wpsc_set_ap_dashboard"> |
| 96 |
<input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpsc_set_ap_dashboard' ) ); ?>"> |
| 97 |
|
| 98 |
<script>jQuery('.wpsc-color-picker').wpColorPicker();</script> |
| 99 |
</form> |
| 100 |
<div class="setting-footer-actions"> |
| 101 |
<button |
| 102 |
class="wpsc-button normal primary margin-right" |
| 103 |
onclick="wpsc_set_ap_dashboard(this);"> |
| 104 |
<?php esc_attr_e( 'Submit', 'supportcandy' ); ?></button> |
| 105 |
<button |
| 106 |
class="wpsc-button normal secondary" |
| 107 |
onclick="wpsc_reset_ap_dashboard(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_reset_ap_dashboard' ) ); ?>');"> |
| 108 |
<?php esc_attr_e( 'Reset default', 'supportcandy' ); ?></button> |
| 109 |
</div> |
| 110 |
|
| 111 |
<?php |
| 112 |
wp_die(); |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* Save settings |
| 117 |
* |
| 118 |
* @return void |
| 119 |
*/ |
| 120 |
public static function save_settings() { |
| 121 |
|
| 122 |
if ( check_ajax_referer( 'wpsc_set_ap_dashboard', '_ajax_nonce', false ) != 1 ) { |
| 123 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 124 |
} |
| 125 |
|
| 126 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 127 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 128 |
} |
| 129 |
|
| 130 |
update_option( |
| 131 |
'wpsc-ap-dashboard', |
| 132 |
array( |
| 133 |
'widget-body-bg-color' => isset( $_POST['widget-body-bg-color'] ) ? sanitize_text_field( wp_unslash( $_POST['widget-body-bg-color'] ) ) : '#f9f9f9', |
| 134 |
'widget-body-svg-color' => isset( $_POST['widget-body-svg-color'] ) ? sanitize_text_field( wp_unslash( $_POST['widget-body-svg-color'] ) ) : '#777', |
| 135 |
'widget-body-text-color' => isset( $_POST['widget-body-text-color'] ) ? sanitize_text_field( wp_unslash( $_POST['widget-body-text-color'] ) ) : '#2c3e50', |
| 136 |
'card-body-bg-color' => isset( $_POST['card-body-bg-color'] ) ? sanitize_text_field( wp_unslash( $_POST['card-body-bg-color'] ) ) : '#f9f9f9', |
| 137 |
'card-body-svg-color' => isset( $_POST['card-body-svg-color'] ) ? sanitize_text_field( wp_unslash( $_POST['card-body-svg-color'] ) ) : '#777', |
| 138 |
'card-body-text-color' => isset( $_POST['card-body-text-color'] ) ? sanitize_text_field( wp_unslash( $_POST['card-body-text-color'] ) ) : '#2c3e50', |
| 139 |
) |
| 140 |
); |
| 141 |
wp_die(); |
| 142 |
} |
| 143 |
|
| 144 |
/** |
| 145 |
* Reset settings to default |
| 146 |
* |
| 147 |
* @return void |
| 148 |
*/ |
| 149 |
public static function reset_settings() { |
| 150 |
|
| 151 |
if ( check_ajax_referer( 'wpsc_reset_ap_dashboard', '_ajax_nonce', false ) != 1 ) { |
| 152 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 153 |
} |
| 154 |
|
| 155 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 156 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 157 |
} |
| 158 |
self::reset(); |
| 159 |
wp_die(); |
| 160 |
} |
| 161 |
} |
| 162 |
endif; |
| 163 |
WPSC_Appearence_Dashboard::init(); |
| 164 |
|