| 1 |
<?php |
| 2 |
namespace WPAdminify\Inc\Classes\Notifications\Base; |
| 3 |
use WPAdminify\Inc\Classes\Helper; |
| 4 |
|
| 5 |
// No, Direct access Sir !!! |
| 6 |
if ( ! defined( 'ABSPATH' ) ) { |
| 7 |
exit; |
| 8 |
} |
| 9 |
|
| 10 |
trait User_Data { |
| 11 |
|
| 12 |
/** |
| 13 |
* Get plugins list |
| 14 |
* |
| 15 |
* @author Jewel Theme <support@jeweltheme.com> |
| 16 |
*/ |
| 17 |
public function get_plugins_list() { |
| 18 |
if ( ! function_exists( 'get_plugins' ) ) { |
| 19 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 20 |
} |
| 21 |
|
| 22 |
$plugins = get_plugins(); |
| 23 |
$activated_plugins = '==== Activated Plugins List ====' . PHP_EOL; |
| 24 |
$deactivated_plugins = PHP_EOL . PHP_EOL . '==== Deactivated Plugins List ====' . PHP_EOL; |
| 25 |
|
| 26 |
$active_plugins_keys = get_option( 'active_plugins', array() ); |
| 27 |
$inactive_counter = array(); |
| 28 |
$active_counter = array(); |
| 29 |
|
| 30 |
foreach ( $plugins as $key => $plugin ) { |
| 31 |
$network_plugins = ! empty( $plugin['Network'] ) ? $plugin['Network'] : 'n/a'; |
| 32 |
$PluginURI = ! empty( $plugin['PluginURI'] ) ? $plugin['PluginURI'] : 'n/a'; |
| 33 |
$new_plugin = $plugin['Name'] . '- v' . $plugin['Version'] . ', URL: ' . $PluginURI . ', Network: ' . $network_plugins; |
| 34 |
|
| 35 |
if ( is_plugin_inactive( $key ) ) { |
| 36 |
$deactivated_plugins .= $new_plugin . PHP_EOL; |
| 37 |
} else { |
| 38 |
$activated_plugins .= $new_plugin . PHP_EOL; |
| 39 |
} |
| 40 |
|
| 41 |
if ( in_array( $key, $active_plugins_keys ) ) { |
| 42 |
// Remove active plugins from list so we can show active and inactive separately . |
| 43 |
unset( $plugins[ $key ] ); |
| 44 |
$inactive_counter[ $key ] = $key; |
| 45 |
} else { |
| 46 |
$active_counter[ $key ] = $key; |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
return array( |
| 51 |
'active_plugins' => $activated_plugins, |
| 52 |
'active_plugins_count' => count( $active_counter ), |
| 53 |
'deactivated_plugins' => $deactivated_plugins, |
| 54 |
'deactivated_plugins_count' => count( $inactive_counter ), |
| 55 |
); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Get Server Info |
| 60 |
* |
| 61 |
* @author Jewel Theme <support@jeweltheme.com> |
| 62 |
*/ |
| 63 |
public function get_server_info() { |
| 64 |
global $wpdb; |
| 65 |
|
| 66 |
$server_data = array(); |
| 67 |
|
| 68 |
$server_software = ( isset( $_SERVER['SERVER_SOFTWARE'] ) && ! empty( $_SERVER['SERVER_SOFTWARE'] ) ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : ''; |
| 69 |
if ( $server_software ) { |
| 70 |
$server_data['software'] = $server_software; |
| 71 |
} |
| 72 |
|
| 73 |
if ( function_exists( 'phpversion' ) ) { |
| 74 |
$server_data['php_version'] = phpversion(); |
| 75 |
} |
| 76 |
|
| 77 |
$server_data['mysql_version'] = $wpdb->db_version(); |
| 78 |
|
| 79 |
$server_data['php_max_upload_size'] = size_format( wp_max_upload_size() ); |
| 80 |
$server_data['php_default_timezone'] = date_default_timezone_get(); |
| 81 |
$server_data['php_soap'] = class_exists( 'SoapClient' ) ? 'Yes' : 'No'; |
| 82 |
$server_data['php_fsockopen'] = function_exists( 'fsockopen' ) ? 'Yes' : 'No'; |
| 83 |
$server_data['php_curl'] = function_exists( 'curl_init' ) ? 'Yes' : 'No'; |
| 84 |
|
| 85 |
return $server_data; |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Get WP Info |
| 90 |
* |
| 91 |
* @author Jewel Theme <support@jeweltheme.com> |
| 92 |
*/ |
| 93 |
public function get_wp_info() { |
| 94 |
$wp_data = array(); |
| 95 |
|
| 96 |
$wp_data['memory_limit'] = WP_MEMORY_LIMIT; |
| 97 |
$wp_data['debug_mode'] = ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? 'Yes' : 'No'; |
| 98 |
$wp_data['locale'] = get_locale(); |
| 99 |
$wp_data['version'] = get_bloginfo( 'version' ); |
| 100 |
$wp_data['multisite'] = is_multisite() ? 'Yes' : 'No'; |
| 101 |
$wp_data['theme_slug'] = get_stylesheet(); |
| 102 |
|
| 103 |
$theme = wp_get_theme( $wp_data['theme_slug'] ); |
| 104 |
|
| 105 |
$wp_data['theme_name'] = $theme->get( 'Name' ); |
| 106 |
$wp_data['theme_version'] = $theme->get( 'Version' ); |
| 107 |
$wp_data['theme_uri'] = $theme->get( 'ThemeURI' ); |
| 108 |
$wp_data['theme_author'] = $theme->get( 'Author' ); |
| 109 |
|
| 110 |
return $wp_data; |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* Get User Counts |
| 115 |
* |
| 116 |
* @author Jewel Theme <support@jeweltheme.com> |
| 117 |
*/ |
| 118 |
public function get_user_counts() { |
| 119 |
$user_count = array(); |
| 120 |
$user_count_data = count_users(); |
| 121 |
$user_count['total'] = $user_count_data['total_users']; |
| 122 |
|
| 123 |
// Get user count based on user role . |
| 124 |
foreach ( $user_count_data['avail_roles'] as $role => $count ) { |
| 125 |
if ( ! $count ) { |
| 126 |
continue; |
| 127 |
} |
| 128 |
|
| 129 |
$user_count[ $role ] = $count; |
| 130 |
} |
| 131 |
|
| 132 |
return $user_count; |
| 133 |
} |
| 134 |
|
| 135 |
/** |
| 136 |
* Get Site Name |
| 137 |
* |
| 138 |
* @author Jewel Theme <support@jeweltheme.com> |
| 139 |
*/ |
| 140 |
public function get_site_name() { |
| 141 |
$site_name = get_bloginfo( 'name' ); |
| 142 |
|
| 143 |
if ( empty( $site_name ) ) { |
| 144 |
$site_name = get_bloginfo( 'description' ); |
| 145 |
$site_name = wp_trim_words( $site_name, 3, '' ); |
| 146 |
} |
| 147 |
|
| 148 |
if ( empty( $site_name ) ) { |
| 149 |
$site_name = esc_url( home_url() ); |
| 150 |
} |
| 151 |
|
| 152 |
return $site_name; |
| 153 |
} |
| 154 |
|
| 155 |
/** |
| 156 |
* Check if Local Server |
| 157 |
* |
| 158 |
* @return boolean |
| 159 |
* @author Jewel Theme <support@jeweltheme.com> |
| 160 |
*/ |
| 161 |
public function is_local_server() { |
| 162 |
$host = isset( $_SERVER['HTTP_HOST'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : 'localhost'; |
| 163 |
$ip = isset( $_SERVER['SERVER_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_ADDR'] ) ) : '127.0.0.1'; |
| 164 |
$is_local = false; |
| 165 |
|
| 166 |
if ( |
| 167 |
in_array( $ip, array( '127.0.0.1', '::1' ) ) |
| 168 |
|| ! strpos( $host, '.' ) |
| 169 |
|| in_array( strrchr( $host, '.' ), array( '.test', '.testing', '.local', '.localhost', '.localdomain' ) ) |
| 170 |
) { |
| 171 |
$is_local = true; |
| 172 |
} |
| 173 |
|
| 174 |
return apply_filters( 'jltwp_adminify_is_local', $is_local ); |
| 175 |
} |
| 176 |
|
| 177 |
/** |
| 178 |
* Get IP Address |
| 179 |
* |
| 180 |
* @author Jewel Theme <support@jeweltheme.com> |
| 181 |
*/ |
| 182 |
public function get_user_ip_address() { |
| 183 |
$response = wp_remote_get( 'https://icanhazip.com/' ); |
| 184 |
|
| 185 |
if ( is_wp_error( $response ) ) { |
| 186 |
return ''; |
| 187 |
} |
| 188 |
|
| 189 |
$ip_address = trim( wp_remote_retrieve_body( $response ) ); |
| 190 |
|
| 191 |
if ( ! filter_var( $ip_address, FILTER_VALIDATE_IP ) ) { |
| 192 |
return ''; |
| 193 |
} |
| 194 |
|
| 195 |
return $ip_address; |
| 196 |
} |
| 197 |
|
| 198 |
/** |
| 199 |
* Get Collection Data |
| 200 |
* |
| 201 |
* @return void |
| 202 |
* @author Jewel Theme <support@jeweltheme.com> |
| 203 |
*/ |
| 204 |
public function get_collect_data( $user_id, $arr = [] ){ |
| 205 |
|
| 206 |
$billing_phone = ''; |
| 207 |
$billing_company = ''; |
| 208 |
$billing_address_1 = ''; |
| 209 |
$billing_address_2 = ''; |
| 210 |
$billing_city = ''; |
| 211 |
$billing_postcode = ''; |
| 212 |
$billing_country = ''; |
| 213 |
$billing_state = ''; |
| 214 |
|
| 215 |
// WooCommerce . |
| 216 |
if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) { |
| 217 |
$billing_phone = get_user_meta( $user_id, 'billing_phone', true ); |
| 218 |
$billing_company = get_user_meta( $user_id, 'billing_company', true ); |
| 219 |
$billing_address_1 = get_user_meta( $user_id, 'billing_address_1', true ); |
| 220 |
$billing_address_2 = get_user_meta( $user_id, 'billing_address_2', true ); |
| 221 |
$billing_city = get_user_meta( $user_id, 'billing_city', true ); |
| 222 |
$billing_postcode = get_user_meta( $user_id, 'billing_postcode', true ); |
| 223 |
$billing_country = get_user_meta( $user_id, 'billing_country', true ); |
| 224 |
$billing_state = get_user_meta( $user_id, 'billing_state', true ); |
| 225 |
} |
| 226 |
|
| 227 |
$all_plugins = $this->get_plugins_list(); |
| 228 |
$active_deactivate_plugins = $all_plugins['active_plugins'] . $all_plugins['deactivated_plugins']; |
| 229 |
|
| 230 |
$data = array( |
| 231 |
'phone' => $billing_phone, |
| 232 |
'company' => $billing_company, |
| 233 |
'address_1' => $billing_address_1, |
| 234 |
'address_2' => $billing_address_2, |
| 235 |
'city' => $billing_city, |
| 236 |
'postcode' => $billing_postcode, |
| 237 |
'country' => $billing_country, |
| 238 |
'state' => $billing_state, |
| 239 |
'list_id' => [3, 23], |
| 240 |
'tag_id' => [103, 40, 45], |
| 241 |
'server' => $this->get_server_info(), |
| 242 |
'wp' => $this->get_wp_info(), |
| 243 |
'number_of_users' => $this->get_user_counts(), |
| 244 |
'site_language' => \get_bloginfo( 'language' ), |
| 245 |
'active_inactive_plugins' => $active_deactivate_plugins, |
| 246 |
'site_name' => $this->get_site_name(), |
| 247 |
'site_source' => 'https://jeweltheme.com', |
| 248 |
'is_local' => $this->is_local_server(), |
| 249 |
'ip_address' => $this->get_user_ip_address(), |
| 250 |
'site_url' => \get_site_url(), // custom field end / need to be create this in . |
| 251 |
'is_active_product' => 1, |
| 252 |
'installed_product_slug' => WP_ADMINIFY_SLUG, |
| 253 |
); |
| 254 |
|
| 255 |
$payload_data = array_merge( $arr, $data ); |
| 256 |
$endpoint_url = Helper::crm_endpoint(); |
| 257 |
if ( 'local' === wp_get_environment_type() ) { |
| 258 |
$response = wp_remote_post( |
| 259 |
$endpoint_url, |
| 260 |
array( |
| 261 |
'body' => $payload_data, |
| 262 |
'timeout' => 100, |
| 263 |
'sslverify' => false, |
| 264 |
) |
| 265 |
); |
| 266 |
} else { |
| 267 |
// 'production' === wp_get_environment_type() . |
| 268 |
$response = wp_safe_remote_post( |
| 269 |
$endpoint_url, |
| 270 |
array( |
| 271 |
'body' => $payload_data, |
| 272 |
'timeout' => 100, |
| 273 |
) |
| 274 |
); |
| 275 |
} |
| 276 |
|
| 277 |
return $response; |
| 278 |
} |
| 279 |
} |
| 280 |
|