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