PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.6
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.6
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / deprecated / admin / ryte / class-ryte.php

class-ryte.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.6, at src/deprecated/admin/ryte/class-ryte.php

285 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPSEO plugin file.
4 *
5 * @package WPSEO\Admin
6 */
7
8 /**
9 * Handles the request for getting the Ryte status.
10 *
11 * @deprecated 18.5
12 */
13 class WPSEO_Ryte implements WPSEO_WordPress_Integration {
14
15 /**
16 * Is the request started by pressing the fetch button.
17 *
18 * @var bool
19 */
20 private $is_manual_request = false;
21
22 /**
23 * Holds the Ryte API response.
24 *
25 * @var array
26 */
27 private $ryte_response = null;
28
29 /**
30 * Constructs the object.
31 *
32 * @deprecated 18.5
33 * @codeCoverageIgnore
34 */
35 public function __construct() {
36 _deprecated_function( __METHOD__, 'WPSEO 18.5' );
37 $this->maybe_add_weekly_schedule();
38 }
39
40 /**
41 * Sets up the hooks.
42 *
43 * @deprecated 18.5
44 * @codeCoverageIgnore
45 *
46 * @return void
47 */
48 public function register_hooks() {
49 _deprecated_function( __METHOD__, 'WPSEO 18.5' );
50 if ( ! self::is_active() ) {
51 return;
52 }
53
54 // Sets the action for the Ryte fetch cron job.
55 add_action( 'wpseo_ryte_fetch', [ $this, 'fetch_from_ryte' ] );
56 }
57
58 /**
59 * Determines if we can use the functionality.
60 *
61 * @deprecated 18.5
62 * @codeCoverageIgnore
63 *
64 * @return bool True if this functionality can be used.
65 */
66 public static function is_active() {
67 _deprecated_function( __METHOD__, 'WPSEO 18.5' );
68 if ( wp_doing_ajax() ) {
69 return false;
70 }
71
72 if ( ! WPSEO_Options::get( 'ryte_indexability' ) ) {
73 return false;
74 }
75
76 return true;
77 }
78
79 /**
80 * Hooks to run on plugin activation.
81 *
82 * @deprecated 18.5
83 * @codeCoverageIgnore
84 */
85 public function activate_hooks() {
86 _deprecated_function( __METHOD__, 'WPSEO 18.5' );
87 if ( $this->get_option()->is_enabled() ) {
88 $this->schedule_cron();
89
90 return;
91 }
92
93 $this->unschedule_cron();
94 }
95
96 /**
97 * Determines whether to add a custom cron weekly schedule.
98 *
99 * @deprecated 18.5
100 * @codeCoverageIgnore
101 *
102 * @return void
103 */
104 public function maybe_add_weekly_schedule() {
105 _deprecated_function( __METHOD__, 'WPSEO 18.5' );
106 // If there's no default cron weekly schedule, add a custom one.
107 add_filter( 'cron_schedules', [ $this, 'add_weekly_schedule' ] );
108 }
109
110 /**
111 * Adds a custom weekly cron schedule.
112 *
113 * @deprecated 18.5
114 * @codeCoverageIgnore
115 *
116 * @param array $schedules The existing custom cron schedules.
117 *
118 * @return array Enriched list of custom cron schedules.
119 */
120 public function add_weekly_schedule( $schedules ) {
121 _deprecated_function( __METHOD__, 'WPSEO 18.5' );
122 if ( ! is_array( $schedules ) ) {
123 $schedules = [];
124 }
125
126 /*
127 * Starting with version 5.4, WordPress does have a default weekly cron
128 * schedule. See https://core.trac.wordpress.org/changeset/47062.
129 * We need to add a custom one only if the default one doesn't exist.
130 */
131 if ( isset( $schedules['weekly'] ) ) {
132 return $schedules;
133 }
134
135 $schedules['weekly'] = [
136 'interval' => WEEK_IN_SECONDS,
137 'display' => __( 'Once Weekly', 'wordpress-seo' ),
138 ];
139
140 return $schedules;
141 }
142
143 /**
144 * Fetches the data from Ryte.
145 *
146 * @deprecated 18.5
147 * @codeCoverageIgnore
148 *
149 * @return bool|null Whether the request ran.
150 */
151 public function fetch_from_ryte() {
152 _deprecated_function( __METHOD__, 'WPSEO 18.5' );
153 // Don't do anything when the WordPress environment type isn't "production".
154 if ( wp_get_environment_type() !== 'production' ) {
155 return;
156 }
157
158 $ryte_option = $this->get_option();
159 if ( ! $ryte_option->should_be_fetched() ) {
160 return false;
161 }
162
163 $new_status = $this->request_indexability();
164
165 // Updates the timestamp in the option.
166 $ryte_option->set_last_fetch( time() );
167
168 $ryte_option->set_status( $new_status );
169 $ryte_option->save_option();
170
171 return true;
172 }
173
174 /**
175 * Retrieves the option to use.
176 *
177 * @deprecated 18.5
178 * @codeCoverageIgnore
179 *
180 * @return WPSEO_Ryte_Option The option.
181 */
182 protected function get_option() {
183 _deprecated_function( __METHOD__, 'WPSEO 18.5' );
184 return new WPSEO_Ryte_Option();
185 }
186
187 /**
188 * Sends a request to Ryte to get the indexability status.
189 *
190 * @deprecated 18.5
191 * @codeCoverageIgnore
192 *
193 * @return int The indexability status value.
194 */
195 protected function request_indexability() {
196 _deprecated_function( __METHOD__, 'WPSEO 18.5' );
197 $parameters = [];
198 if ( $this->wordfence_protection_enabled() ) {
199 $parameters['wf_strict'] = 1;
200 }
201
202 $request = new WPSEO_Ryte_Request();
203 $response = $request->do_request( get_option( 'home' ), $parameters );
204
205 // Populate the ryte_response property.
206 $this->ryte_response = $response;
207
208 // It's a valid Ryte response because the array contains an `is_indexable` element.
209 if ( isset( $response['is_indexable'] ) ) {
210 return (int) $response['is_indexable'];
211 }
212
213 // It's not a valid Ryte response.
214 return WPSEO_Ryte_Option::CANNOT_FETCH;
215 }
216
217 /**
218 * Schedules the cronjob to get the new indexability status.
219 *
220 * @deprecated 18.5
221 * @codeCoverageIgnore
222 *
223 * @return void
224 */
225 private function schedule_cron() {
226 _deprecated_function( __METHOD__, 'WPSEO 18.5' );
227 if ( wp_next_scheduled( 'wpseo_ryte_fetch' ) ) {
228 return;
229 }
230
231 wp_schedule_event( time(), 'weekly', 'wpseo_ryte_fetch' );
232 }
233
234 /**
235 * Unschedules the cronjob to get the new indexability status.
236 *
237 * @deprecated 18.5
238 * @codeCoverageIgnore
239 *
240 * @return void
241 */
242 private function unschedule_cron() {
243 _deprecated_function( __METHOD__, 'WPSEO 18.5' );
244 if ( ! wp_next_scheduled( 'wpseo_ryte_fetch' ) ) {
245 return;
246 }
247
248 wp_clear_scheduled_hook( 'wpseo_ryte_fetch' );
249 }
250
251 /**
252 * Checks if WordFence protects the site against 'fake' Google crawlers.
253 *
254 * @deprecated 18.5
255 * @codeCoverageIgnore
256 *
257 * @return bool True if WordFence protects the site.
258 */
259 private function wordfence_protection_enabled() {
260 _deprecated_function( __METHOD__, 'WPSEO 18.5' );
261 if ( ! class_exists( 'wfConfig' ) ) {
262 return false;
263 }
264
265 if ( ! method_exists( 'wfConfig', 'get' ) ) {
266 return false;
267 }
268
269 return (bool) wfConfig::get( 'blockFakeBots' );
270 }
271
272 /**
273 * Retrieves the Ryte API response property.
274 *
275 * @deprecated 18.5
276 * @codeCoverageIgnore
277 *
278 * @return array|WP_Error The response or WP_Error on failure.
279 */
280 public function get_response() {
281 _deprecated_function( __METHOD__, 'WPSEO 18.5' );
282 return $this->ryte_response;
283 }
284 }
285