User agent tracking

This commit is contained in:
Mike Jolley 2016-09-12 22:11:05 +01:00
parent 59dcb30928
commit 0e6bbc8210
2 changed files with 24 additions and 0 deletions

View File

@ -128,6 +128,9 @@ class WC_Tracker {
// Template overrides
$data['template_overrides'] = self::get_all_template_overrides();
// Template overrides
$data['admin_user_agents'] = self::get_admin_user_agents();
return apply_filters( 'woocommerce_tracker_data', $data );
}
@ -395,6 +398,14 @@ class WC_Tracker {
}
return $override_data;
}
/**
* When an admin user logs in, there user agent is tracked in user meta and collected here.
* @return array
*/
private static function get_admin_user_agents() {
return array_filter( (array) get_option( 'woocommerce_tracker_ua', array() ) );
}
}
WC_Tracker::init();

View File

@ -1420,3 +1420,16 @@ function wc_do_deprecated_action( $action, $args, $deprecated_in, $replacement )
do_action_ref_array( $action, $args );
}
}
/**
* Store user agents. Used for tracker.
* @since 2.7.0
*/
function wc_maybe_store_user_agent( $user_login, $user ) {
if ( 'yes' === get_option( 'woocommerce_allow_tracking', 'no' ) && user_can( $user, 'manage_woocommerce' ) ) {
$admin_user_agents = array_filter( (array) get_option( 'woocommerce_tracker_ua', array() ) );
$admin_user_agents[] = wc_get_user_agent();
update_option( 'woocommerce_tracker_ua', array_unique( $admin_user_agents ) );
}
}
add_action( 'wp_login', 'wc_maybe_store_user_agent', 10, 2 );