Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wordpres.../src/integrat.../admin
File: background-indexing-integration.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Integrations\Admin;
[2] Fix | Delete
[3] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Indexable_General_Indexation_Action;
[4] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Indexable_Indexing_Complete_Action;
[5] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Indexable_Post_Indexation_Action;
[6] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Indexable_Post_Type_Archive_Indexation_Action;
[7] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Indexable_Term_Indexation_Action;
[8] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Post_Link_Indexing_Action;
[9] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Term_Link_Indexing_Action;
[10] Fix | Delete
use Yoast\WP\SEO\Conditionals\Get_Request_Conditional;
[11] Fix | Delete
use Yoast\WP\SEO\Conditionals\Migrations_Conditional;
[12] Fix | Delete
use Yoast\WP\SEO\Conditionals\WP_CRON_Enabled_Conditional;
[13] Fix | Delete
use Yoast\WP\SEO\Conditionals\Yoast_Admin_And_Dashboard_Conditional;
[14] Fix | Delete
use Yoast\WP\SEO\Helpers\Indexable_Helper;
[15] Fix | Delete
use Yoast\WP\SEO\Helpers\Indexing_Helper;
[16] Fix | Delete
use Yoast\WP\SEO\Integrations\Integration_Interface;
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* Class Background_Indexing_Integration.
[20] Fix | Delete
*
[21] Fix | Delete
* @package Yoast\WP\SEO\Integrations\Admin
[22] Fix | Delete
*/
[23] Fix | Delete
class Background_Indexing_Integration implements Integration_Interface {
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* The post indexing action.
[27] Fix | Delete
*
[28] Fix | Delete
* @var Indexable_Post_Indexation_Action
[29] Fix | Delete
*/
[30] Fix | Delete
protected $post_indexation;
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* The term indexing action.
[34] Fix | Delete
*
[35] Fix | Delete
* @var Indexable_Term_Indexation_Action
[36] Fix | Delete
*/
[37] Fix | Delete
protected $term_indexation;
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* The post type archive indexing action.
[41] Fix | Delete
*
[42] Fix | Delete
* @var Indexable_Post_Type_Archive_Indexation_Action
[43] Fix | Delete
*/
[44] Fix | Delete
protected $post_type_archive_indexation;
[45] Fix | Delete
[46] Fix | Delete
/**
[47] Fix | Delete
* Represents the general indexing.
[48] Fix | Delete
*
[49] Fix | Delete
* @var Indexable_General_Indexation_Action
[50] Fix | Delete
*/
[51] Fix | Delete
protected $general_indexation;
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* Represents the indexing completed action.
[55] Fix | Delete
*
[56] Fix | Delete
* @var Indexable_Indexing_Complete_Action
[57] Fix | Delete
*/
[58] Fix | Delete
protected $complete_indexation_action;
[59] Fix | Delete
[60] Fix | Delete
/**
[61] Fix | Delete
* The post link indexing action.
[62] Fix | Delete
*
[63] Fix | Delete
* @var Post_Link_Indexing_Action
[64] Fix | Delete
*/
[65] Fix | Delete
protected $post_link_indexing_action;
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* The term link indexing action.
[69] Fix | Delete
*
[70] Fix | Delete
* @var Term_Link_Indexing_Action
[71] Fix | Delete
*/
[72] Fix | Delete
protected $term_link_indexing_action;
[73] Fix | Delete
[74] Fix | Delete
/**
[75] Fix | Delete
* Represents the indexing helper.
[76] Fix | Delete
*
[77] Fix | Delete
* @var Indexing_Helper
[78] Fix | Delete
*/
[79] Fix | Delete
protected $indexing_helper;
[80] Fix | Delete
[81] Fix | Delete
/**
[82] Fix | Delete
* An object that checks if we are on the Yoast admin or on the dashboard page.
[83] Fix | Delete
*
[84] Fix | Delete
* @var Yoast_Admin_And_Dashboard_Conditional
[85] Fix | Delete
*/
[86] Fix | Delete
protected $yoast_admin_and_dashboard_conditional;
[87] Fix | Delete
[88] Fix | Delete
/**
[89] Fix | Delete
* An object that checks if we are handling a GET request.
[90] Fix | Delete
*
[91] Fix | Delete
* @var Get_Request_Conditional
[92] Fix | Delete
*/
[93] Fix | Delete
private $get_request_conditional;
[94] Fix | Delete
[95] Fix | Delete
/**
[96] Fix | Delete
* An object that checks if WP_CRON is enabled.
[97] Fix | Delete
*
[98] Fix | Delete
* @var WP_CRON_Enabled_Conditional
[99] Fix | Delete
*/
[100] Fix | Delete
private $wp_cron_enabled_conditional;
[101] Fix | Delete
[102] Fix | Delete
/**
[103] Fix | Delete
* The indexable helper
[104] Fix | Delete
*
[105] Fix | Delete
* @var Indexable_Helper
[106] Fix | Delete
*/
[107] Fix | Delete
private $indexable_helper;
[108] Fix | Delete
[109] Fix | Delete
/**
[110] Fix | Delete
* Returns the conditionals based on which this integration should be active.
[111] Fix | Delete
*
[112] Fix | Delete
* @return array The array of conditionals.
[113] Fix | Delete
*/
[114] Fix | Delete
public static function get_conditionals() {
[115] Fix | Delete
return [
[116] Fix | Delete
Migrations_Conditional::class,
[117] Fix | Delete
];
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
/**
[121] Fix | Delete
* Shutdown_Indexing_Integration constructor.
[122] Fix | Delete
*
[123] Fix | Delete
* @param Indexable_Post_Indexation_Action $post_indexation The post indexing action.
[124] Fix | Delete
* @param Indexable_Term_Indexation_Action $term_indexation The term indexing action.
[125] Fix | Delete
* @param Indexable_Post_Type_Archive_Indexation_Action $post_type_archive_indexation The post type archive indexing action.
[126] Fix | Delete
* @param Indexable_General_Indexation_Action $general_indexation The general indexing action.
[127] Fix | Delete
* @param Indexable_Indexing_Complete_Action $complete_indexation_action The complete indexing action.
[128] Fix | Delete
* @param Post_Link_Indexing_Action $post_link_indexing_action The post indexing action.
[129] Fix | Delete
* @param Term_Link_Indexing_Action $term_link_indexing_action The term indexing action.
[130] Fix | Delete
* @param Indexing_Helper $indexing_helper The indexing helper.
[131] Fix | Delete
* @param Indexable_Helper $indexable_helper The indexable helper.
[132] Fix | Delete
* @param Yoast_Admin_And_Dashboard_Conditional $yoast_admin_and_dashboard_conditional An object that checks if we are on the Yoast admin or on the dashboard page.
[133] Fix | Delete
* @param Get_Request_Conditional $get_request_conditional An object that checks if we are handling a GET request.
[134] Fix | Delete
* @param WP_CRON_Enabled_Conditional $wp_cron_enabled_conditional An object that checks if WP_CRON is enabled.
[135] Fix | Delete
*/
[136] Fix | Delete
public function __construct(
[137] Fix | Delete
Indexable_Post_Indexation_Action $post_indexation,
[138] Fix | Delete
Indexable_Term_Indexation_Action $term_indexation,
[139] Fix | Delete
Indexable_Post_Type_Archive_Indexation_Action $post_type_archive_indexation,
[140] Fix | Delete
Indexable_General_Indexation_Action $general_indexation,
[141] Fix | Delete
Indexable_Indexing_Complete_Action $complete_indexation_action,
[142] Fix | Delete
Post_Link_Indexing_Action $post_link_indexing_action,
[143] Fix | Delete
Term_Link_Indexing_Action $term_link_indexing_action,
[144] Fix | Delete
Indexing_Helper $indexing_helper,
[145] Fix | Delete
Indexable_Helper $indexable_helper,
[146] Fix | Delete
Yoast_Admin_And_Dashboard_Conditional $yoast_admin_and_dashboard_conditional,
[147] Fix | Delete
Get_Request_Conditional $get_request_conditional,
[148] Fix | Delete
WP_CRON_Enabled_Conditional $wp_cron_enabled_conditional
[149] Fix | Delete
) {
[150] Fix | Delete
$this->post_indexation = $post_indexation;
[151] Fix | Delete
$this->term_indexation = $term_indexation;
[152] Fix | Delete
$this->post_type_archive_indexation = $post_type_archive_indexation;
[153] Fix | Delete
$this->general_indexation = $general_indexation;
[154] Fix | Delete
$this->complete_indexation_action = $complete_indexation_action;
[155] Fix | Delete
$this->post_link_indexing_action = $post_link_indexing_action;
[156] Fix | Delete
$this->term_link_indexing_action = $term_link_indexing_action;
[157] Fix | Delete
$this->indexing_helper = $indexing_helper;
[158] Fix | Delete
$this->indexable_helper = $indexable_helper;
[159] Fix | Delete
$this->yoast_admin_and_dashboard_conditional = $yoast_admin_and_dashboard_conditional;
[160] Fix | Delete
$this->get_request_conditional = $get_request_conditional;
[161] Fix | Delete
$this->wp_cron_enabled_conditional = $wp_cron_enabled_conditional;
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
/**
[165] Fix | Delete
* Register hooks.
[166] Fix | Delete
*
[167] Fix | Delete
* @return void
[168] Fix | Delete
*/
[169] Fix | Delete
public function register_hooks() {
[170] Fix | Delete
\add_action( 'admin_init', [ $this, 'register_shutdown_indexing' ] );
[171] Fix | Delete
\add_action( 'wpseo_indexable_index_batch', [ $this, 'index' ] );
[172] Fix | Delete
// phpcs:ignore WordPress.WP.CronInterval -- The sniff doesn't understand values with parentheses. https://github.com/WordPress/WordPress-Coding-Standards/issues/2025
[173] Fix | Delete
\add_filter( 'cron_schedules', [ $this, 'add_cron_schedule' ] );
[174] Fix | Delete
\add_action( 'admin_init', [ $this, 'schedule_cron_indexing' ], 11 );
[175] Fix | Delete
[176] Fix | Delete
$this->add_limit_filters();
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
/**
[180] Fix | Delete
* Adds the filters that change the indexing limits.
[181] Fix | Delete
*
[182] Fix | Delete
* @return void.
[183] Fix | Delete
*/
[184] Fix | Delete
public function add_limit_filters() {
[185] Fix | Delete
\add_filter( 'wpseo_post_indexation_limit', [ $this, 'throttle_cron_indexing' ] );
[186] Fix | Delete
\add_filter( 'wpseo_post_type_archive_indexation_limit', [ $this, 'throttle_cron_indexing' ] );
[187] Fix | Delete
\add_filter( 'wpseo_term_indexation_limit', [ $this, 'throttle_cron_indexing' ] );
[188] Fix | Delete
\add_filter( 'wpseo_prominent_words_indexation_limit', [ $this, 'throttle_cron_indexing' ] );
[189] Fix | Delete
\add_filter( 'wpseo_link_indexing_limit', [ $this, 'throttle_cron_link_indexing' ] );
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
/**
[193] Fix | Delete
* Enqueues the required scripts.
[194] Fix | Delete
*
[195] Fix | Delete
* @return void
[196] Fix | Delete
*/
[197] Fix | Delete
public function register_shutdown_indexing() {
[198] Fix | Delete
if ( $this->should_index_on_shutdown( $this->get_shutdown_limit() ) ) {
[199] Fix | Delete
$this->register_shutdown_function( 'index' );
[200] Fix | Delete
}
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
/**
[204] Fix | Delete
* Run a single indexing pass of each indexing action. Intended for use as a shutdown function.
[205] Fix | Delete
*
[206] Fix | Delete
* @return void
[207] Fix | Delete
*/
[208] Fix | Delete
public function index() {
[209] Fix | Delete
if ( \wp_doing_cron() && ! $this->should_index_on_cron() ) {
[210] Fix | Delete
$this->unschedule_cron_indexing();
[211] Fix | Delete
[212] Fix | Delete
return;
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
$this->post_indexation->index();
[216] Fix | Delete
$this->term_indexation->index();
[217] Fix | Delete
$this->general_indexation->index();
[218] Fix | Delete
$this->post_type_archive_indexation->index();
[219] Fix | Delete
$this->post_link_indexing_action->index();
[220] Fix | Delete
$this->term_link_indexing_action->index();
[221] Fix | Delete
[222] Fix | Delete
if ( $this->indexing_helper->get_limited_filtered_unindexed_count_background( 1 ) === 0 ) {
[223] Fix | Delete
// We set this as complete, even though prominent words might not be complete. But that's the way we always treated that.
[224] Fix | Delete
$this->complete_indexation_action->complete();
[225] Fix | Delete
}
[226] Fix | Delete
}
[227] Fix | Delete
[228] Fix | Delete
/**
[229] Fix | Delete
* Adds the 'Every fifteen minutes' cron schedule to WP-Cron.
[230] Fix | Delete
*
[231] Fix | Delete
* @param array $schedules The existing schedules.
[232] Fix | Delete
*
[233] Fix | Delete
* @return array The schedules containing the fifteen_minutes schedule.
[234] Fix | Delete
*/
[235] Fix | Delete
public function add_cron_schedule( $schedules ) {
[236] Fix | Delete
if ( ! \is_array( $schedules ) ) {
[237] Fix | Delete
return $schedules;
[238] Fix | Delete
}
[239] Fix | Delete
[240] Fix | Delete
$schedules['fifteen_minutes'] = [
[241] Fix | Delete
'interval' => ( 15 * \MINUTE_IN_SECONDS ),
[242] Fix | Delete
'display' => \esc_html__( 'Every fifteen minutes', 'wordpress-seo' ),
[243] Fix | Delete
];
[244] Fix | Delete
[245] Fix | Delete
return $schedules;
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
/**
[249] Fix | Delete
* Schedule background indexing every 15 minutes if the index isn't already up to date.
[250] Fix | Delete
*
[251] Fix | Delete
* @return void
[252] Fix | Delete
*/
[253] Fix | Delete
public function schedule_cron_indexing() {
[254] Fix | Delete
/**
[255] Fix | Delete
* Filter: 'wpseo_unindexed_count_queries_ran' - Informs whether the expensive unindexed count queries have been ran already.
[256] Fix | Delete
*
[257] Fix | Delete
* @internal
[258] Fix | Delete
*
[259] Fix | Delete
* @param bool $have_queries_ran
[260] Fix | Delete
*/
[261] Fix | Delete
$have_queries_ran = \apply_filters( 'wpseo_unindexed_count_queries_ran', false );
[262] Fix | Delete
[263] Fix | Delete
if ( ( ! $this->yoast_admin_and_dashboard_conditional->is_met() || ! $this->get_request_conditional->is_met() ) && ! $have_queries_ran ) {
[264] Fix | Delete
return;
[265] Fix | Delete
}
[266] Fix | Delete
[267] Fix | Delete
if ( ! \wp_next_scheduled( 'wpseo_indexable_index_batch' ) && $this->should_index_on_cron() ) {
[268] Fix | Delete
\wp_schedule_event( ( \time() + \HOUR_IN_SECONDS ), 'fifteen_minutes', 'wpseo_indexable_index_batch' );
[269] Fix | Delete
}
[270] Fix | Delete
}
[271] Fix | Delete
[272] Fix | Delete
/**
[273] Fix | Delete
* Limit cron indexing to 15 indexables per batch instead of 25.
[274] Fix | Delete
*
[275] Fix | Delete
* @param int $indexation_limit The current limit (filter input).
[276] Fix | Delete
*
[277] Fix | Delete
* @return int The new batch limit.
[278] Fix | Delete
*/
[279] Fix | Delete
public function throttle_cron_indexing( $indexation_limit ) {
[280] Fix | Delete
if ( \wp_doing_cron() ) {
[281] Fix | Delete
/**
[282] Fix | Delete
* Filter: 'wpseo_cron_indexing_limit_size' - Adds the possibility to limit the number of items that are indexed when in cron action.
[283] Fix | Delete
*
[284] Fix | Delete
* @param int $limit Maximum number of indexables to be indexed per indexing action.
[285] Fix | Delete
*/
[286] Fix | Delete
return \apply_filters( 'wpseo_cron_indexing_limit_size', 15 );
[287] Fix | Delete
}
[288] Fix | Delete
[289] Fix | Delete
return $indexation_limit;
[290] Fix | Delete
}
[291] Fix | Delete
[292] Fix | Delete
/**
[293] Fix | Delete
* Limit cron indexing to 3 links per batch instead of 5.
[294] Fix | Delete
*
[295] Fix | Delete
* @param int $link_indexation_limit The current limit (filter input).
[296] Fix | Delete
*
[297] Fix | Delete
* @return int The new batch limit.
[298] Fix | Delete
*/
[299] Fix | Delete
public function throttle_cron_link_indexing( $link_indexation_limit ) {
[300] Fix | Delete
if ( \wp_doing_cron() ) {
[301] Fix | Delete
/**
[302] Fix | Delete
* Filter: 'wpseo_cron_link_indexing_limit_size' - Adds the possibility to limit the number of links that are indexed when in cron action.
[303] Fix | Delete
*
[304] Fix | Delete
* @param int $limit Maximum number of link indexables to be indexed per link indexing action.
[305] Fix | Delete
*/
[306] Fix | Delete
return \apply_filters( 'wpseo_cron_link_indexing_limit_size', 3 );
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
return $link_indexation_limit;
[310] Fix | Delete
}
[311] Fix | Delete
[312] Fix | Delete
/**
[313] Fix | Delete
* Determine whether cron indexation should be performed.
[314] Fix | Delete
*
[315] Fix | Delete
* @return bool Should cron indexation be performed.
[316] Fix | Delete
*/
[317] Fix | Delete
protected function should_index_on_cron() {
[318] Fix | Delete
if ( ! $this->indexable_helper->should_index_indexables() ) {
[319] Fix | Delete
return false;
[320] Fix | Delete
}
[321] Fix | Delete
[322] Fix | Delete
// The filter supersedes everything when preventing cron indexation.
[323] Fix | Delete
if ( \apply_filters( 'Yoast\WP\SEO\enable_cron_indexing', true ) !== true ) {
[324] Fix | Delete
return false;
[325] Fix | Delete
}
[326] Fix | Delete
[327] Fix | Delete
return $this->indexing_helper->get_limited_filtered_unindexed_count_background( 1 ) > 0;
[328] Fix | Delete
}
[329] Fix | Delete
[330] Fix | Delete
/**
[331] Fix | Delete
* Determine whether background indexation should be performed.
[332] Fix | Delete
*
[333] Fix | Delete
* @param int $shutdown_limit The shutdown limit used to determine whether indexation should be run.
[334] Fix | Delete
*
[335] Fix | Delete
* @return bool Should background indexation be performed.
[336] Fix | Delete
*/
[337] Fix | Delete
protected function should_index_on_shutdown( $shutdown_limit ) {
[338] Fix | Delete
if ( ! $this->yoast_admin_and_dashboard_conditional->is_met() || ! $this->get_request_conditional->is_met() ) {
[339] Fix | Delete
return false;
[340] Fix | Delete
}
[341] Fix | Delete
[342] Fix | Delete
if ( ! $this->indexable_helper->should_index_indexables() ) {
[343] Fix | Delete
return false;
[344] Fix | Delete
}
[345] Fix | Delete
[346] Fix | Delete
if ( $this->wp_cron_enabled_conditional->is_met() ) {
[347] Fix | Delete
return false;
[348] Fix | Delete
}
[349] Fix | Delete
[350] Fix | Delete
$total_unindexed = $this->indexing_helper->get_limited_filtered_unindexed_count_background( $shutdown_limit );
[351] Fix | Delete
if ( $total_unindexed === 0 || $total_unindexed > $shutdown_limit ) {
[352] Fix | Delete
return false;
[353] Fix | Delete
}
[354] Fix | Delete
[355] Fix | Delete
return true;
[356] Fix | Delete
}
[357] Fix | Delete
[358] Fix | Delete
/**
[359] Fix | Delete
* Retrieves the shutdown limit. This limit is the amount of indexables that is generated in the background.
[360] Fix | Delete
*
[361] Fix | Delete
* @return int The shutdown limit.
[362] Fix | Delete
*/
[363] Fix | Delete
protected function get_shutdown_limit() {
[364] Fix | Delete
/**
[365] Fix | Delete
* Filter 'wpseo_shutdown_indexation_limit' - Allow filtering the number of objects that can be indexed during shutdown.
[366] Fix | Delete
*
[367] Fix | Delete
* @param int $limit The maximum number of objects indexed.
[368] Fix | Delete
*/
[369] Fix | Delete
return \apply_filters( 'wpseo_shutdown_indexation_limit', 25 );
[370] Fix | Delete
}
[371] Fix | Delete
[372] Fix | Delete
/**
[373] Fix | Delete
* Removes the cron indexing job from the scheduled event queue.
[374] Fix | Delete
*
[375] Fix | Delete
* @return void
[376] Fix | Delete
*/
[377] Fix | Delete
protected function unschedule_cron_indexing() {
[378] Fix | Delete
$scheduled = \wp_next_scheduled( 'wpseo_indexable_index_batch' );
[379] Fix | Delete
if ( $scheduled ) {
[380] Fix | Delete
\wp_unschedule_event( $scheduled, 'wpseo_indexable_index_batch' );
[381] Fix | Delete
}
[382] Fix | Delete
}
[383] Fix | Delete
[384] Fix | Delete
/**
[385] Fix | Delete
* Registers a method to be executed on shutdown.
[386] Fix | Delete
* This wrapper mostly exists for making this class more unittestable.
[387] Fix | Delete
*
[388] Fix | Delete
* @param string $method_name The name of the method on the current instance to register.
[389] Fix | Delete
*
[390] Fix | Delete
* @return void
[391] Fix | Delete
*/
[392] Fix | Delete
protected function register_shutdown_function( $method_name ) {
[393] Fix | Delete
\register_shutdown_function( [ $this, $method_name ] );
[394] Fix | Delete
}
[395] Fix | Delete
}
[396] Fix | Delete
[397] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function