supportcandy
/
includes
/
admin
/
settings
/
miscellaneous-settings
/
class-wpsc-miscellaneous-settings.php
class-wpsc-miscellaneous-settings.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.3.9, at includes/admin/settings/miscellaneous-settings/class-wpsc-miscellaneous-settings.php
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | exit; // Exit if accessed directly! |
| 4 | } |
| 5 | |
| 6 | if ( ! class_exists( 'WPSC_Miscellaneous_Settings' ) ) : |
| 7 | |
| 8 | final class WPSC_Miscellaneous_Settings { |
| 9 | |
| 10 | /** |
| 11 | * Tabs for this section |
| 12 | * |
| 13 | * @var array |
| 14 | */ |
| 15 | private static $tabs; |
| 16 | |
| 17 | /** |
| 18 | * Current tab |
| 19 | * |
| 20 | * @var string |
| 21 | */ |
| 22 | public static $current_tab; |
| 23 | |
| 24 | /** |
| 25 | * Initialize this class |
| 26 | * |
| 27 | * @return void |
| 28 | */ |
| 29 | public static function init() { |
| 30 | |
| 31 | // Load tabs for this section. |
| 32 | add_action( 'admin_init', array( __CLASS__, 'load_tabs' ) ); |
| 33 | |
| 34 | // Add current tab to admin localization data. |
| 35 | add_filter( 'wpsc_admin_localizations', array( __CLASS__, 'localizations' ) ); |
| 36 | |
| 37 | // Load section tab layout. |
| 38 | add_action( 'wp_ajax_wpsc_get_miscellaneous_settings', array( __CLASS__, 'get_miscellaneous_settings' ) ); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Load tabs for this section |
| 43 | */ |
| 44 | public static function load_tabs() { |
| 45 | |
| 46 | self::$tabs = apply_filters( |
| 47 | 'wpsc_ms_tabs', |
| 48 | array( |
| 49 | 'term-and-conditions' => array( |
| 50 | 'slug' => 'term_and_conditions', |
| 51 | 'label' => esc_attr__( 'Term & Conditions', 'supportcandy' ), |
| 52 | 'callback' => 'wpsc_get_ms_term_and_conditions', |
| 53 | ), |
| 54 | 'gdpr' => array( |
| 55 | 'slug' => 'gdpr', |
| 56 | 'label' => esc_attr__( 'GDPR', 'supportcandy' ), |
| 57 | 'callback' => 'wpsc_get_ms_gdpr', |
| 58 | ), |
| 59 | 'recaptcha' => array( |
| 60 | 'slug' => 'recaptcha', |
| 61 | 'label' => esc_attr__( 'reCaptcha', 'supportcandy' ), |
| 62 | 'callback' => 'wpsc_get_ms_recaptcha', |
| 63 | ), |
| 64 | 'advanced' => array( |
| 65 | 'slug' => 'advanced', |
| 66 | 'label' => esc_attr__( 'Advanced', 'supportcandy' ), |
| 67 | 'callback' => 'wpsc_get_ms_advanced', |
| 68 | ), |
| 69 | ) |
| 70 | ); |
| 71 | self::$current_tab = isset( $_REQUEST['tab'] ) ? sanitize_text_field( $_REQUEST['tab'] ) : 'term-and-conditions'; // phpcs:ignore |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Add localizations to local JS |
| 76 | * |
| 77 | * @param array $localizations - localizations. |
| 78 | * @return array |
| 79 | */ |
| 80 | public static function localizations( $localizations ) { |
| 81 | |
| 82 | if ( ! ( WPSC_Settings::$is_current_page && WPSC_Settings::$current_section === 'miscellaneous-settings' ) ) { |
| 83 | return $localizations; |
| 84 | } |
| 85 | |
| 86 | // Current section. |
| 87 | $localizations['current_tab'] = self::$current_tab; |
| 88 | |
| 89 | return $localizations; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * General setion body layout |
| 94 | * |
| 95 | * @return void |
| 96 | */ |
| 97 | public static function get_miscellaneous_settings() { |
| 98 | |
| 99 | if ( ! WPSC_Functions::is_site_admin() ) { |
| 100 | wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 101 | }?> |
| 102 | |
| 103 | <div class="wpsc-setting-tab-container"> |
| 104 | <?php |
| 105 | foreach ( self::$tabs as $key => $tab ) { |
| 106 | $active = self::$current_tab === $key ? 'active' : '' |
| 107 | ?> |
| 108 | <button |
| 109 | class="<?php echo esc_attr( $key ) . ' ' . esc_attr( $active ); ?>" |
| 110 | onclick="<?php echo esc_attr( $tab['callback'] ) . '();'; ?>"> |
| 111 | <?php echo esc_attr( $tab['label'] ); ?> |
| 112 | </button> |
| 113 | <?php |
| 114 | } |
| 115 | ?> |
| 116 | </div> |
| 117 | |
| 118 | <div class="wpsc-setting-section-body"></div> |
| 119 | <?php |
| 120 | wp_die(); |
| 121 | } |
| 122 | } |
| 123 | endif; |
| 124 | |
| 125 | WPSC_Miscellaneous_Settings::init(); |
| 126 |