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: indexing-notification-integration.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Integrations\Admin;
[2] Fix | Delete
[3] Fix | Delete
use WPSEO_Addon_Manager;
[4] Fix | Delete
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
[5] Fix | Delete
use Yoast\WP\SEO\Conditionals\Not_Admin_Ajax_Conditional;
[6] Fix | Delete
use Yoast\WP\SEO\Conditionals\User_Can_Manage_Wpseo_Options_Conditional;
[7] Fix | Delete
use Yoast\WP\SEO\Config\Indexing_Reasons;
[8] Fix | Delete
use Yoast\WP\SEO\Helpers\Current_Page_Helper;
[9] Fix | Delete
use Yoast\WP\SEO\Helpers\Environment_Helper;
[10] Fix | Delete
use Yoast\WP\SEO\Helpers\Indexing_Helper;
[11] Fix | Delete
use Yoast\WP\SEO\Helpers\Notification_Helper;
[12] Fix | Delete
use Yoast\WP\SEO\Helpers\Product_Helper;
[13] Fix | Delete
use Yoast\WP\SEO\Helpers\Short_Link_Helper;
[14] Fix | Delete
use Yoast\WP\SEO\Integrations\Integration_Interface;
[15] Fix | Delete
use Yoast\WP\SEO\Presenters\Admin\Indexing_Failed_Notification_Presenter;
[16] Fix | Delete
use Yoast\WP\SEO\Presenters\Admin\Indexing_Notification_Presenter;
[17] Fix | Delete
use Yoast_Notification;
[18] Fix | Delete
use Yoast_Notification_Center;
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* Class Indexing_Notification_Integration.
[22] Fix | Delete
*
[23] Fix | Delete
* @package Yoast\WP\SEO\Integrations\Admin
[24] Fix | Delete
*/
[25] Fix | Delete
class Indexing_Notification_Integration implements Integration_Interface {
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* The notification ID.
[29] Fix | Delete
*/
[30] Fix | Delete
public const NOTIFICATION_ID = 'wpseo-reindex';
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* The Yoast notification center.
[34] Fix | Delete
*
[35] Fix | Delete
* @var Yoast_Notification_Center
[36] Fix | Delete
*/
[37] Fix | Delete
protected $notification_center;
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* The product helper.
[41] Fix | Delete
*
[42] Fix | Delete
* @var Product_Helper
[43] Fix | Delete
*/
[44] Fix | Delete
protected $product_helper;
[45] Fix | Delete
[46] Fix | Delete
/**
[47] Fix | Delete
* The current page helper.
[48] Fix | Delete
*
[49] Fix | Delete
* @var Current_Page_Helper
[50] Fix | Delete
*/
[51] Fix | Delete
protected $page_helper;
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* The short link helper.
[55] Fix | Delete
*
[56] Fix | Delete
* @var Short_Link_Helper
[57] Fix | Delete
*/
[58] Fix | Delete
protected $short_link_helper;
[59] Fix | Delete
[60] Fix | Delete
/**
[61] Fix | Delete
* The notification helper.
[62] Fix | Delete
*
[63] Fix | Delete
* @var Notification_Helper
[64] Fix | Delete
*/
[65] Fix | Delete
protected $notification_helper;
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* The indexing helper.
[69] Fix | Delete
*
[70] Fix | Delete
* @var Indexing_Helper
[71] Fix | Delete
*/
[72] Fix | Delete
protected $indexing_helper;
[73] Fix | Delete
[74] Fix | Delete
/**
[75] Fix | Delete
* The Addon Manager.
[76] Fix | Delete
*
[77] Fix | Delete
* @var WPSEO_Addon_Manager
[78] Fix | Delete
*/
[79] Fix | Delete
protected $addon_manager;
[80] Fix | Delete
[81] Fix | Delete
/**
[82] Fix | Delete
* The Environment Helper.
[83] Fix | Delete
*
[84] Fix | Delete
* @var Environment_Helper
[85] Fix | Delete
*/
[86] Fix | Delete
protected $environment_helper;
[87] Fix | Delete
[88] Fix | Delete
/**
[89] Fix | Delete
* Indexing_Notification_Integration constructor.
[90] Fix | Delete
*
[91] Fix | Delete
* @param Yoast_Notification_Center $notification_center The notification center.
[92] Fix | Delete
* @param Product_Helper $product_helper The product helper.
[93] Fix | Delete
* @param Current_Page_Helper $page_helper The current page helper.
[94] Fix | Delete
* @param Short_Link_Helper $short_link_helper The short link helper.
[95] Fix | Delete
* @param Notification_Helper $notification_helper The notification helper.
[96] Fix | Delete
* @param Indexing_Helper $indexing_helper The indexing helper.
[97] Fix | Delete
* @param WPSEO_Addon_Manager $addon_manager The addon manager.
[98] Fix | Delete
* @param Environment_Helper $environment_helper The environment helper.
[99] Fix | Delete
*/
[100] Fix | Delete
public function __construct(
[101] Fix | Delete
Yoast_Notification_Center $notification_center,
[102] Fix | Delete
Product_Helper $product_helper,
[103] Fix | Delete
Current_Page_Helper $page_helper,
[104] Fix | Delete
Short_Link_Helper $short_link_helper,
[105] Fix | Delete
Notification_Helper $notification_helper,
[106] Fix | Delete
Indexing_Helper $indexing_helper,
[107] Fix | Delete
WPSEO_Addon_Manager $addon_manager,
[108] Fix | Delete
Environment_Helper $environment_helper
[109] Fix | Delete
) {
[110] Fix | Delete
$this->notification_center = $notification_center;
[111] Fix | Delete
$this->product_helper = $product_helper;
[112] Fix | Delete
$this->page_helper = $page_helper;
[113] Fix | Delete
$this->short_link_helper = $short_link_helper;
[114] Fix | Delete
$this->notification_helper = $notification_helper;
[115] Fix | Delete
$this->indexing_helper = $indexing_helper;
[116] Fix | Delete
$this->addon_manager = $addon_manager;
[117] Fix | Delete
$this->environment_helper = $environment_helper;
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
/**
[121] Fix | Delete
* Initializes the integration.
[122] Fix | Delete
*
[123] Fix | Delete
* Adds hooks and jobs to cleanup or add the notification when necessary.
[124] Fix | Delete
*
[125] Fix | Delete
* @return void
[126] Fix | Delete
*/
[127] Fix | Delete
public function register_hooks() {
[128] Fix | Delete
if ( $this->page_helper->get_current_yoast_seo_page() === 'wpseo_dashboard' ) {
[129] Fix | Delete
\add_action( 'admin_init', [ $this, 'maybe_cleanup_notification' ] );
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
if ( $this->indexing_helper->has_reason() ) {
[133] Fix | Delete
\add_action( 'admin_init', [ $this, 'maybe_create_notification' ] );
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
\add_action( self::NOTIFICATION_ID, [ $this, 'maybe_create_notification' ] );
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
/**
[140] Fix | Delete
* Returns the conditionals based on which this loadable should be active.
[141] Fix | Delete
*
[142] Fix | Delete
* @return array The conditionals.
[143] Fix | Delete
*/
[144] Fix | Delete
public static function get_conditionals() {
[145] Fix | Delete
return [
[146] Fix | Delete
Admin_Conditional::class,
[147] Fix | Delete
Not_Admin_Ajax_Conditional::class,
[148] Fix | Delete
User_Can_Manage_Wpseo_Options_Conditional::class,
[149] Fix | Delete
];
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
/**
[153] Fix | Delete
* Checks whether the notification should be shown and adds
[154] Fix | Delete
* it to the notification center if this is the case.
[155] Fix | Delete
*
[156] Fix | Delete
* @return void
[157] Fix | Delete
*/
[158] Fix | Delete
public function maybe_create_notification() {
[159] Fix | Delete
if ( ! $this->should_show_notification() ) {
[160] Fix | Delete
return;
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
if ( ! $this->notification_center->get_notification_by_id( self::NOTIFICATION_ID ) ) {
[164] Fix | Delete
$notification = $this->notification();
[165] Fix | Delete
$this->notification_helper->restore_notification( $notification );
[166] Fix | Delete
$this->notification_center->add_notification( $notification );
[167] Fix | Delete
}
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
/**
[171] Fix | Delete
* Checks whether the notification should not be shown anymore and removes
[172] Fix | Delete
* it from the notification center if this is the case.
[173] Fix | Delete
*
[174] Fix | Delete
* @return void
[175] Fix | Delete
*/
[176] Fix | Delete
public function maybe_cleanup_notification() {
[177] Fix | Delete
$notification = $this->notification_center->get_notification_by_id( self::NOTIFICATION_ID );
[178] Fix | Delete
[179] Fix | Delete
if ( $notification === null ) {
[180] Fix | Delete
return;
[181] Fix | Delete
}
[182] Fix | Delete
[183] Fix | Delete
if ( $this->should_show_notification() ) {
[184] Fix | Delete
return;
[185] Fix | Delete
}
[186] Fix | Delete
[187] Fix | Delete
$this->notification_center->remove_notification_by_id( self::NOTIFICATION_ID );
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
/**
[191] Fix | Delete
* Checks whether the notification should be shown.
[192] Fix | Delete
*
[193] Fix | Delete
* @return bool If the notification should be shown.
[194] Fix | Delete
*/
[195] Fix | Delete
protected function should_show_notification() {
[196] Fix | Delete
if ( ! $this->environment_helper->is_production_mode() ) {
[197] Fix | Delete
return false;
[198] Fix | Delete
}
[199] Fix | Delete
// Don't show a notification if the indexing has already been started earlier.
[200] Fix | Delete
if ( $this->indexing_helper->get_started() > 0 ) {
[201] Fix | Delete
return false;
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
// We're about to perform expensive queries, let's inform.
[205] Fix | Delete
\add_filter( 'wpseo_unindexed_count_queries_ran', '__return_true' );
[206] Fix | Delete
[207] Fix | Delete
// Never show a notification when nothing should be indexed.
[208] Fix | Delete
return $this->indexing_helper->get_limited_filtered_unindexed_count( 1 ) > 0;
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
/**
[212] Fix | Delete
* Returns an instance of the notification.
[213] Fix | Delete
*
[214] Fix | Delete
* @return Yoast_Notification The notification to show.
[215] Fix | Delete
*/
[216] Fix | Delete
protected function notification() {
[217] Fix | Delete
$reason = $this->indexing_helper->get_reason();
[218] Fix | Delete
[219] Fix | Delete
$presenter = $this->get_presenter( $reason );
[220] Fix | Delete
[221] Fix | Delete
return new Yoast_Notification(
[222] Fix | Delete
$presenter,
[223] Fix | Delete
[
[224] Fix | Delete
'type' => Yoast_Notification::WARNING,
[225] Fix | Delete
'id' => self::NOTIFICATION_ID,
[226] Fix | Delete
'capabilities' => 'wpseo_manage_options',
[227] Fix | Delete
'priority' => 0.8,
[228] Fix | Delete
]
[229] Fix | Delete
);
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
/**
[233] Fix | Delete
* Gets the presenter to use to show the notification.
[234] Fix | Delete
*
[235] Fix | Delete
* @param string $reason The reason for the notification.
[236] Fix | Delete
*
[237] Fix | Delete
* @return Indexing_Failed_Notification_Presenter|Indexing_Notification_Presenter
[238] Fix | Delete
*/
[239] Fix | Delete
protected function get_presenter( $reason ) {
[240] Fix | Delete
if ( $reason === Indexing_Reasons::REASON_INDEXING_FAILED ) {
[241] Fix | Delete
$presenter = new Indexing_Failed_Notification_Presenter( $this->product_helper, $this->short_link_helper, $this->addon_manager );
[242] Fix | Delete
}
[243] Fix | Delete
else {
[244] Fix | Delete
$total_unindexed = $this->indexing_helper->get_filtered_unindexed_count();
[245] Fix | Delete
$presenter = new Indexing_Notification_Presenter( $this->short_link_helper, $total_unindexed, $reason );
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
return $presenter;
[249] Fix | Delete
}
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function