PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / trunk
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent vtrunk
3.5.3 3.5.2 3.5.1 3.4.9 3.5.0 3.4.8 3.4.7 trunk 2.3.1 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6
supportcandy / includes / frontend / class-wpsc-shortcode-six.php

class-wpsc-shortcode-six.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent trunk, at includes/frontend/class-wpsc-shortcode-six.php

118 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly!
4 }
5
6 if ( ! class_exists( 'WPSC_Shortcode_Six' ) ) :
7
8 final class WPSC_Shortcode_Six {
9
10 /**
11 * Initialize this class
12 */
13 public static function init() {
14
15 // register shortcode.
16 add_shortcode( 'wpsc_agent_profile', array( __CLASS__, 'layout' ) );
17 }
18
19 /**
20 * Layout for this shortcode
21 *
22 * @param array $attrs - Shortcode attributes.
23 * @return string
24 */
25 public static function layout( $attrs ) {
26
27 $current_user = WPSC_Current_User::$current_user;
28
29 // logout if guest login is open-ticket.
30 if ( WPSC_Current_User::$login_type == 'guest' && WPSC_Current_User::$guest_login_type == 'open-ticket' ) {
31 $current_user->logout();
32 }
33
34 // return empty if logged in user is not an agent.
35 if ( $current_user->is_customer && ! $current_user->is_agent ) {
36 return '';
37 }
38
39 ob_start();?>
40 <div id="wpsc-container" style="display:none;">
41 <div class="wpsc-shortcode-container">
42 <?php
43
44 // logged in agent as agent we checked above.
45 if ( $current_user->is_customer ) {
46 // js events.
47 add_action( 'wpsc_js_ready', array( __CLASS__, 'register_js_ready_function' ) );
48 ?>
49 <div class="wpsc-body"></div>
50 <?php
51 } else {
52 // Not logged in.
53 WPSC_Frontend::load_authentication_screen( true, false );
54 }
55 ?>
56
57 </div>
58 </div>
59 <?php
60 WPSC_Frontend::load_html_snippets();
61 self::load_js_functions();
62 return ob_get_clean();
63 }
64
65 /**
66 * Load js functions for this shortcode
67 *
68 * @return void
69 */
70 public static function load_js_functions() {
71 ?>
72
73 <script type="text/javascript">
74
75 /**
76 * Get create ticket form
77 */
78 function wpsc_get_agent_profile(is_humbargar = false) {
79
80 jQuery('.wpsc-body').html(supportcandy.loader_html);
81
82 if (supportcandy.is_reload != 1) {
83 wpsc_scroll_top();
84 } else { supportcandy.is_reload = 0 }
85
86 var url = new URL(window.location.href);
87 var search_params = url.searchParams;
88
89 var data = { action: 'wpsc_get_agent_profile'};
90 search_params.forEach(function(value, key) {
91 data[key] = value;
92 });
93 jQuery.post(supportcandy.ajax_url, data).done(function (response) {
94 jQuery('.wpsc-body').html(response);
95 wpsc_reset_responsive_style();
96 jQuery('.wpsc-ap-nav.general').trigger('click');
97 }).fail(function(response){
98 jQuery('.wpsc-body').html('<div style="display:flex; justify-content:center; margin:0 15px 15px; width:100%;"><?php esc_attr_e( 'Unauthorized access!', 'supportcandy' ); ?></div>');
99 });
100 }
101 </script>
102 <?php
103 }
104
105 /**
106 * JS ready function
107 *
108 * @return void
109 */
110 public static function register_js_ready_function() {
111
112 echo 'wpsc_get_agent_profile();' . PHP_EOL;
113 }
114 }
115 endif;
116
117 WPSC_Shortcode_Six::init();
118