: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
// Preventing to direct access
defined( 'ABSPATH' ) OR die( 'Direct access not acceptable!' );
if ( ! class_exists( 'WWS_Analytics' ) ) :
* Plugin public analytics report
* @package WeCreativez/Classes
public function __construct() {
add_action( "wp_ajax_wws_click_analytics", array( $this, 'click_analytics' ) );
add_action( "wp_ajax_nopriv_wws_click_analytics", array( $this, 'click_analytics' ) );
add_action( "wp_ajax_wws_analytics_deep_report", array( $this, 'analytics_deep_report' ) );
add_action( "wp_ajax_nopriv_wws_analytics_deep_report", array( $this, 'analytics_deep_report' ) );
add_action( 'admin_init', array( $this, 'delete_complete_analytics' ) );
add_action( 'admin_init', array( $this, 'delete_analytics' ) );
public function delete_complete_analytics() {
if ( ! isset( $_GET['wws_delete_complete_analytics'] ) || ! wp_verify_nonce( $_GET['_wpnonce'] ) ) {
$this->_delete_all_analytics();
wp_redirect( admin_url( 'admin.php?page=wc-whatsapp-support-analytics' ) );
public function delete_analytics() {
if ( ! isset( $_GET['wws_delete_analytics'] ) ) {
$wws_analytics_table = $wpdb->prefix.'wws_analytics';
$wpdb->delete( $wws_analytics_table, array( 'ID' => $_GET['wws_delete_analytics'] ), array( '%d' ) );
wp_redirect( wp_get_referer() );
public function click_analytics() {
check_ajax_referer( 'wws-security-token', 'security' );
$click_analytics = apply_filters( 'wws_click_analytics', array(
'visitor_ip' => sanitize_text_field( $this->_get_current_ip() ),
'number' => ( isset( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : 'N/A' ),
'message' => ( isset( $_POST['message'] ) ? sanitize_text_field( $_POST['message'] ) : 'N/A' ),
'through' => ( isset( $_POST['through'] ) ? sanitize_text_field( $_POST['through'] ) : 'N/A' ),
'referral' => esc_url_raw( $this->_get_current_url() ),
'device_type' => ( wp_is_mobile() == true ? 'Mobile' : 'Desktop' ),
'os' => sanitize_text_field( $this->_getOS() ),
'browser' => sanitize_text_field( $this->getBrowser() ),
'date' => current_time('M d, y - H:i:s'),
do_action( 'wws_before_click_analytics', $click_analytics );
$wpdb->prefix.'wws_analytics',
do_action( 'wws_after_click_analytics', $click_analytics );
public function analytics_deep_report() {
$ip_data = maybe_unserialize( file_get_contents( "http://ip-api.com/php/$ip" ) );
$ip_city = isset( $ip_data['city'] ) ? $ip_data['city'] : '';
$ip_region = isset( $ip_data['regionName'] ) ? $ip_data['regionName'] : '';
$ip_country = isset( $ip_data['country'] ) ? $ip_data['country'] : '';
$ip_zip = isset( $ip_data['zip'] ) ? $ip_data['zip'] : '';
$ip_lon = isset( $ip_data['lon'] ) ? $ip_data['lon'] : '';
$ip_lat = isset( $ip_data['lat'] ) ? $ip_data['lat'] : '';
$ip_org = isset( $ip_data['org'] ) ? $ip_data['org'] : '';
$ip_as = isset( $ip_data['as'] ) ? $ip_data['as'] : '';
$ip_isp = isset( $ip_data['isp'] ) ? $ip_data['isp'] : '';
$ip_timezone = isset( $ip_data['timezone'] ) ? $ip_data['timezone'] : '';
require_once WWS_PLUGIN_PATH . 'includes/admin/views/analytics/admin-deep-analytics.php';
protected function _get_current_url() {
protected function _get_current_ip() {
if ( isset( $_SERVER['HTTP_CLIENT_IP'] ) ) {
//check ip from share internet
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
//to check ip is pass from proxy
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
$ip = $_SERVER['REMOTE_ADDR'];
protected function _getOS() {
$os_platform = "Unknown OS Platform";
'/windows nt 10/i' => 'Windows 10',
'/windows nt 6.3/i' => 'Windows 8.1',
'/windows nt 6.2/i' => 'Windows 8',
'/windows nt 6.1/i' => 'Windows 7',
'/windows nt 6.0/i' => 'Windows Vista',
'/windows nt 5.2/i' => 'Windows Server 2003/XP x64',
'/windows nt 5.1/i' => 'Windows XP',
'/windows xp/i' => 'Windows XP',
'/windows nt 5.0/i' => 'Windows 2000',
'/windows me/i' => 'Windows ME',
'/win98/i' => 'Windows 98',
'/win95/i' => 'Windows 95',
'/win16/i' => 'Windows 3.11',
'/macintosh|mac os x/i' => 'Mac OS X',
'/mac_powerpc/i' => 'Mac OS 9',
'/android/i' => 'Android',
'/blackberry/i' => 'BlackBerry',
foreach ($os_array as $regex => $value)
if (preg_match($regex, $_SERVER['HTTP_USER_AGENT']))
protected function getBrowser(){
$user_agent = $_SERVER['HTTP_USER_AGENT'];
if(strpos($user_agent, 'Maxthon') !== FALSE)
elseif(strpos($user_agent, 'SeaMonkey') !== FALSE)
elseif(strpos($user_agent, 'Vivaldi') !== FALSE)
elseif(strpos($user_agent, 'Arora') !== FALSE)
elseif(strpos($user_agent, 'Avant Browser') !== FALSE)
elseif(strpos($user_agent, 'Beamrise') !== FALSE)
elseif(strpos($user_agent, 'Epiphany') !== FALSE)
elseif(strpos($user_agent, 'Chromium') !== FALSE)
elseif(strpos($user_agent, 'Iceweasel') !== FALSE)
elseif(strpos($user_agent, 'Galeon') !== FALSE)
elseif(strpos($user_agent, 'Edge') !== FALSE)
elseif(strpos($user_agent, 'Trident') !== FALSE) //IE 11
return 'Internet Explorer';
elseif(strpos($user_agent, 'MSIE') !== FALSE)
return 'Internet Explorer';
elseif(strpos($user_agent, 'Opera Mini') !== FALSE)
elseif(strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR') !== FALSE)
elseif(strpos($user_agent, 'Firefox') !== FALSE)
return 'Mozilla Firefox';
elseif(strpos($user_agent, 'Chrome') !== FALSE)
elseif(strpos($user_agent, 'Safari') !== FALSE)
elseif(strpos($user_agent, 'iTunes') !== FALSE)
elseif(strpos($user_agent, 'Konqueror') !== FALSE)
elseif(strpos($user_agent, 'Dillo') !== FALSE)
elseif(strpos($user_agent, 'Netscape') !== FALSE)
elseif(strpos($user_agent, 'Midori') !== FALSE)
elseif(strpos($user_agent, 'ELinks') !== FALSE)
elseif(strpos($user_agent, 'Links') !== FALSE)
elseif(strpos($user_agent, 'Lynx') !== FALSE)
elseif(strpos($user_agent, 'w3m') !== FALSE)
public static function get_complete_analytics( $order = 'DESC' ) {
$wws_analytics_table = $wpdb->prefix.'wws_analytics';
return $wpdb->get_results( "SELECT * FROM {$wws_analytics_table} ORDER BY id $order", ARRAY_A );
public static function get_total_clicks() {
$wws_analytics_table = $wpdb->prefix.'wws_analytics';
return count( $wpdb->get_results( "SELECT id FROM {$wws_analytics_table}", ARRAY_A ) );
public static function get_total_clicks_by_mobile() {
$wws_analytics_table = $wpdb->prefix.'wws_analytics';
return count( $wpdb->get_results( "SELECT id FROM {$wws_analytics_table} WHERE device_type = 'Mobile'", ARRAY_A ) );
public static function get_total_clicks_by_desktop() {
$wws_analytics_table = $wpdb->prefix.'wws_analytics';
return count( $wpdb->get_results( "SELECT id FROM {$wws_analytics_table} WHERE device_type = 'Desktop'", ARRAY_A ) );
* Display top 10 IP address analytic.
* @global $wpdb WordPress database connection.
public static function the_top_ten_ip_address() {
$query = $wpdb->get_results(
"SELECT COUNT( visitor_ip ) as count, visitor_ip
FROM {$wpdb->prefix}wws_analytics
$html .= '<th>' . esc_html__( 'IP Address', 'wc-wws' ) . '</th>';
$html .= '<th>' . esc_html__( 'Clicks', 'wc-wws' ) . '</th>';
foreach ( $query as $q ) {
$html .= '<td>' . esc_html( $q['visitor_ip'] ) . '</td>';
$html .= '<td>' . esc_html( $q['count'] ) . '</td>';
* Display top 10 referral links analytic.
* @global $wpdb WordPress database connection.
public static function the_top_ten_referral_links() {
$query = $wpdb->get_results(
"SELECT COUNT( referral ) as count, referral
FROM {$wpdb->prefix}wws_analytics
$html .= '<th>' . esc_html__( 'Referral Links', 'wc-wws' ) . '</th>';
$html .= '<th>' . esc_html__( 'Clicks', 'wc-wws' ) . '</th>';
foreach ( $query as $q ) {
$html .= '<td><a href="' . esc_url( $q['referral'] ) . '" target="_blank">' . esc_url( $q['referral'] ) . '</a></td>';
$html .= '<td>' . esc_html( $q['count'] ) . '</td>';
* Display top 10 operating systems analytic.
* @global $wpdb WordPress database connection.
public static function the_top_ten_operating_systems() {
$query = $wpdb->get_results(
"SELECT COUNT( os ) as count, os
FROM {$wpdb->prefix}wws_analytics
$html .= '<th>' . esc_html__( 'Operating Systems', 'wc-wws' ) . '</th>';
$html .= '<th>' . esc_html__( 'Clicks', 'wc-wws' ) . '</th>';
foreach ( $query as $q ) {
$html .= '<td>' . esc_html( $q['os'] ) . '</td>';
$html .= '<td>' . esc_html( $q['count'] ) . '</td>';
* Display top 10 browsers analytic.
* @global $wpdb WordPress database connection.
public static function the_top_ten_browsers() {
$query = $wpdb->get_results(
"SELECT COUNT( browser ) as count, browser
FROM {$wpdb->prefix}wws_analytics
$html .= '<th>' . esc_html__( 'Browsers', 'wc-wws' ) . '</th>';
$html .= '<th>' . esc_html__( 'Clicks', 'wc-wws' ) . '</th>';
foreach ( $query as $q ) {
$html .= '<td>' . esc_html( $q['browser'] ) . '</td>';
$html .= '<td>' . esc_html( $q['count'] ) . '</td>';
* Get current month analytics in chart format.
* @global $wpdb WordPress database connection.
public static function get_current_month_chart_data() {
// Numeric representation of a month, without leading zeros
$current_month = current_time( 'n' );
// A two digit representation of a year
$current_year = current_time( 'y' );
// Calculate days in a month
$days_in_month = cal_days_in_month( CAL_GREGORIAN, $current_month, $current_year );
1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0,
6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0,
11 => 0, 12 => 0, 13 => 0, 14 => 0, 15 => 0,
16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0,
21 => 0, 22 => 0, 23 => 0, 24 => 0, 25 => 0,
26 => 0, 27 => 0, 28 => 0,
if ( $days_in_month > 28 ) {
if ( $days_in_month > 29 ) {
if ( $days_in_month > 30 ) {