3 * @package WPSEO\Admin|Google_Search_Console
7 * Class WPSEO_GSC_Settings
9 class WPSEO_GSC_Settings {
12 * Clear all data from the database
14 * @param WPSEO_GSC_Service $service
16 public static function clear_data( WPSEO_GSC_Service $service ) {
17 // Remove issue and issue counts.
20 // Removes the GSC options.
21 self::remove_gsc_option();
23 // Clear the service data.
24 $service->clear_data();
28 * Reloading all the issues
30 public static function reload_issues( ) {
31 // Remove issue and issue counts.
36 * When authorization is successful return true, otherwise false
38 * @param string $authorization_code
39 * @param Yoast_Api_Google_Client $client
43 public static function validate_authorization( $authorization_code, Yoast_Api_Google_Client $client ) {
44 return ( $authorization_code !== '' && $client->authenticate_client( $authorization_code ) );
52 public static function get_profile() {
54 $option = get_option( WPSEO_GSC::OPTION_WPSEO_GSC, array( 'profile' => '' ) );
58 if ( ! empty( $option['profile'] ) ) {
59 $profile = $option['profile'];
62 // Return the profile.
63 return trim( $profile, '/' );
67 * Removes the issue counts and all the issues from the options
69 private static function remove() {
70 // Remove the issue counts from the options.
71 self::remove_issue_counts();
73 // Removing all issues from the database.
74 self::remove_issues();
78 * Remove the issue counts
80 private static function remove_issue_counts() {
81 // Remove the options which are holding the counts.
82 delete_option( WPSEO_GSC_Count::OPTION_CI_COUNTS );
83 delete_option( WPSEO_GSC_Count::OPTION_CI_LAST_FETCH );
87 * Delete the issues and their meta data from the database
89 private static function remove_issues() {
92 // Remove local crawl issues by running a delete query.
93 $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'wpseo-gsc-issues-%'" );
97 * Removes the options for GSC
99 private static function remove_gsc_option() {
100 delete_option( WPSEO_GSC::OPTION_WPSEO_GSC );