| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly! |
| 4 |
} |
| 5 |
|
| 6 |
if ( ! class_exists( 'WPSC_TE_Advanced' ) ) : |
| 7 |
|
| 8 |
final class WPSC_TE_Advanced { |
| 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_te_advanced', array( __CLASS__, 'load_settings_ui' ) ); |
| 19 |
add_action( 'wp_ajax_wpsc_set_te_advanced', array( __CLASS__, 'save_settings' ) ); |
| 20 |
add_action( 'wp_ajax_wpsc_reset_te_advanced', array( __CLASS__, 'reset_settings' ) ); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Reset settings |
| 25 |
* |
| 26 |
* @return void |
| 27 |
*/ |
| 28 |
public static function reset() { |
| 29 |
|
| 30 |
$advanced = apply_filters( |
| 31 |
'wpsc_te_advanced', |
| 32 |
array( |
| 33 |
'html-pasting' => 0, |
| 34 |
) |
| 35 |
); |
| 36 |
update_option( 'wpsc-te-advanced', $advanced ); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Settings user interface |
| 41 |
* |
| 42 |
* @return void |
| 43 |
*/ |
| 44 |
public static function load_settings_ui() { |
| 45 |
|
| 46 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 47 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 48 |
} |
| 49 |
$settings = get_option( 'wpsc-te-advanced', array() );?> |
| 50 |
|
| 51 |
<form action="#" onsubmit="return false;" class="wpsc-frm-te-advanced"> |
| 52 |
<div class="wpsc-dock-container"> |
| 53 |
<?php |
| 54 |
printf( |
| 55 |
/* translators: Click here to see the documentation */ |
| 56 |
esc_attr__( '%s to see the documentation!', 'supportcandy' ), |
| 57 |
'<a href="https://supportcandy.net/docs/rich-text-editor/" target="_blank">' . esc_attr__( 'Click here', 'supportcandy' ) . '</a>' |
| 58 |
); |
| 59 |
?> |
| 60 |
</div> |
| 61 |
<div class="wpsc-input-group"> |
| 62 |
<div class="label-container"> |
| 63 |
<label for=""><?php esc_attr_e( 'HTML pasting', 'supportcandy' ); ?></label> |
| 64 |
</div> |
| 65 |
<select id="wpsc-te-hp" name="html-pasting"> |
| 66 |
<option <?php selected( $settings['html-pasting'], 1 ); ?> value="1"><?php esc_attr_e( 'Enable', 'supportcandy' ); ?></option> |
| 67 |
<option <?php selected( $settings['html-pasting'], 0 ); ?> value="0"><?php esc_attr_e( 'Disable', 'supportcandy' ); ?></option> |
| 68 |
</select> |
| 69 |
</div> |
| 70 |
<?php do_action( 'wpsc_te_advanced' ); ?> |
| 71 |
<input type="hidden" name="action" value="wpsc_set_te_advanced"> |
| 72 |
<input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpsc_set_te_advanced' ) ); ?>"> |
| 73 |
</form> |
| 74 |
<div class="setting-footer-actions"> |
| 75 |
<button |
| 76 |
class="wpsc-button normal primary margin-right" |
| 77 |
onclick="wpsc_set_te_advanced(this);"> |
| 78 |
<?php esc_attr_e( 'Submit', 'supportcandy' ); ?></button> |
| 79 |
<button |
| 80 |
class="wpsc-button normal secondary" |
| 81 |
onclick="wpsc_reset_te_advanced(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_reset_te_advanced' ) ); ?>');"> |
| 82 |
<?php esc_attr_e( 'Reset default', 'supportcandy' ); ?></button> |
| 83 |
</div> |
| 84 |
<?php |
| 85 |
wp_die(); |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Save settings |
| 90 |
* |
| 91 |
* @return void |
| 92 |
*/ |
| 93 |
public static function save_settings() { |
| 94 |
|
| 95 |
if ( check_ajax_referer( 'wpsc_set_te_advanced', '_ajax_nonce', false ) != 1 ) { |
| 96 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 97 |
} |
| 98 |
|
| 99 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 100 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 101 |
} |
| 102 |
|
| 103 |
$advanced = apply_filters( |
| 104 |
'wpsc_set_te_advanced', |
| 105 |
array( |
| 106 |
'html-pasting' => isset( $_POST['html-pasting'] ) ? intval( $_POST['html-pasting'] ) : 1, |
| 107 |
) |
| 108 |
); |
| 109 |
update_option( 'wpsc-te-advanced', $advanced ); |
| 110 |
wp_die(); |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* Reset settings to default |
| 115 |
* |
| 116 |
* @return void |
| 117 |
*/ |
| 118 |
public static function reset_settings() { |
| 119 |
|
| 120 |
if ( check_ajax_referer( 'wpsc_reset_te_advanced', '_ajax_nonce', false ) != 1 ) { |
| 121 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 122 |
} |
| 123 |
|
| 124 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 125 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 126 |
} |
| 127 |
self::reset(); |
| 128 |
wp_die(); |
| 129 |
} |
| 130 |
} |
| 131 |
endif; |
| 132 |
|
| 133 |
WPSC_TE_Advanced::init(); |
| 134 |
|