]> _ Git - couzy.git/blob
1471f4bb83c6a57ad24cce341fb581797f9dbf8a
[couzy.git] /
1 <?php
2 /**
3  * @package WPSEO\Admin|Google_Search_Console
4  */
5
6 /**
7  * Class WPSEO_GSC_Settings
8  */
9 class WPSEO_GSC_Settings {
10
11         /**
12          * Clear all data from the database
13          *
14          * @param WPSEO_GSC_Service $service
15          */
16         public static function clear_data( WPSEO_GSC_Service $service ) {
17                 // Remove issue and issue counts.
18                 self::remove();
19
20                 // Removes the GSC options.
21                 self::remove_gsc_option();
22
23                 // Clear the service data.
24                 $service->clear_data();
25         }
26
27         /**
28          * Reloading all the issues
29          */
30         public static function reload_issues( ) {
31                 // Remove issue and issue counts.
32                 self::remove();
33         }
34
35         /**
36          * When authorization is successful return true, otherwise false
37          *
38          * @param string                  $authorization_code
39          * @param Yoast_Api_Google_Client $client
40          *
41          * @return bool
42          */
43         public static function validate_authorization( $authorization_code, Yoast_Api_Google_Client $client ) {
44                 return ( $authorization_code !== '' && $client->authenticate_client( $authorization_code ) );
45         }
46
47         /**
48          * Get the GSC profile
49          *
50          * @return string
51          */
52         public static function get_profile() {
53                 // Get option.
54                 $option = get_option( WPSEO_GSC::OPTION_WPSEO_GSC, array( 'profile' => '' ) );
55
56                 // Set the profile.
57                 $profile = '';
58                 if ( ! empty( $option['profile'] ) ) {
59                         $profile = $option['profile'];
60                 }
61
62                 // Return the profile.
63                 return trim( $profile, '/' );
64         }
65
66         /**
67          * Removes the issue counts and all the issues from the options
68          */
69         private static function remove() {
70                 // Remove the issue counts from the options.
71                 self::remove_issue_counts();
72
73                 // Removing all issues from the database.
74                 self::remove_issues();
75         }
76
77         /**
78          * Remove the issue counts
79          */
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 );
84         }
85
86         /**
87          * Delete the issues and their meta data from the database
88          */
89         private static function remove_issues() {
90                 global $wpdb;
91
92                 // Remove local crawl issues by running a delete query.
93                 $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'wpseo-gsc-issues-%'" );
94         }
95
96         /**
97          * Removes the options for GSC
98          */
99         private static function remove_gsc_option() {
100                 delete_option( WPSEO_GSC::OPTION_WPSEO_GSC );
101         }
102
103 }