/** * Get stats data for this site * * @since 4.1.0 * * @param WP_REST_Request $data { * Array of parameters received by request. * * @type string $date Date range to restrict results to. * } * * @return int|string Number of spam blocked by Akismet. Otherwise, an error message. */ public function get_stats_data(WP_REST_Request $data) { // Get parameters to fetch Stats data. $range = $data->get_param('range'); // If no parameters were passed. if (empty($range) || !in_array($range, array('day', 'week', 'month'), true)) { $range = 'day'; } if (!function_exists('stats_get_from_restapi')) { require_once JETPACK__PLUGIN_DIR . 'modules/stats.php'; } $response = array('general' => stats_get_from_restapi()); switch ($range) { case 'day': $response['day'] = stats_get_from_restapi(array(), 'visits?unit=day&quantity=30'); break; case 'week': $response['week'] = stats_get_from_restapi(array(), 'visits?unit=week&quantity=14'); break; case 'month': $response['month'] = stats_get_from_restapi(array(), 'visits?unit=month&quantity=12&'); break; } return rest_ensure_response($response); }
/** * Get stats data for this site * * @since 4.1.0 * * @param WP_REST_Request $data { * Array of parameters received by request. * * @type string $date Date range to restrict results to. * } * * @return int|string Number of spam blocked by Akismet. Otherwise, an error message. */ public function get_stats_data(WP_REST_Request $data) { // Get parameters to fetch Stats data. $range = $data->get_param('range'); // If no parameters were passed. if (empty($range) || !in_array($range, array('day', 'week', 'month'), true)) { $range = 'day'; } if (!function_exists('stats_get_from_restapi')) { require_once JETPACK__PLUGIN_DIR . 'modules/stats.php'; } switch ($range) { // This is always called first on page load case 'day': $initial_stats = stats_get_from_restapi(); return rest_ensure_response(array('general' => $initial_stats, 'day' => isset($initial_stats->visits) ? $initial_stats->visits : array())); case 'week': return rest_ensure_response(array('week' => stats_get_from_restapi(array(), 'visits?unit=week&quantity=14'))); case 'month': return rest_ensure_response(array('month' => stats_get_from_restapi(array(), 'visits?unit=month&quantity=12&'))); } }
function build_initial_stats_shape() { if (!function_exists('stats_get_from_restapi')) { require_once JETPACK__PLUGIN_DIR . 'modules/stats.php'; } return array('general' => stats_get_from_restapi(), 'day' => stats_get_from_restapi(array(), 'visits?unit=day&quantity=30'), 'week' => stats_get_from_restapi(array(), 'visits?unit=week&quantity=14'), 'month' => stats_get_from_restapi(array(), 'visits?unit=month&quantity=12&')); }