Skip to content

Commit

Permalink
Merge pull request woocommerce#21322 from woocommerce/update/tracker
Browse files Browse the repository at this point in the history
Tracker changes
  • Loading branch information
claudiulodro authored Sep 11, 2018
2 parents e1255de + c572327 commit a9b635e
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions includes/class-wc-tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,14 @@ private static function get_tracking_data() {
$data['jetpack_is_staging'] = ( class_exists( 'Jetpack' ) && is_callable( 'Jetpack::is_staging_site' ) && Jetpack::is_staging_site() ) ? 'yes' : 'no';
$data['connect_installed'] = class_exists( 'WC_Connect_Loader' ) ? 'yes' : 'no';
$data['connect_active'] = ( class_exists( 'WC_Connect_Loader' ) && wp_next_scheduled( 'wc_connect_fetch_service_schemas' ) ) ? 'yes' : 'no';
$data['helper_connected'] = self::get_helper_connected();

// Store count info.
$data['users'] = self::get_user_counts();
$data['products'] = self::get_product_counts();
$data['orders'] = self::get_orders();
$data['reviews'] = self::get_review_counts();
$data['categories'] = self::get_category_counts();

// Payment gateway info.
$data['gateways'] = self::get_active_payment_gateways();
Expand Down Expand Up @@ -258,6 +261,21 @@ private static function get_all_plugins() {
);
}

/**
* Check to see if the helper is connected to woocommerce.com
*
* @return string
*/
private static function get_helper_connected() {
if ( class_exists( 'WC_Helper_Options' ) && is_callable( 'WC_Helper_Options::get' ) ) {
$authenticated = WC_Helper_Options::get( 'auth' );
} else {
$authenticated = '';
}
return ( ! empty( $authenticated ) ) ? 'yes' : 'no';
}


/**
* Get user totals based on user role.
*
Expand Down Expand Up @@ -321,6 +339,41 @@ private static function get_orders() {
return array_merge( $order_dates, $order_counts, $order_totals );
}

/**
* Get review counts for different statuses.
*
* @return array
*/
private static function get_review_counts() {
global $wpdb;
$review_count = array();
$counts = $wpdb->get_results( "
SELECT comment_approved, COUNT(*) AS num_reviews
FROM {$wpdb->comments}
WHERE comment_type = 'review'
GROUP BY comment_approved
", ARRAY_A );
if ( $counts ) {
foreach ( $counts as $count ) {
if ( 1 === $count['comment_approved'] ) {
$review_count['approved'] = $count['num_reviews'];
} else {
$review_count['pending'] = $count['num_reviews'];
}
}
}
return $review_count;
}

/**
* Get the number of product categories.
*
* @return int
*/
private static function get_category_counts() {
return wp_count_terms( 'product_cat' );
}

/**
* Get a list of all active payment gateways.
*
Expand Down

0 comments on commit a9b635e

Please sign in to comment.