| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly! |
| 4 |
} |
| 5 |
|
| 6 |
if ( ! class_exists( 'WPSC_EN_Settings_GS' ) ) : |
| 7 |
|
| 8 |
final class WPSC_EN_Settings_GS { |
| 9 |
|
| 10 |
/** |
| 11 |
* Initialize this class |
| 12 |
*/ |
| 13 |
public static function init() { |
| 14 |
|
| 15 |
add_action( 'wp_ajax_wpsc_get_en_general_setting', array( __CLASS__, 'get_engs' ) ); |
| 16 |
add_action( 'wp_ajax_wpsc_set_en_general', array( __CLASS__, 'save_settings' ) ); |
| 17 |
add_action( 'wp_ajax_wpsc_reset_en_general', array( __CLASS__, 'reset_settings' ) ); |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Install this setting. To be called from installation. |
| 22 |
* |
| 23 |
* @return void |
| 24 |
*/ |
| 25 |
public static function reset() { |
| 26 |
|
| 27 |
$general = apply_filters( |
| 28 |
'wpsc_en_general', |
| 29 |
array( |
| 30 |
'from-name' => '', |
| 31 |
'from-email' => '', |
| 32 |
'reply-to' => '', |
| 33 |
'cron-email-count' => 5, |
| 34 |
'blocked-emails' => array(), |
| 35 |
'attachments-in-notification' => 'actual-files', |
| 36 |
) |
| 37 |
); |
| 38 |
update_option( 'wpsc-en-general', $general ); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Get ticket form fields |
| 43 |
* |
| 44 |
* @return void |
| 45 |
*/ |
| 46 |
public static function get_engs() { |
| 47 |
|
| 48 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 49 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 50 |
} |
| 51 |
$settings = get_option( 'wpsc-en-general', array() );?> |
| 52 |
|
| 53 |
<div class="wpsc-setting-header"> |
| 54 |
<h2><?php esc_attr_e( 'General Settings', 'supportcandy' ); ?></h2> |
| 55 |
</div> |
| 56 |
<div class="wpsc-setting-section-body"> |
| 57 |
<div class="wpsc-dock-container"> |
| 58 |
<?php |
| 59 |
printf( |
| 60 |
/* translators: Click here to see the documentation */ |
| 61 |
esc_attr__( '%s to see the documentation!', 'supportcandy' ), |
| 62 |
'<a href="https://supportcandy.net/docs/email-notification-settings/" target="_blank">' . esc_attr__( 'Click here', 'supportcandy' ) . '</a>' |
| 63 |
); |
| 64 |
?> |
| 65 |
</div> |
| 66 |
<form action="#" onsubmit="return false;" class="wpsc-frm-en-general"> |
| 67 |
<div class="wpsc-input-group"> |
| 68 |
<div class="label-container"> |
| 69 |
<label for=""><?php esc_attr_e( 'From name', 'supportcandy' ); ?></label> |
| 70 |
</div> |
| 71 |
<input type="text" name="wpsc-from-name" value="<?php echo esc_attr( $settings['from-name'] ); ?>" autocomplete="off"/> |
| 72 |
</div> |
| 73 |
<div class="wpsc-input-group"> |
| 74 |
<div class="label-container"> |
| 75 |
<label for=""><?php esc_attr_e( 'From email', 'supportcandy' ); ?></label> |
| 76 |
</div> |
| 77 |
<input type="text" name="wpsc-from-email" value="<?php echo esc_attr( $settings['from-email'] ); ?>" autocomplete="off"/> |
| 78 |
</div> |
| 79 |
<div class="wpsc-input-group"> |
| 80 |
<div class="label-container"> |
| 81 |
<label for=""><?php esc_attr_e( 'Reply to', 'supportcandy' ); ?></label> |
| 82 |
</div> |
| 83 |
<input type="text" name="wpsc-reply-to" value="<?php echo esc_attr( $settings['reply-to'] ); ?>" autocomplete="off"/> |
| 84 |
</div> |
| 85 |
<div class="wpsc-input-group"> |
| 86 |
<div class="label-container"> |
| 87 |
<label for=""><?php esc_attr_e( 'Number of emails per cron job (background emails)', 'supportcandy' ); ?></label> |
| 88 |
</div> |
| 89 |
<input type="text" name="wpsc-cron-email-count" value="<?php echo esc_attr( $settings['cron-email-count'] ); ?>" autocomplete="off"/> |
| 90 |
</div> |
| 91 |
<div class="wpsc-input-group"> |
| 92 |
<div class="label-container"> |
| 93 |
<label for=""><?php esc_attr_e( 'Blocked emails (one per line)', 'supportcandy' ); ?></label> |
| 94 |
</div> |
| 95 |
<?php $blocked_emails = $settings['blocked-emails'] ? implode( PHP_EOL, $settings['blocked-emails'] ) : ''; ?> |
| 96 |
<textarea name="wpsc-blocked-emails" rows="5"><?php echo esc_attr( $blocked_emails ); ?></textarea> |
| 97 |
</div> |
| 98 |
<div class="wpsc-input-group"> |
| 99 |
<div class="label-container"> |
| 100 |
<label for=""><?php esc_attr_e( 'Attachments in notifications', 'supportcandy' ); ?></label> |
| 101 |
</div> |
| 102 |
<select name="attachments-in-notification"> |
| 103 |
<option <?php selected( $settings['attachments-in-notification'], 'actual-files' ); ?> value="actual-files"><?php esc_attr_e( 'Actual files', 'supportcandy' ); ?></option> |
| 104 |
<option <?php selected( $settings['attachments-in-notification'], 'file-links' ); ?> value="file-links"><?php esc_attr_e( 'File links', 'supportcandy' ); ?></option> |
| 105 |
<option <?php selected( $settings['attachments-in-notification'], 'disable' ); ?> value="disable"><?php esc_attr_e( 'Disable', 'supportcandy' ); ?></option> |
| 106 |
</select> |
| 107 |
</div> |
| 108 |
<?php do_action( 'wpsc_en_general' ); ?> |
| 109 |
<input type="hidden" name="action" value="wpsc_set_en_general"> |
| 110 |
<input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpsc_set_en_general' ) ); ?>"> |
| 111 |
</form> |
| 112 |
<div class="setting-footer-actions"> |
| 113 |
<button |
| 114 |
class="wpsc-button normal primary margin-right" |
| 115 |
onclick="wpsc_set_en_general(this);"> |
| 116 |
<?php esc_attr_e( 'Submit', 'supportcandy' ); ?></button> |
| 117 |
<button |
| 118 |
class="wpsc-button normal secondary" |
| 119 |
onclick="wpsc_reset_en_general(this);"> |
| 120 |
<?php esc_attr_e( 'Reset default', 'supportcandy' ); ?></button> |
| 121 |
</div> |
| 122 |
</div> |
| 123 |
<?php |
| 124 |
wp_die(); |
| 125 |
} |
| 126 |
|
| 127 |
/** |
| 128 |
* Save settings |
| 129 |
* |
| 130 |
* @return void |
| 131 |
*/ |
| 132 |
public static function save_settings() { |
| 133 |
|
| 134 |
if ( check_ajax_referer( 'wpsc_set_en_general', '_ajax_nonce', false ) != 1 ) { |
| 135 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 136 |
} |
| 137 |
|
| 138 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 139 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 140 |
} |
| 141 |
|
| 142 |
$blocked_emails = isset( $_POST['wpsc-blocked-emails'] ) ? sanitize_textarea_field( wp_unslash( $_POST['wpsc-blocked-emails'] ) ) : ''; |
| 143 |
$blocked_emails = array_filter( array_map( 'sanitize_text_field', explode( PHP_EOL, $blocked_emails ) ) ); |
| 144 |
|
| 145 |
$general = apply_filters( |
| 146 |
'wpsc_set_en_general', |
| 147 |
array( |
| 148 |
'from-name' => isset( $_POST['wpsc-from-name'] ) ? sanitize_text_field( wp_unslash( $_POST['wpsc-from-name'] ) ) : '', |
| 149 |
'from-email' => isset( $_POST['wpsc-from-email'] ) ? sanitize_text_field( wp_unslash( $_POST['wpsc-from-email'] ) ) : '', |
| 150 |
'reply-to' => isset( $_POST['wpsc-reply-to'] ) ? sanitize_text_field( wp_unslash( $_POST['wpsc-reply-to'] ) ) : 1, |
| 151 |
'cron-email-count' => isset( $_POST['wpsc-cron-email-count'] ) && sanitize_text_field( wp_unslash( $_POST['wpsc-cron-email-count'] ) ) ? intval( $_POST['wpsc-cron-email-count'] ) : 5, |
| 152 |
'blocked-emails' => $blocked_emails, |
| 153 |
'attachments-in-notification' => isset( $_POST['attachments-in-notification'] ) ? sanitize_text_field( wp_unslash( $_POST['attachments-in-notification'] ) ) : 'actual-files', |
| 154 |
) |
| 155 |
); |
| 156 |
update_option( 'wpsc-en-general', $general ); |
| 157 |
wp_die(); |
| 158 |
} |
| 159 |
|
| 160 |
/** |
| 161 |
* Reset settings to default |
| 162 |
* |
| 163 |
* @return void |
| 164 |
*/ |
| 165 |
public static function reset_settings() { |
| 166 |
|
| 167 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 168 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 169 |
} |
| 170 |
self::reset(); |
| 171 |
wp_die(); |
| 172 |
} |
| 173 |
} |
| 174 |
endif; |
| 175 |
|
| 176 |
WPSC_EN_Settings_GS::init(); |
| 177 |
|