2015-01-03 23:18:27 +02:00
< ? php
class UM_Admin_Tracking {
private $data ;
public function __construct () {
$this -> schedule_send ();
2015-01-04 03:10:49 +02:00
add_action ( 'admin_notices' , array ( $this , 'admin_notices' ), 10 );
2015-01-03 23:18:27 +02:00
}
/***
*** @setup info array
***/
private function setup_data () {
$data = array ();
// Retrieve current theme info
if ( get_bloginfo ( 'version' ) < '3.4' ) {
$theme_data = get_theme_data ( get_stylesheet_directory () . '/style.css' );
$theme = $theme_data [ 'Name' ];
$theme_ver = $theme_data [ 'Version' ];
} else {
$theme_data = wp_get_theme ();
$theme = $theme_data -> Name ;
$theme_ver = $theme_data -> Version ;
}
$data [ 'url' ] = home_url ();
2015-01-04 03:10:49 +02:00
2015-01-03 23:18:27 +02:00
$data [ 'theme' ] = $theme ;
$data [ 'theme_version' ] = $theme_ver ;
2015-01-04 03:10:49 +02:00
2015-01-03 23:18:27 +02:00
$data [ 'wp_version' ] = get_bloginfo ( 'version' );
2015-01-04 03:10:49 +02:00
2015-01-20 14:43:05 +02:00
$data [ 'version' ] = ultimatemember_version ;
2015-01-04 03:10:49 +02:00
2015-01-03 23:18:27 +02:00
$result = count_users ();
$data [ 'users_count' ] = $result [ 'total_users' ];
// Retrieve current plugin information
if ( ! function_exists ( 'get_plugins' ) ) {
include ABSPATH . '/wp-admin/includes/plugin.php' ;
}
$plugins = array_keys ( get_plugins () );
$active_plugins = get_option ( 'active_plugins' , array () );
foreach ( $plugins as $key => $plugin ) {
if ( in_array ( $plugin , $active_plugins ) ) {
// Remove active plugins from list so we can show active and inactive separately
unset ( $plugins [ $key ] );
}
}
$data [ 'active_plugins' ] = $active_plugins ;
$data [ 'inactive_plugins' ] = $plugins ;
2015-01-04 03:10:49 +02:00
$data [ 'language' ] = get_bloginfo ( 'language' );
$data [ 'multisite' ] = ( is_multisite () ) ? 1 : 0 ;
2015-01-03 23:18:27 +02:00
$this -> data = $data ;
}
/***
*** @check if tracking is allowed
***/
private function tracking_allowed () {
if ( ! um_get_option ( 'allow_tracking' ) )
return 0 ;
if ( stristr ( network_site_url ( '/' ), 'dev' ) !== false ||
stristr ( network_site_url ( '/' ), 'localhost' ) !== false ||
stristr ( network_site_url ( '/' ), ':8888' ) !== false // This is common with MAMP on OS X
) {
return 0 ;
}
return 1 ;
}
/***
*** @get last send time
***/
private function get_last_send () {
return get_option ( 'um_tracking_last_send' );
}
/***
*** @send a report
***/
public function send_checkin ( $override = false ) {
if ( ! $this -> tracking_allowed () && ! $override )
return ;
// Send a maximum of once per week
$last_send = $this -> get_last_send ();
if ( $last_send && $last_send > strtotime ( '-1 week' ) )
return ;
$this -> setup_data ();
2015-01-22 18:50:13 +02:00
$request = wp_remote_post ( 'https://ultimatemember.com/?um_action=checkin' , array (
2015-01-03 23:18:27 +02:00
'method' => 'POST' ,
'timeout' => 20 ,
'redirection' => 5 ,
'httpversion' => '1.0' ,
'blocking' => true ,
'body' => $this -> data ,
2015-01-20 14:43:05 +02:00
'user-agent' => 'UM/' . ultimatemember_version . '; ' . get_bloginfo ( 'url' ),
2015-01-03 23:18:27 +02:00
) );
update_option ( 'um_tracking_last_send' , time () );
2015-01-04 03:10:49 +02:00
2015-01-03 23:18:27 +02:00
}
/***
*** @run a scheduled report
***/
private function schedule_send () {
add_action ( 'um_weekly_scheduled_events' , array ( $this , 'send_checkin' ) );
}
/***
*** @show admin notices
***/
public function admin_notices () {
if ( ! current_user_can ( 'manage_options' ) )
return ;
$hide_notice = get_option ( 'um_tracking_notice' );
if ( $hide_notice )
return ;
$optin_url = add_query_arg ( 'um_adm_action' , 'opt_into_tracking' );
$optout_url = add_query_arg ( 'um_adm_action' , 'opt_out_of_tracking' );
2015-01-06 00:38:33 +02:00
echo '<div class="updated" style="border-color: #3ba1da;"><p>' ;
2015-01-04 03:10:49 +02:00
2015-01-21 21:32:13 +02:00
echo __ ( 'Help us improve Ultimate Member’ s compatibility with other plugins and themes by allowing us to track non-sensitive data on your site. Click <a href="https://ultimatemember.com/tracking/" target="_blank">here</a> to see what data we track.' , 'ultimatemember' );
2015-01-04 03:10:49 +02:00
echo '</p>' ;
echo '<p><a href="' . esc_url ( $optin_url ) . '" class="button button-primary">' . __ ( 'Allow tracking' , 'ultimatemember' ) . '</a>' ;
echo ' <a href="' . esc_url ( $optout_url ) . '" class="button-secondary">' . __ ( 'Do not allow tracking' , 'ultimatemember' ) . '</a></p></div>' ;
2015-01-03 23:18:27 +02:00
}
}