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/clone/wp-conte.../plugins/wordpres.../src/integrat...
File: cleanup-integration.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Integrations;
[2] Fix | Delete
[3] Fix | Delete
use Closure;
[4] Fix | Delete
use Yoast\WP\SEO\Repositories\Indexable_Cleanup_Repository;
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Adds cleanup hooks.
[8] Fix | Delete
*/
[9] Fix | Delete
class Cleanup_Integration implements Integration_Interface {
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Identifier used to determine the current task.
[13] Fix | Delete
*/
[14] Fix | Delete
public const CURRENT_TASK_OPTION = 'wpseo-cleanup-current-task';
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* Identifier for the cron job.
[18] Fix | Delete
*/
[19] Fix | Delete
public const CRON_HOOK = 'wpseo_cleanup_cron';
[20] Fix | Delete
[21] Fix | Delete
/**
[22] Fix | Delete
* Identifier for starting the cleanup.
[23] Fix | Delete
*/
[24] Fix | Delete
public const START_HOOK = 'wpseo_start_cleanup_indexables';
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* The cleanup repository.
[28] Fix | Delete
*
[29] Fix | Delete
* @var Indexable_Cleanup_Repository
[30] Fix | Delete
*/
[31] Fix | Delete
private $cleanup_repository;
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* The constructor.
[35] Fix | Delete
*
[36] Fix | Delete
* @param Indexable_Cleanup_Repository $cleanup_repository The cleanup repository.
[37] Fix | Delete
*/
[38] Fix | Delete
public function __construct( Indexable_Cleanup_Repository $cleanup_repository ) {
[39] Fix | Delete
$this->cleanup_repository = $cleanup_repository;
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* Initializes the integration.
[44] Fix | Delete
*
[45] Fix | Delete
* This is the place to register hooks and filters.
[46] Fix | Delete
*
[47] Fix | Delete
* @return void
[48] Fix | Delete
*/
[49] Fix | Delete
public function register_hooks() {
[50] Fix | Delete
\add_action( self::START_HOOK, [ $this, 'run_cleanup' ] );
[51] Fix | Delete
\add_action( self::CRON_HOOK, [ $this, 'run_cleanup_cron' ] );
[52] Fix | Delete
\add_action( 'wpseo_deactivate', [ $this, 'reset_cleanup' ] );
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* Returns the conditionals based on which this loadable should be active.
[57] Fix | Delete
*
[58] Fix | Delete
* @return array The array of conditionals.
[59] Fix | Delete
*/
[60] Fix | Delete
public static function get_conditionals() {
[61] Fix | Delete
return [];
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
/**
[65] Fix | Delete
* Starts the indexables cleanup.
[66] Fix | Delete
*
[67] Fix | Delete
* @return void
[68] Fix | Delete
*/
[69] Fix | Delete
public function run_cleanup() {
[70] Fix | Delete
$this->reset_cleanup();
[71] Fix | Delete
[72] Fix | Delete
$cleanups = $this->get_cleanup_tasks();
[73] Fix | Delete
$limit = $this->get_limit();
[74] Fix | Delete
[75] Fix | Delete
foreach ( $cleanups as $name => $action ) {
[76] Fix | Delete
$items_cleaned = $action( $limit );
[77] Fix | Delete
[78] Fix | Delete
if ( $items_cleaned === false ) {
[79] Fix | Delete
return;
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
if ( $items_cleaned < $limit ) {
[83] Fix | Delete
continue;
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
// There are more items to delete for the current cleanup job, start a cronjob at the specified job.
[87] Fix | Delete
$this->start_cron_job( $name );
[88] Fix | Delete
[89] Fix | Delete
return;
[90] Fix | Delete
}
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
/**
[94] Fix | Delete
* Returns an array of cleanup tasks.
[95] Fix | Delete
*
[96] Fix | Delete
* @return Closure[] The cleanup tasks.
[97] Fix | Delete
*/
[98] Fix | Delete
public function get_cleanup_tasks() {
[99] Fix | Delete
return \array_merge(
[100] Fix | Delete
[
[101] Fix | Delete
'clean_indexables_with_object_type_and_object_sub_type_shop_order' => function ( $limit ) {
[102] Fix | Delete
return $this->cleanup_repository->clean_indexables_with_object_type_and_object_sub_type( 'post', 'shop_order', $limit );
[103] Fix | Delete
},
[104] Fix | Delete
'clean_indexables_by_post_status_auto-draft' => function ( $limit ) {
[105] Fix | Delete
return $this->cleanup_repository->clean_indexables_with_post_status( 'auto-draft', $limit );
[106] Fix | Delete
},
[107] Fix | Delete
'clean_indexables_for_non_publicly_viewable_post' => function ( $limit ) {
[108] Fix | Delete
return $this->cleanup_repository->clean_indexables_for_non_publicly_viewable_post( $limit );
[109] Fix | Delete
},
[110] Fix | Delete
'clean_indexables_for_non_publicly_viewable_taxonomies' => function ( $limit ) {
[111] Fix | Delete
return $this->cleanup_repository->clean_indexables_for_non_publicly_viewable_taxonomies( $limit );
[112] Fix | Delete
},
[113] Fix | Delete
'clean_indexables_for_non_publicly_viewable_post_type_archive_pages' => function ( $limit ) {
[114] Fix | Delete
return $this->cleanup_repository->clean_indexables_for_non_publicly_viewable_post_type_archive_pages( $limit );
[115] Fix | Delete
},
[116] Fix | Delete
'clean_indexables_for_authors_archive_disabled' => function ( $limit ) {
[117] Fix | Delete
return $this->cleanup_repository->clean_indexables_for_authors_archive_disabled( $limit );
[118] Fix | Delete
},
[119] Fix | Delete
'clean_indexables_for_authors_without_archive' => function ( $limit ) {
[120] Fix | Delete
return $this->cleanup_repository->clean_indexables_for_authors_without_archive( $limit );
[121] Fix | Delete
},
[122] Fix | Delete
'update_indexables_author_to_reassigned' => function ( $limit ) {
[123] Fix | Delete
return $this->cleanup_repository->update_indexables_author_to_reassigned( $limit );
[124] Fix | Delete
},
[125] Fix | Delete
'clean_orphaned_user_indexables_without_wp_user' => function ( $limit ) {
[126] Fix | Delete
return $this->cleanup_repository->clean_indexables_for_orphaned_users( $limit );
[127] Fix | Delete
},
[128] Fix | Delete
'clean_orphaned_user_indexables_without_wp_post' => function ( $limit ) {
[129] Fix | Delete
return $this->cleanup_repository->clean_indexables_for_object_type_and_source_table( 'posts', 'ID', 'post', $limit );
[130] Fix | Delete
},
[131] Fix | Delete
'clean_orphaned_user_indexables_without_wp_term' => function ( $limit ) {
[132] Fix | Delete
return $this->cleanup_repository->clean_indexables_for_object_type_and_source_table( 'terms', 'term_id', 'term', $limit );
[133] Fix | Delete
},
[134] Fix | Delete
],
[135] Fix | Delete
$this->get_additional_indexable_cleanups(),
[136] Fix | Delete
[
[137] Fix | Delete
/* These should always be the last ones to be called. */
[138] Fix | Delete
'clean_orphaned_content_indexable_hierarchy' => function ( $limit ) {
[139] Fix | Delete
return $this->cleanup_repository->cleanup_orphaned_from_table( 'Indexable_Hierarchy', 'indexable_id', $limit );
[140] Fix | Delete
},
[141] Fix | Delete
'clean_orphaned_content_seo_links_indexable_id' => function ( $limit ) {
[142] Fix | Delete
return $this->cleanup_repository->cleanup_orphaned_from_table( 'SEO_Links', 'indexable_id', $limit );
[143] Fix | Delete
},
[144] Fix | Delete
'clean_orphaned_content_seo_links_target_indexable_id' => function ( $limit ) {
[145] Fix | Delete
return $this->cleanup_repository->cleanup_orphaned_from_table( 'SEO_Links', 'target_indexable_id', $limit );
[146] Fix | Delete
},
[147] Fix | Delete
[148] Fix | Delete
],
[149] Fix | Delete
$this->get_additional_misc_cleanups()
[150] Fix | Delete
);
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
/**
[154] Fix | Delete
* Gets additional tasks from the 'wpseo_cleanup_tasks' filter.
[155] Fix | Delete
*
[156] Fix | Delete
* @return Closure[] Associative array of indexable cleanup functions.
[157] Fix | Delete
*/
[158] Fix | Delete
private function get_additional_indexable_cleanups() {
[159] Fix | Delete
[160] Fix | Delete
/**
[161] Fix | Delete
* Filter: Adds the possibility to add additional indexable cleanup functions.
[162] Fix | Delete
*
[163] Fix | Delete
* @param array $additional_tasks Associative array with unique keys. Value should be a cleanup function that receives a limit.
[164] Fix | Delete
*/
[165] Fix | Delete
$additional_tasks = \apply_filters( 'wpseo_cleanup_tasks', [] );
[166] Fix | Delete
[167] Fix | Delete
return $this->validate_additional_tasks( $additional_tasks );
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
/**
[171] Fix | Delete
* Gets additional tasks from the 'wpseo_misc_cleanup_tasks' filter.
[172] Fix | Delete
*
[173] Fix | Delete
* @return Closure[] Associative array of indexable cleanup functions.
[174] Fix | Delete
*/
[175] Fix | Delete
private function get_additional_misc_cleanups() {
[176] Fix | Delete
[177] Fix | Delete
/**
[178] Fix | Delete
* Filter: Adds the possibility to add additional non-indexable cleanup functions.
[179] Fix | Delete
*
[180] Fix | Delete
* @param array $additional_tasks Associative array with unique keys. Value should be a cleanup function that receives a limit.
[181] Fix | Delete
*/
[182] Fix | Delete
$additional_tasks = \apply_filters( 'wpseo_misc_cleanup_tasks', [] );
[183] Fix | Delete
[184] Fix | Delete
return $this->validate_additional_tasks( $additional_tasks );
[185] Fix | Delete
}
[186] Fix | Delete
[187] Fix | Delete
/**
[188] Fix | Delete
* Validates the additional tasks.
[189] Fix | Delete
*
[190] Fix | Delete
* @param Closure[] $additional_tasks The additional tasks to validate.
[191] Fix | Delete
*
[192] Fix | Delete
* @return Closure[] The validated additional tasks.
[193] Fix | Delete
*/
[194] Fix | Delete
private function validate_additional_tasks( $additional_tasks ) {
[195] Fix | Delete
if ( ! \is_array( $additional_tasks ) ) {
[196] Fix | Delete
return [];
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
foreach ( $additional_tasks as $key => $value ) {
[200] Fix | Delete
if ( \is_int( $key ) ) {
[201] Fix | Delete
return [];
[202] Fix | Delete
}
[203] Fix | Delete
if ( ( ! \is_object( $value ) ) || ! ( $value instanceof Closure ) ) {
[204] Fix | Delete
return [];
[205] Fix | Delete
}
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
return $additional_tasks;
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
/**
[212] Fix | Delete
* Gets the deletion limit for cleanups.
[213] Fix | Delete
*
[214] Fix | Delete
* @return int The limit for the amount of entities to be cleaned.
[215] Fix | Delete
*/
[216] Fix | Delete
private function get_limit() {
[217] Fix | Delete
/**
[218] Fix | Delete
* Filter: Adds the possibility to limit the number of items that are deleted from the database on cleanup.
[219] Fix | Delete
*
[220] Fix | Delete
* @param int $limit Maximum number of indexables to be cleaned up per query.
[221] Fix | Delete
*/
[222] Fix | Delete
$limit = \apply_filters( 'wpseo_cron_query_limit_size', 1000 );
[223] Fix | Delete
[224] Fix | Delete
if ( ! \is_int( $limit ) ) {
[225] Fix | Delete
$limit = 1000;
[226] Fix | Delete
}
[227] Fix | Delete
[228] Fix | Delete
return \abs( $limit );
[229] Fix | Delete
}
[230] Fix | Delete
[231] Fix | Delete
/**
[232] Fix | Delete
* Resets and stops the cleanup integration.
[233] Fix | Delete
*
[234] Fix | Delete
* @return void
[235] Fix | Delete
*/
[236] Fix | Delete
public function reset_cleanup() {
[237] Fix | Delete
\delete_option( self::CURRENT_TASK_OPTION );
[238] Fix | Delete
\wp_unschedule_hook( self::CRON_HOOK );
[239] Fix | Delete
}
[240] Fix | Delete
[241] Fix | Delete
/**
[242] Fix | Delete
* Starts the cleanup cron job.
[243] Fix | Delete
*
[244] Fix | Delete
* @param string $task_name The task name of the next cleanup task to run.
[245] Fix | Delete
* @param int $schedule_time The time in seconds to wait before running the first cron job. Default is 1 hour.
[246] Fix | Delete
*
[247] Fix | Delete
* @return void
[248] Fix | Delete
*/
[249] Fix | Delete
public function start_cron_job( $task_name, $schedule_time = 3600 ) {
[250] Fix | Delete
\update_option( self::CURRENT_TASK_OPTION, $task_name );
[251] Fix | Delete
\wp_schedule_event(
[252] Fix | Delete
( \time() + $schedule_time ),
[253] Fix | Delete
'hourly',
[254] Fix | Delete
self::CRON_HOOK
[255] Fix | Delete
);
[256] Fix | Delete
}
[257] Fix | Delete
[258] Fix | Delete
/**
[259] Fix | Delete
* The callback that is called for the cleanup cron job.
[260] Fix | Delete
*
[261] Fix | Delete
* @return void
[262] Fix | Delete
*/
[263] Fix | Delete
public function run_cleanup_cron() {
[264] Fix | Delete
$current_task_name = \get_option( self::CURRENT_TASK_OPTION );
[265] Fix | Delete
[266] Fix | Delete
if ( $current_task_name === false ) {
[267] Fix | Delete
$this->reset_cleanup();
[268] Fix | Delete
[269] Fix | Delete
return;
[270] Fix | Delete
}
[271] Fix | Delete
[272] Fix | Delete
$limit = $this->get_limit();
[273] Fix | Delete
$tasks = $this->get_cleanup_tasks();
[274] Fix | Delete
[275] Fix | Delete
// The task may have been added by a filter that has been removed, in that case just start over.
[276] Fix | Delete
if ( ! isset( $tasks[ $current_task_name ] ) ) {
[277] Fix | Delete
$current_task_name = \key( $tasks );
[278] Fix | Delete
}
[279] Fix | Delete
[280] Fix | Delete
$current_task = \current( $tasks );
[281] Fix | Delete
while ( $current_task !== false ) {
[282] Fix | Delete
// Skip the tasks that have already been done.
[283] Fix | Delete
if ( \key( $tasks ) !== $current_task_name ) {
[284] Fix | Delete
$current_task = \next( $tasks );
[285] Fix | Delete
continue;
[286] Fix | Delete
}
[287] Fix | Delete
[288] Fix | Delete
// Call the cleanup callback function that accompanies the current task.
[289] Fix | Delete
$items_cleaned = $current_task( $limit );
[290] Fix | Delete
[291] Fix | Delete
if ( $items_cleaned === false ) {
[292] Fix | Delete
$this->reset_cleanup();
[293] Fix | Delete
[294] Fix | Delete
return;
[295] Fix | Delete
}
[296] Fix | Delete
[297] Fix | Delete
if ( $items_cleaned === 0 ) {
[298] Fix | Delete
// Check if we are finished with all tasks.
[299] Fix | Delete
if ( \next( $tasks ) === false ) {
[300] Fix | Delete
$this->reset_cleanup();
[301] Fix | Delete
[302] Fix | Delete
return;
[303] Fix | Delete
}
[304] Fix | Delete
[305] Fix | Delete
// Continue with the next task next time the cron job is run.
[306] Fix | Delete
\update_option( self::CURRENT_TASK_OPTION, \key( $tasks ) );
[307] Fix | Delete
[308] Fix | Delete
return;
[309] Fix | Delete
}
[310] Fix | Delete
[311] Fix | Delete
// There were items deleted for the current task, continue with the same task next cron call.
[312] Fix | Delete
return;
[313] Fix | Delete
}
[314] Fix | Delete
}
[315] Fix | Delete
}
[316] Fix | Delete
[317] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function