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.../watchers
File: indexable-attachment-watcher.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Integrations\Watchers;
[2] Fix | Delete
[3] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Indexable_Post_Indexation_Action;
[4] Fix | Delete
use Yoast\WP\SEO\Conditionals\Migrations_Conditional;
[5] Fix | Delete
use Yoast\WP\SEO\Config\Indexing_Reasons;
[6] Fix | Delete
use Yoast\WP\SEO\Helpers\Attachment_Cleanup_Helper;
[7] Fix | Delete
use Yoast\WP\SEO\Helpers\Indexing_Helper;
[8] Fix | Delete
use Yoast\WP\SEO\Integrations\Cleanup_Integration;
[9] Fix | Delete
use Yoast\WP\SEO\Integrations\Integration_Interface;
[10] Fix | Delete
use Yoast_Notification_Center;
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Watches the disable-attachment key in wpseo_titles, in order to clear the permalink of the category indexables.
[14] Fix | Delete
*/
[15] Fix | Delete
class Indexable_Attachment_Watcher implements Integration_Interface {
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* The indexing helper.
[19] Fix | Delete
*
[20] Fix | Delete
* @var Indexing_Helper
[21] Fix | Delete
*/
[22] Fix | Delete
protected $indexing_helper;
[23] Fix | Delete
[24] Fix | Delete
/**
[25] Fix | Delete
* The attachment cleanup helper.
[26] Fix | Delete
*
[27] Fix | Delete
* @var Attachment_Cleanup_Helper
[28] Fix | Delete
*/
[29] Fix | Delete
protected $attachment_cleanup;
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* The notifications center.
[33] Fix | Delete
*
[34] Fix | Delete
* @var Yoast_Notification_Center
[35] Fix | Delete
*/
[36] Fix | Delete
private $notification_center;
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* Returns the conditionals based on which this loadable should be active.
[40] Fix | Delete
*
[41] Fix | Delete
* @return array
[42] Fix | Delete
*/
[43] Fix | Delete
public static function get_conditionals() {
[44] Fix | Delete
return [ Migrations_Conditional::class ];
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* Indexable_Attachment_Watcher constructor.
[49] Fix | Delete
*
[50] Fix | Delete
* @param Indexing_Helper $indexing_helper The indexing helper.
[51] Fix | Delete
* @param Attachment_Cleanup_Helper $attachment_cleanup The attachment cleanup helper.
[52] Fix | Delete
* @param Yoast_Notification_Center $notification_center The notification center.
[53] Fix | Delete
*/
[54] Fix | Delete
public function __construct(
[55] Fix | Delete
Indexing_Helper $indexing_helper,
[56] Fix | Delete
Attachment_Cleanup_Helper $attachment_cleanup,
[57] Fix | Delete
Yoast_Notification_Center $notification_center
[58] Fix | Delete
) {
[59] Fix | Delete
$this->indexing_helper = $indexing_helper;
[60] Fix | Delete
$this->attachment_cleanup = $attachment_cleanup;
[61] Fix | Delete
$this->notification_center = $notification_center;
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
/**
[65] Fix | Delete
* Initializes the integration.
[66] Fix | Delete
*
[67] Fix | Delete
* This is the place to register hooks and filters.
[68] Fix | Delete
*
[69] Fix | Delete
* @return void
[70] Fix | Delete
*/
[71] Fix | Delete
public function register_hooks() {
[72] Fix | Delete
\add_action( 'update_option_wpseo_titles', [ $this, 'check_option' ], 20, 2 );
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
/**
[76] Fix | Delete
* Checks if the disable-attachment key in wpseo_titles has a change in value, and if so,
[77] Fix | Delete
* either it cleans up attachment indexables when it has been toggled to true,
[78] Fix | Delete
* or it starts displaying a notification for the user to start a new SEO optimization.
[79] Fix | Delete
*
[80] Fix | Delete
* @param array $old_value The old value of the wpseo_titles option.
[81] Fix | Delete
* @param array $new_value The new value of the wpseo_titles option.
[82] Fix | Delete
*
[83] Fix | Delete
* @return void
[84] Fix | Delete
*/
[85] Fix | Delete
public function check_option( $old_value, $new_value ) {
[86] Fix | Delete
// If this is the first time saving the option, in which case its value would be false.
[87] Fix | Delete
if ( $old_value === false ) {
[88] Fix | Delete
$old_value = [];
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
// If either value is not an array, return.
[92] Fix | Delete
if ( ! \is_array( $old_value ) || ! \is_array( $new_value ) ) {
[93] Fix | Delete
return;
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
// If both values aren't set, they haven't changed.
[97] Fix | Delete
if ( ! isset( $old_value['disable-attachment'] ) && ! isset( $new_value['disable-attachment'] ) ) {
[98] Fix | Delete
return;
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
// If a new value has been set for 'disable-attachment', there's two things we might need to do, depending on what's the new value.
[102] Fix | Delete
if ( $old_value['disable-attachment'] !== $new_value['disable-attachment'] ) {
[103] Fix | Delete
// Delete cache because we now might have new stuff to index or old unindexed stuff don't need indexing anymore.
[104] Fix | Delete
\delete_transient( Indexable_Post_Indexation_Action::UNINDEXED_COUNT_TRANSIENT );
[105] Fix | Delete
\delete_transient( Indexable_Post_Indexation_Action::UNINDEXED_LIMITED_COUNT_TRANSIENT );
[106] Fix | Delete
[107] Fix | Delete
// Set this core option (introduced in WP 6.4) to ensure consistency.
[108] Fix | Delete
if ( \get_option( 'wp_attachment_pages_enabled' ) !== false ) {
[109] Fix | Delete
\update_option( 'wp_attachment_pages_enabled', (int) ! $new_value['disable-attachment'] );
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
switch ( $new_value['disable-attachment'] ) {
[113] Fix | Delete
case false:
[114] Fix | Delete
$this->indexing_helper->set_reason( Indexing_Reasons::REASON_ATTACHMENTS_MADE_ENABLED );
[115] Fix | Delete
return;
[116] Fix | Delete
case true:
[117] Fix | Delete
$this->attachment_cleanup->remove_attachment_indexables( false );
[118] Fix | Delete
$this->attachment_cleanup->clean_attachment_links_from_target_indexable_ids( false );
[119] Fix | Delete
[120] Fix | Delete
if ( ! \wp_next_scheduled( Cleanup_Integration::START_HOOK ) ) {
[121] Fix | Delete
// This just schedules the cleanup routine cron again.
[122] Fix | Delete
\wp_schedule_single_event( ( \time() + ( \MINUTE_IN_SECONDS * 5 ) ), Cleanup_Integration::START_HOOK );
[123] Fix | Delete
}
[124] Fix | Delete
return;
[125] Fix | Delete
}
[126] Fix | Delete
}
[127] Fix | Delete
}
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function