| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly! |
| 4 |
} |
| 5 |
|
| 6 |
if ( ! class_exists( 'WPSC_Appearence_Settings' ) ) : |
| 7 |
|
| 8 |
final class WPSC_Appearence_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_appearence_settings', array( __CLASS__, 'get_appearence_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_gs_appearance_tabs', |
| 48 |
array( |
| 49 |
'general' => array( |
| 50 |
'slug' => 'general', |
| 51 |
'label' => esc_attr__( 'General', 'supportcandy' ), |
| 52 |
'callback' => 'wpsc_get_ap_general', |
| 53 |
), |
| 54 |
'ticket-list' => array( |
| 55 |
'slug' => 'ticket_list', |
| 56 |
'label' => esc_attr__( 'Ticket List', 'supportcandy' ), |
| 57 |
'callback' => 'wpsc_get_ap_ticket_list', |
| 58 |
), |
| 59 |
'individual-ticket' => array( |
| 60 |
'slug' => 'individual_ticket', |
| 61 |
'label' => esc_attr__( 'Individual Ticket', 'supportcandy' ), |
| 62 |
'callback' => 'wpsc_get_ap_individual_ticket', |
| 63 |
), |
| 64 |
'modal-popup' => array( |
| 65 |
'slug' => 'modal_popup', |
| 66 |
'label' => esc_attr__( 'Modal Popup', 'supportcandy' ), |
| 67 |
'callback' => 'wpsc_get_ap_modal_popup', |
| 68 |
), |
| 69 |
'agent-collision' => array( |
| 70 |
'slug' => 'agent_collision', |
| 71 |
'label' => esc_attr__( 'Agent Collision', 'supportcandy' ), |
| 72 |
'callback' => 'wpsc_get_ap_agent_collision', |
| 73 |
), |
| 74 |
'dashboard' => array( |
| 75 |
'slug' => 'dashboard', |
| 76 |
'label' => esc_attr__( 'Dashboard', 'supportcandy' ), |
| 77 |
'callback' => 'wpsc_get_ap_dashboard', |
| 78 |
), |
| 79 |
) |
| 80 |
); |
| 81 |
self::$current_tab = isset( $_REQUEST['tab'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tab'] ) ) : 'general'; // phpcs:ignore |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Add localizations to local JS |
| 86 |
* |
| 87 |
* @param array $localizations - localization. |
| 88 |
* @return array |
| 89 |
*/ |
| 90 |
public static function localizations( $localizations ) { |
| 91 |
|
| 92 |
if ( ! ( WPSC_Settings::$is_current_page && WPSC_Settings::$current_section === 'appearence' ) ) { |
| 93 |
return $localizations; |
| 94 |
} |
| 95 |
|
| 96 |
// Current section. |
| 97 |
$localizations['current_tab'] = self::$current_tab; |
| 98 |
|
| 99 |
return $localizations; |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* General setion body layout |
| 104 |
* |
| 105 |
* @return void |
| 106 |
*/ |
| 107 |
public static function get_appearence_settings() { |
| 108 |
|
| 109 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 110 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 111 |
}?> |
| 112 |
|
| 113 |
<div class="wpsc-setting-tab-container"> |
| 114 |
<?php |
| 115 |
foreach ( self::$tabs as $key => $tab ) : |
| 116 |
$active = self::$current_tab === $key ? 'active' : '' |
| 117 |
?> |
| 118 |
<button |
| 119 |
class="<?php echo esc_attr( $key ) . ' ' . esc_attr( $active ); ?>" |
| 120 |
onclick="<?php echo esc_attr( $tab['callback'] ) . '();'; ?>"> |
| 121 |
<?php echo esc_attr( $tab['label'] ); ?> |
| 122 |
</button> |
| 123 |
<?php |
| 124 |
endforeach; |
| 125 |
?> |
| 126 |
</div> |
| 127 |
<div class="wpsc-setting-section-body"></div> |
| 128 |
<?php |
| 129 |
wp_die(); |
| 130 |
} |
| 131 |
} |
| 132 |
endif; |
| 133 |
|
| 134 |
WPSC_Appearence_Settings::init(); |
| 135 |
|