1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace WC_POS\API;
13
14 use WC_API_Resource;
15 use WC_API_Server;
16
17 class Support extends WC_API_Resource {
18
19 protected $base = '/pos/support';
20
21 public $support_email = 'support@woopos.com.au';
22
23
24 25 26 27 28 29 30 31
32 public function register_routes( array $routes ) {
33
34
35 $routes[ $this->base ] = array(
36 array( array( $this, 'send_support_email' ), WC_API_Server::CREATABLE | WC_API_Server::ACCEPT_DATA )
37 );
38
39 return $routes;
40
41 }
42
43
44 45 46 47
48 public function send_support_email( $data ) {
49 $name = isset( $data['name'] ) ? $data['name'] : '' ;
50 $email = isset( $data['email'] ) ? $data['email'] : '' ;
51 $message = isset( $data['message'] ) ? $data['message'] : '' ;
52 $append_report = isset( $data['append_report'] ) ? $data['append_report'] : false ;
53 $report = isset( $data['report'] ) ? $data['report'] : '' ;
54
55 $headers[] = 'From: '. $name .' <'. $email .'>';
56 $headers[] = 'Reply-To: '. $name .' <'. $email .'>';
57 $message = $message . "\n\n";
58
59 if( $append_report ){
60 $message .= $report;
61 $message .= $this->get_active_plugins();
62 }
63
64 $support_email = apply_filters( 'woocommerce_pos_support_email', $this->support_email );
65
66 if( wp_mail( $support_email, 'WooCommerce POS Support', $message, $headers ) ) {
67 return array(
68 'result' => 'success',
69 'message' => __( 'Email sent', 'woocommerce-pos')
70 );
71 }
72
73 return new \WP_Error(
74 'woocommerce_pos_email_error',
75 __( 'There was an error sending the email', 'woocommerce-pos' ),
76 array( 'status' => 400 )
77 );
78 }
79
80 81 82
83 public function get_active_plugins(){
84 $plugins = '*** Active Plugins ***' . "\n\n";
85
86 $active_plugins = (array) get_option( 'active_plugins', array() );
87
88 if ( is_multisite() ) {
89 $network_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) );
90 $active_plugins = array_merge( $active_plugins, $network_activated_plugins );
91 }
92
93 foreach ( $active_plugins as $plugin ) {
94 $plugin_data = @get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
95 if( ! empty( $plugin_data['Name'] ) ){
96 $plugins .= $plugin_data['Name'] . ': by ' . $plugin_data['Author'] . ' - ' . $plugin_data['Version'] . "\n";
97 }
98 }
99
100 return $plugins;
101
102 }
103
104 }