/** * Test if the dashboards are disabled after updating the option * * @covers Yoast_GA_Settings::dashboards_disabled() */ public function test_dashboards_disabled_AND_update_option() { $options = $this->class_options->get_options(); $options['dashboards_disabled'] = 1; $this->class_options->update_option($options); // Get the new options by re-instantiate the settings class $this->class_instance = Yoast_GA_Settings::get_instance(); $this->assertTrue($this->class_instance->dashboards_disabled()); }
/** * Getting instance of this object. If instance doesn't exists it will be created. * * @return object|Yoast_GA_Settings */ public static function get_instance() { if (is_null(self::$instance)) { self::$instance = new Yoast_GA_Settings(); } return self::$instance; }
/** * Setting the target_object and adding actions * * @param object $target_object */ public function __construct($target_object) { $this->target_object = $target_object; add_action('admin_menu', array($this, 'create_admin_menu'), 10); if (!function_exists('is_plugin_active_for_network')) { require_once ABSPATH . '/wp-admin/includes/plugin.php'; } if (is_plugin_active_for_network(GAWP_PATH)) { add_action('network_admin_menu', array($this, 'create_admin_menu'), 5); } $this->dashboards_disabled = Yoast_GA_Settings::get_instance()->dashboards_disabled(); }
/** * 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')); $dashboards = Yoast_GA_Dashboards::get_instance(); // 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('Yoast_Google_Analytics_Notice', 'config_warning')); } // Check if something has went wrong with GA-api calls $has_tracking_code = !is_null($this->get_tracking_code()) && empty($this->options['manual_ua_code_field']); if ($has_tracking_code && $this->show_admin_dashboard_warning()) { Yoast_Google_Analytics::get_instance()->check_for_ga_issues(); } 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(); } $dashboards_disabled = Yoast_GA_Settings::get_instance()->dashboards_disabled(); if ($dashboards_disabled == false && isset($_POST['dashboards_disabled'])) { $dashboards->reset_dashboards_data(); } // 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->init_dashboards($this->get_current_profile()); }
/** * Handle the post requests in the admin form of the GA plugin * * @param Yoast_GA_Dashboards $dashboards */ private function handle_ga_post_request($dashboards) { 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(); } $dashboards_disabled = Yoast_GA_Settings::get_instance()->dashboards_disabled(); if ($dashboards_disabled == false && isset($_POST['dashboards_disabled']) || $this->ga_profile_changed($_POST)) { $dashboards->reset_dashboards_data(); } // Post submitted and verified with our nonce $this->save_settings($_POST); } }
/** * Construct on the dashboards class for GA */ protected function __construct() { add_filter('ga_extend_dashboards', array($this, 'extend_dashboards'), 10, 1); $this->dashboards_disabled = Yoast_GA_Settings::get_instance()->dashboards_disabled(); }