/** * Test the difference output from hours_between functionality */ public function test_hours_between() { $diff = 4; $start = strtotime('-' . $diff . ' hours'); $end = time(); $this->assertEquals(Yoast_GA_Utils::hours_between($start, $end), $diff); }
/** * Check if something went wrong with API calls to Google Analytics */ public function check_for_ga_issues() { $last_run = get_option('yst_ga_last_wp_run'); $has_failed = get_option('yst_ga_api_call_fail', false); // Show error, something went wrong if ($has_failed && ($last_run === false || Yoast_GA_Utils::hours_between(strtotime($last_run), time()) >= 48)) { $notice_type = 'warning_fetching_data'; // Authentication has been successful, so there will be an access token if (!$this->client->getAccessToken()) { $notice_type .= '_authenticate'; } add_action('admin_notices', array('Yoast_Google_Analytics_Notice', $notice_type)); } }
/** * Init function for the settings of GA */ public function init_settings() { $this->options = $this->get_options(); $this->api = Yoast_Api_Libs::load_api_libraries(array('google', 'googleanalytics')); // Listener for reconnecting with google analytics $this->google_analytics_listener(); if (is_null($this->get_tracking_code()) && $this->show_admin_warning()) { add_action('admin_notices', array($this, 'config_warning')); } $last_run = get_option('yst_ga_last_wp_run'); if ($last_run === false || Yoast_GA_Utils::hours_between(strtotime($last_run), time()) >= 48) { // Show error, something went wrong if (!is_null($this->get_tracking_code()) && empty($this->options['manual_ua_code_field']) && $this->show_admin_dashboard_warning()) { add_action('admin_notices', array($this, 'warning_fetching_data')); } } if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (!function_exists('wp_verify_nonce')) { require_once ABSPATH . 'wp-includes/pluggable.php'; } if (isset($_POST['ga-form-settings']) && wp_verify_nonce($_POST['yoast_ga_nonce'], 'save_settings')) { if (!isset($_POST['ignore_users'])) { $_POST['ignore_users'] = array(); } // Post submitted and verified with our nonce $this->save_settings($_POST); } } /** * Show the notifications if we have one */ $this->show_notification('ga_notifications'); // Load the Google Analytics Dashboards functionality $dashboards = Yoast_GA_Dashboards::get_instance(); $dashboards->init_dashboards($this->get_current_profile()); }
/** * Wrapper to enable stubbing in tests. */ protected function wp_seo_active() { return Yoast_GA_Utils::wp_seo_active(); }
/** * Check if the WP cron did run yesterday. If not, we need to run it form here */ public function check_api_call_hook() { $last_run = $this->get_last_aggregate_run(); /** * Transient doesn't exists, so we need to run the * hook (This function runs already on Shutdown so * we can call it directly from now on) or the last run has ben more than 24 hours */ if ($last_run === false || Yoast_GA_Utils::hours_between(strtotime($last_run), time()) >= 24) { $this->aggregate_data(); } }