class-ryte.php
6.12 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Handles the request for getting the Ryte status.
*
* @deprecated 18.5
*/
class WPSEO_Ryte implements WPSEO_WordPress_Integration {
/**
* Is the request started by pressing the fetch button.
*
* @var bool
*/
private $is_manual_request = false;
/**
* Holds the Ryte API response.
*
* @var array
*/
private $ryte_response = null;
/**
* Constructs the object.
*
* @deprecated 18.5
* @codeCoverageIgnore
*/
public function __construct() {
_deprecated_function( __METHOD__, 'Yoast SEO 18.5' );
$this->maybe_add_weekly_schedule();
}
/**
* Sets up the hooks.
*
* @deprecated 18.5
* @codeCoverageIgnore
*
* @return void
*/
public function register_hooks() {
_deprecated_function( __METHOD__, 'Yoast SEO 18.5' );
if ( ! self::is_active() ) {
return;
}
// Sets the action for the Ryte fetch cron job.
add_action( 'wpseo_ryte_fetch', [ $this, 'fetch_from_ryte' ] );
}
/**
* Determines if we can use the functionality.
*
* @deprecated 18.5
* @codeCoverageIgnore
*
* @return bool True if this functionality can be used.
*/
public static function is_active() {
_deprecated_function( __METHOD__, 'Yoast SEO 18.5' );
if ( wp_doing_ajax() ) {
return false;
}
if ( ! WPSEO_Options::get( 'ryte_indexability' ) ) {
return false;
}
return true;
}
/**
* Hooks to run on plugin activation.
*
* @deprecated 18.5
* @codeCoverageIgnore
*/
public function activate_hooks() {
_deprecated_function( __METHOD__, 'Yoast SEO 18.5' );
if ( $this->get_option()->is_enabled() ) {
$this->schedule_cron();
return;
}
$this->unschedule_cron();
}
/**
* Determines whether to add a custom cron weekly schedule.
*
* @deprecated 18.5
* @codeCoverageIgnore
*
* @return void
*/
public function maybe_add_weekly_schedule() {
_deprecated_function( __METHOD__, 'Yoast SEO 18.5' );
// If there's no default cron weekly schedule, add a custom one.
add_filter( 'cron_schedules', [ $this, 'add_weekly_schedule' ] );
}
/**
* Adds a custom weekly cron schedule.
*
* @deprecated 18.5
* @codeCoverageIgnore
*
* @param array $schedules The existing custom cron schedules.
*
* @return array Enriched list of custom cron schedules.
*/
public function add_weekly_schedule( $schedules ) {
_deprecated_function( __METHOD__, 'Yoast SEO 18.5' );
if ( ! is_array( $schedules ) ) {
$schedules = [];
}
/*
* Starting with version 5.4, WordPress does have a default weekly cron
* schedule. See https://core.trac.wordpress.org/changeset/47062.
* We need to add a custom one only if the default one doesn't exist.
*/
if ( isset( $schedules['weekly'] ) ) {
return $schedules;
}
$schedules['weekly'] = [
'interval' => WEEK_IN_SECONDS,
'display' => __( 'Once Weekly', 'wordpress-seo' ),
];
return $schedules;
}
/**
* Fetches the data from Ryte.
*
* @deprecated 18.5
* @codeCoverageIgnore
*
* @return bool|null Whether the request ran.
*/
public function fetch_from_ryte() {
_deprecated_function( __METHOD__, 'Yoast SEO 18.5' );
// Don't do anything when the WordPress environment type isn't "production".
if ( wp_get_environment_type() !== 'production' ) {
return;
}
$ryte_option = $this->get_option();
if ( ! $ryte_option->should_be_fetched() ) {
return false;
}
$new_status = $this->request_indexability();
// Updates the timestamp in the option.
$ryte_option->set_last_fetch( time() );
$ryte_option->set_status( $new_status );
$ryte_option->save_option();
return true;
}
/**
* Retrieves the option to use.
*
* @deprecated 18.5
* @codeCoverageIgnore
*
* @return WPSEO_Ryte_Option The option.
*/
protected function get_option() {
_deprecated_function( __METHOD__, 'Yoast SEO 18.5' );
return new WPSEO_Ryte_Option();
}
/**
* Sends a request to Ryte to get the indexability status.
*
* @deprecated 18.5
* @codeCoverageIgnore
*
* @return int The indexability status value.
*/
protected function request_indexability() {
_deprecated_function( __METHOD__, 'Yoast SEO 18.5' );
$parameters = [];
if ( $this->wordfence_protection_enabled() ) {
$parameters['wf_strict'] = 1;
}
$request = new WPSEO_Ryte_Request();
$response = $request->do_request( get_option( 'home' ), $parameters );
// Populate the ryte_response property.
$this->ryte_response = $response;
// It's a valid Ryte response because the array contains an `is_indexable` element.
if ( isset( $response['is_indexable'] ) ) {
return (int) $response['is_indexable'];
}
// It's not a valid Ryte response.
return WPSEO_Ryte_Option::CANNOT_FETCH;
}
/**
* Schedules the cronjob to get the new indexability status.
*
* @deprecated 18.5
* @codeCoverageIgnore
*
* @return void
*/
private function schedule_cron() {
_deprecated_function( __METHOD__, 'Yoast SEO 18.5' );
if ( wp_next_scheduled( 'wpseo_ryte_fetch' ) ) {
return;
}
wp_schedule_event( time(), 'weekly', 'wpseo_ryte_fetch' );
}
/**
* Unschedules the cronjob to get the new indexability status.
*
* @deprecated 18.5
* @codeCoverageIgnore
*
* @return void
*/
private function unschedule_cron() {
_deprecated_function( __METHOD__, 'Yoast SEO 18.5' );
if ( ! wp_next_scheduled( 'wpseo_ryte_fetch' ) ) {
return;
}
wp_clear_scheduled_hook( 'wpseo_ryte_fetch' );
}
/**
* Checks if WordFence protects the site against 'fake' Google crawlers.
*
* @deprecated 18.5
* @codeCoverageIgnore
*
* @return bool True if WordFence protects the site.
*/
private function wordfence_protection_enabled() {
_deprecated_function( __METHOD__, 'Yoast SEO 18.5' );
if ( ! class_exists( 'wfConfig' ) ) {
return false;
}
if ( ! method_exists( 'wfConfig', 'get' ) ) {
return false;
}
return (bool) wfConfig::get( 'blockFakeBots' );
}
/**
* Retrieves the Ryte API response property.
*
* @deprecated 18.5
* @codeCoverageIgnore
*
* @return array|WP_Error The response or WP_Error on failure.
*/
public function get_response() {
_deprecated_function( __METHOD__, 'Yoast SEO 18.5' );
return $this->ryte_response;
}
}