supportcandy
/
includes
/
admin
/
settings
/
text-editor-settings
/
class-wpsc-te-registered-user.php
class-wpsc-te-registered-user.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.4.3, at includes/admin/settings/text-editor-settings/class-wpsc-te-registered-user.php
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | exit; // Exit if accessed directly! |
| 4 | } |
| 5 | |
| 6 | if ( ! class_exists( 'WPSC_TE_Registered_User' ) ) : |
| 7 | |
| 8 | final class WPSC_TE_Registered_User { |
| 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_registered_user', array( __CLASS__, 'load_settings_ui' ) ); |
| 19 | add_action( 'wp_ajax_wpsc_set_te_registered_user', array( __CLASS__, 'save_settings' ) ); |
| 20 | add_action( 'wp_ajax_wpsc_reset_te_registered_user', array( __CLASS__, 'reset_settings' ) ); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Reset settings |
| 25 | * |
| 26 | * @return void |
| 27 | */ |
| 28 | public static function reset() { |
| 29 | |
| 30 | $gs_file = get_option( 'wpsc-gs-file-attachments' ); |
| 31 | |
| 32 | $attach_notice = sprintf( |
| 33 | /* translators: %1$s: attachment max file size, %2$s: allowed file extenstions. */ |
| 34 | esc_attr__( 'You can upload files maximum size %1$s mb of types %2$s.', 'supportcandy' ), |
| 35 | $gs_file['attachments-max-filesize'], |
| 36 | $gs_file['allowed-file-extensions'] |
| 37 | ); |
| 38 | |
| 39 | $registered_user = apply_filters( |
| 40 | 'wpsc_te_registered_user', |
| 41 | array( |
| 42 | 'enable' => 1, |
| 43 | 'allow-attachments' => 1, |
| 44 | 'toolbar' => array( 'bold', 'italic', 'underline', 'blockquote', 'alignleft aligncenter alignright', 'bullist', 'numlist', 'rtl', 'link', 'wpsc_insert_editor_img' ), |
| 45 | 'file-attachment-notice' => 0, |
| 46 | 'file-attachment-notice-text' => $attach_notice, |
| 47 | ) |
| 48 | ); |
| 49 | update_option( 'wpsc-te-registered-user', $registered_user ); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Settings user interface |
| 54 | * |
| 55 | * @return void |
| 56 | */ |
| 57 | public static function load_settings_ui() { |
| 58 | |
| 59 | if ( ! WPSC_Functions::is_site_admin() ) { |
| 60 | wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 61 | } |
| 62 | $settings = get_option( 'wpsc-te-registered-user', array() );?> |
| 63 | |
| 64 | <form action="#" onsubmit="return false;" class="wpsc-frm-te-registered-user"> |
| 65 | <div class="wpsc-dock-container"> |
| 66 | <?php |
| 67 | printf( |
| 68 | /* translators: Click here to see the documentation */ |
| 69 | esc_attr__( '%s to see the documentation!', 'supportcandy' ), |
| 70 | '<a href="https://supportcandy.net/docs/rich-text-editor/" target="_blank">' . esc_attr__( 'Click here', 'supportcandy' ) . '</a>' |
| 71 | ); |
| 72 | ?> |
| 73 | </div> |
| 74 | <div class="wpsc-input-group"> |
| 75 | <div class="label-container"> |
| 76 | <label for=""><?php esc_attr_e( 'Enable', 'supportcandy' ); ?></label> |
| 77 | </div> |
| 78 | <select id="wpsc-te-registered-user-enable" name="enable"> |
| 79 | <option <?php selected( $settings['enable'], 1 ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option> |
| 80 | <option <?php selected( $settings['enable'], 0 ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option> |
| 81 | </select> |
| 82 | </div> |
| 83 | <div class="wpsc-input-group"> |
| 84 | <div class="label-container"> |
| 85 | <label for=""><?php esc_attr_e( 'Allow attachments', 'supportcandy' ); ?></label> |
| 86 | </div> |
| 87 | <select id="wpsc-te-registered-user-allow-attach" name="allow-attachments"> |
| 88 | <option <?php selected( $settings['allow-attachments'], 1 ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option> |
| 89 | <option <?php selected( $settings['allow-attachments'], 0 ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option> |
| 90 | </select> |
| 91 | </div> |
| 92 | <div class="wpsc-input-group"> |
| 93 | <div class="label-container"> |
| 94 | <label for=""><?php esc_attr_e( 'Toolbar actions', 'supportcandy' ); ?></label> |
| 95 | </div> |
| 96 | <div class="checkboxes-group"> |
| 97 | <?php |
| 98 | foreach ( WPSC_Text_Editor::$toolbar as $action ) : |
| 99 | ?> |
| 100 | <div class="inner-group"> |
| 101 | <?php |
| 102 | $checked = in_array( $action['value'], $settings['toolbar'] ) ? 'checked' : '' |
| 103 | ?> |
| 104 | <input name="toolbar[]" type="checkbox" <?php echo esc_attr( $checked ); ?> value="<?php echo esc_attr( $action['value'] ); ?>"> |
| 105 | <?php echo esc_attr( $action['name'] ); ?> |
| 106 | </div> |
| 107 | <?php |
| 108 | endforeach; |
| 109 | ?> |
| 110 | </div> |
| 111 | </div> |
| 112 | <div class="wpsc-input-group"> |
| 113 | <div class="label-container"> |
| 114 | <label for=""><?php esc_attr_e( 'Show file attachment notice', 'supportcandy' ); ?></label> |
| 115 | </div> |
| 116 | <select id="wpsc-file-attachment-notice" name="file-attachment-notice"> |
| 117 | <option <?php selected( $settings['file-attachment-notice'], 1 ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option> |
| 118 | <option <?php selected( $settings['file-attachment-notice'], 0 ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option> |
| 119 | </select> |
| 120 | <script> |
| 121 | jQuery('#wpsc-file-attachment-notice').change(function() { |
| 122 | if (this.value=='1') { |
| 123 | jQuery('#wpsc-file-attachment-notice-text').show(); |
| 124 | } else { |
| 125 | jQuery('#wpsc-file-attachment-notice-text').hide(); |
| 126 | } |
| 127 | }); |
| 128 | </script> |
| 129 | </div> |
| 130 | <?php |
| 131 | $display = ! $settings['file-attachment-notice'] ? 'display:none' : '' |
| 132 | ?> |
| 133 | <div class="wpsc-input-group" id="wpsc-file-attachment-notice-text" style="<?php echo esc_attr( $display ); ?>"> |
| 134 | <input type="text" name="file-attachment-notice-text" value="<?php echo esc_attr( $settings['file-attachment-notice-text'] ); ?>" autocomplete="off"> |
| 135 | </div> |
| 136 | <?php do_action( 'wpsc_te_registered_user' ); ?> |
| 137 | <input type="hidden" name="action" value="wpsc_set_te_registered_user"> |
| 138 | <input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpsc_set_te_registered_user' ) ); ?>"> |
| 139 | </form> |
| 140 | <div class="setting-footer-actions"> |
| 141 | <button |
| 142 | class="wpsc-button normal primary margin-right" |
| 143 | onclick="wpsc_set_te_registered_user(this);"> |
| 144 | <?php esc_attr_e( 'Submit', 'supportcandy' ); ?></button> |
| 145 | <button |
| 146 | class="wpsc-button normal secondary" |
| 147 | onclick="wpsc_reset_te_registered_user(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_reset_te_registered_user' ) ); ?>');"> |
| 148 | <?php esc_attr_e( 'Reset default', 'supportcandy' ); ?></button> |
| 149 | </div> |
| 150 | <?php |
| 151 | wp_die(); |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Save settings |
| 156 | * |
| 157 | * @return void |
| 158 | */ |
| 159 | public static function save_settings() { |
| 160 | |
| 161 | if ( check_ajax_referer( 'wpsc_set_te_registered_user', '_ajax_nonce', false ) != 1 ) { |
| 162 | wp_send_json_error( 'Unauthorised request!', 401 ); |
| 163 | } |
| 164 | |
| 165 | if ( ! WPSC_Functions::is_site_admin() ) { |
| 166 | wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 167 | } |
| 168 | |
| 169 | $registered_user = apply_filters( |
| 170 | 'wpsc_te_set_registered_user', |
| 171 | array( |
| 172 | 'enable' => isset( $_POST['enable'] ) ? intval( $_POST['enable'] ) : 1, |
| 173 | 'allow-attachments' => isset( $_POST['allow-attachments'] ) ? intval( $_POST['allow-attachments'] ) : 1, |
| 174 | 'toolbar' => isset( $_POST['toolbar'] ) ? array_filter( array_map( 'sanitize_text_field', wp_unslash( $_POST['toolbar'] ) ) ) : array(), |
| 175 | 'file-attachment-notice' => isset( $_POST['file-attachment-notice'] ) ? intval( $_POST['file-attachment-notice'] ) : 0, |
| 176 | 'file-attachment-notice-text' => isset( $_POST['file-attachment-notice-text'] ) ? sanitize_text_field( wp_unslash( $_POST['file-attachment-notice-text'] ) ) : '', |
| 177 | ) |
| 178 | ); |
| 179 | update_option( 'wpsc-te-registered-user', $registered_user ); |
| 180 | wp_die(); |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Reset settings to default |
| 185 | * |
| 186 | * @return void |
| 187 | */ |
| 188 | public static function reset_settings() { |
| 189 | |
| 190 | if ( check_ajax_referer( 'wpsc_reset_te_registered_user', '_ajax_nonce', false ) != 1 ) { |
| 191 | wp_send_json_error( 'Unauthorised request!', 401 ); |
| 192 | } |
| 193 | |
| 194 | if ( ! WPSC_Functions::is_site_admin() ) { |
| 195 | wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 196 | } |
| 197 | self::reset(); |
| 198 | wp_die(); |
| 199 | } |
| 200 | } |
| 201 | endif; |
| 202 | |
| 203 | WPSC_TE_Registered_User::init(); |
| 204 |