PluginProbe
EmailKit – Email Customizer for WooCommerce & WP / 1.5.2
EmailKit – Email Customizer for WooCommerce & WP v1.5.2
1.6.9 1.6.8 1.6.7 trunk 1.0.0 1.2.0 1.4.0 1.4.5 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6
emailkit / Promotional / Onboard / Classes / PluginDataSender.php

PluginDataSender.php in EmailKit – Email Customizer for WooCommerce & WP 1.5.2, at Promotional/Onboard/Classes/PluginDataSender.php

104 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace EmailKit\Promotional\Onboard\Classes;
4
5 use EmailKit\Promotional\Onboard\Onboard;
6 use EmailKit\Traits\Singleton;
7
8 defined( 'ABSPATH' ) || exit;
9
10 class PluginDataSender {
11
12 use Singleton;
13
14 private $installedPlugins = [];
15 private $themes = [];
16 private $activatedPlugins = [];
17
18 public function __construct() {
19 $this->set_activated_plugins();
20 $this->set_installed_plugins();
21 $this->setThemes();
22 }
23
24 private function set_activated_plugins() {
25 foreach ( apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) as $plugin ) {
26 array_push( $this->activatedPlugins, $plugin );
27 }
28 }
29
30 private function set_installed_plugins() {
31 foreach ( get_plugins() as $key => $plugin ) {
32 $status = false;
33 if ( in_array( $key, $this->activatedPlugins ) ) {
34 $status = true;
35 }
36 array_push( $this->installedPlugins, [
37 'name' => $plugin['Name'],
38 'version' => $plugin['Version'],
39 'is_active' => $status,
40 ] );
41 }
42 }
43
44 private function setThemes() {
45 $activeTheme = wp_get_theme()->get('Name') ;
46 foreach (wp_get_themes() as $key => $theme) {
47 array_push($this->themes, [
48 "name" => $theme->Name,
49 "version" => $theme->Version,
50 'is_active' => $activeTheme == $theme->Name,
51 ]);
52 }
53 }
54
55
56 private function getUrl( $route ) {
57 return 'https://account.wpmet.com/sync/api/' . $route;
58 }
59
60
61 public function send( $route ) {
62 return wp_remote_post(
63 $this->getUrl($route) ,
64 [
65 'method' => 'POST',
66 'data_format' => 'body',
67 'headers' => [
68 'Content-Type' => 'application/json'
69 ],
70 'body' => json_encode( $this->get_data() )
71 ]
72 );
73 }
74
75 public function sendAutomizyData( $route, $data ) {
76 return wp_remote_post(
77 $this->getUrl($route) ,
78 [
79 'method' => 'POST',
80 'data_format' => 'body',
81 'headers' => [
82 'Content-Type' => 'application/json'
83 ],
84 'body' => json_encode( $data )
85 ]
86 );
87 }
88
89 public function get_data() {
90 return [
91 'environment_id' => Onboard::ENVIRONMENT_ID,
92 "domain" => get_site_url(),
93 "total_user" => count_users()['total_users'],
94 "themes" => $this->themes,
95 "plugins" => $this->installedPlugins,
96 "php_version" => phpversion(),
97 "db_version" => mysqli_get_client_version(), //phpcs:ignore WordPress.DB.RestrictedFunctions
98 "server_name" => isset($_SERVER['SERVER_SOFTWARE'])? explode( ' ', sanitize_text_field(wp_unslash($_SERVER['SERVER_SOFTWARE'])))[0] : '',
99 "max_execution_time" => ini_get( 'max_execution_time' ),
100 "php_memory_size" => ini_get( 'memory_limit' ),
101 "language" => get_locale()
102 ];
103 }
104 }