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: search-engines-discouraged-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\Conditionals\No_Conditionals;
[4] Fix | Delete
use Yoast\WP\SEO\Helpers\Capability_Helper;
[5] Fix | Delete
use Yoast\WP\SEO\Helpers\Current_Page_Helper;
[6] Fix | Delete
use Yoast\WP\SEO\Helpers\Notification_Helper;
[7] Fix | Delete
use Yoast\WP\SEO\Helpers\Options_Helper;
[8] Fix | Delete
use Yoast\WP\SEO\Integrations\Integration_Interface;
[9] Fix | Delete
use Yoast\WP\SEO\Presenters\Admin\Search_Engines_Discouraged_Presenter;
[10] Fix | Delete
use Yoast_Notification;
[11] Fix | Delete
use Yoast_Notification_Center;
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* Shows a notification for users who have access for robots disabled.
[15] Fix | Delete
*/
[16] Fix | Delete
class Search_Engines_Discouraged_Watcher implements Integration_Interface {
[17] Fix | Delete
[18] Fix | Delete
use No_Conditionals;
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* The notification ID.
[22] Fix | Delete
*/
[23] Fix | Delete
public const NOTIFICATION_ID = 'wpseo-search-engines-discouraged';
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* The Yoast notification center.
[27] Fix | Delete
*
[28] Fix | Delete
* @var Yoast_Notification_Center
[29] Fix | Delete
*/
[30] Fix | Delete
protected $notification_center;
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* The notification helper.
[34] Fix | Delete
*
[35] Fix | Delete
* @var Notification_Helper
[36] Fix | Delete
*/
[37] Fix | Delete
protected $notification_helper;
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* The search engines discouraged presenter.
[41] Fix | Delete
*
[42] Fix | Delete
* @var Search_Engines_Discouraged_Presenter
[43] Fix | Delete
*/
[44] Fix | Delete
protected $presenter;
[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 $current_page_helper;
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* The options helper.
[55] Fix | Delete
*
[56] Fix | Delete
* @var Options_Helper
[57] Fix | Delete
*/
[58] Fix | Delete
protected $options_helper;
[59] Fix | Delete
[60] Fix | Delete
/**
[61] Fix | Delete
* The capability helper.
[62] Fix | Delete
*
[63] Fix | Delete
* @var Capability_Helper
[64] Fix | Delete
*/
[65] Fix | Delete
protected $capability_helper;
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* Search_Engines_Discouraged_Watcher constructor.
[69] Fix | Delete
*
[70] Fix | Delete
* @param Yoast_Notification_Center $notification_center The notification center.
[71] Fix | Delete
* @param Notification_Helper $notification_helper The notification helper.
[72] Fix | Delete
* @param Current_Page_Helper $current_page_helper The current page helper.
[73] Fix | Delete
* @param Options_Helper $options_helper The options helper.
[74] Fix | Delete
* @param Capability_Helper $capability_helper The capability helper.
[75] Fix | Delete
*/
[76] Fix | Delete
public function __construct(
[77] Fix | Delete
Yoast_Notification_Center $notification_center,
[78] Fix | Delete
Notification_Helper $notification_helper,
[79] Fix | Delete
Current_Page_Helper $current_page_helper,
[80] Fix | Delete
Options_Helper $options_helper,
[81] Fix | Delete
Capability_Helper $capability_helper
[82] Fix | Delete
) {
[83] Fix | Delete
$this->notification_center = $notification_center;
[84] Fix | Delete
$this->notification_helper = $notification_helper;
[85] Fix | Delete
$this->current_page_helper = $current_page_helper;
[86] Fix | Delete
$this->options_helper = $options_helper;
[87] Fix | Delete
$this->capability_helper = $capability_helper;
[88] Fix | Delete
$this->presenter = new Search_Engines_Discouraged_Presenter();
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Initializes the integration.
[93] Fix | Delete
*
[94] Fix | Delete
* On admin_init, it is checked whether the notification about search engines being discouraged should be shown.
[95] Fix | Delete
* On admin_notices, the notice about the search engines being discouraged will be shown when necessary.
[96] Fix | Delete
*
[97] Fix | Delete
* @return void
[98] Fix | Delete
*/
[99] Fix | Delete
public function register_hooks() {
[100] Fix | Delete
\add_action( 'admin_init', [ $this, 'manage_search_engines_discouraged_notification' ] );
[101] Fix | Delete
[102] Fix | Delete
/*
[103] Fix | Delete
* The `admin_notices` hook fires on single site admin pages vs.
[104] Fix | Delete
* `network_admin_notices` which fires on multisite admin pages and
[105] Fix | Delete
* `user_admin_notices` which fires on multisite user admin pages.
[106] Fix | Delete
*/
[107] Fix | Delete
\add_action( 'admin_notices', [ $this, 'maybe_show_search_engines_discouraged_notice' ] );
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
/**
[111] Fix | Delete
* Manage the search engines discouraged notification.
[112] Fix | Delete
*
[113] Fix | Delete
* Shows the notification if needed and deletes it if needed.
[114] Fix | Delete
*
[115] Fix | Delete
* @return void
[116] Fix | Delete
*/
[117] Fix | Delete
public function manage_search_engines_discouraged_notification() {
[118] Fix | Delete
if ( ! $this->should_show_search_engines_discouraged_notification() ) {
[119] Fix | Delete
$this->remove_search_engines_discouraged_notification_if_exists();
[120] Fix | Delete
}
[121] Fix | Delete
else {
[122] Fix | Delete
$this->maybe_add_search_engines_discouraged_notification();
[123] Fix | Delete
}
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
/**
[127] Fix | Delete
* Show the search engine discouraged notice when needed.
[128] Fix | Delete
*
[129] Fix | Delete
* @return void
[130] Fix | Delete
*/
[131] Fix | Delete
public function maybe_show_search_engines_discouraged_notice() {
[132] Fix | Delete
if ( ! $this->should_show_search_engines_discouraged_notice() ) {
[133] Fix | Delete
return;
[134] Fix | Delete
}
[135] Fix | Delete
$this->show_search_engines_discouraged_notice();
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
/**
[139] Fix | Delete
* Whether the search engines discouraged notification should be shown.
[140] Fix | Delete
*
[141] Fix | Delete
* @return bool
[142] Fix | Delete
*/
[143] Fix | Delete
protected function should_show_search_engines_discouraged_notification() {
[144] Fix | Delete
return $this->search_engines_are_discouraged() && $this->options_helper->get( 'ignore_search_engines_discouraged_notice', false ) === false;
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
/**
[148] Fix | Delete
* Remove the search engines discouraged notification if it exists.
[149] Fix | Delete
*
[150] Fix | Delete
* @return void
[151] Fix | Delete
*/
[152] Fix | Delete
protected function remove_search_engines_discouraged_notification_if_exists() {
[153] Fix | Delete
$this->notification_center->remove_notification_by_id( self::NOTIFICATION_ID );
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
/**
[157] Fix | Delete
* Add the search engines discouraged notification if it does not exist yet.
[158] Fix | Delete
*
[159] Fix | Delete
* @return void
[160] Fix | Delete
*/
[161] Fix | Delete
protected function maybe_add_search_engines_discouraged_notification() {
[162] Fix | Delete
if ( ! $this->notification_center->get_notification_by_id( self::NOTIFICATION_ID ) ) {
[163] Fix | Delete
$notification = $this->notification();
[164] Fix | Delete
$this->notification_helper->restore_notification( $notification );
[165] Fix | Delete
$this->notification_center->add_notification( $notification );
[166] Fix | Delete
}
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
/**
[170] Fix | Delete
* Checks whether search engines are discouraged from indexing the site.
[171] Fix | Delete
*
[172] Fix | Delete
* @return bool Whether search engines are discouraged from indexing the site.
[173] Fix | Delete
*/
[174] Fix | Delete
protected function search_engines_are_discouraged() {
[175] Fix | Delete
return (string) \get_option( 'blog_public' ) === '0';
[176] Fix | Delete
}
[177] Fix | Delete
[178] Fix | Delete
/**
[179] Fix | Delete
* Whether the search engines notice should be shown.
[180] Fix | Delete
*
[181] Fix | Delete
* @return bool
[182] Fix | Delete
*/
[183] Fix | Delete
protected function should_show_search_engines_discouraged_notice() {
[184] Fix | Delete
$pages_to_show_notice = [
[185] Fix | Delete
'index.php',
[186] Fix | Delete
'plugins.php',
[187] Fix | Delete
'update-core.php',
[188] Fix | Delete
];
[189] Fix | Delete
[190] Fix | Delete
return (
[191] Fix | Delete
$this->search_engines_are_discouraged()
[192] Fix | Delete
&& $this->capability_helper->current_user_can( 'manage_options' )
[193] Fix | Delete
&& $this->options_helper->get( 'ignore_search_engines_discouraged_notice', false ) === false
[194] Fix | Delete
&& (
[195] Fix | Delete
$this->current_page_helper->is_yoast_seo_page()
[196] Fix | Delete
|| \in_array( $this->current_page_helper->get_current_admin_page(), $pages_to_show_notice, true )
[197] Fix | Delete
)
[198] Fix | Delete
&& $this->current_page_helper->get_current_yoast_seo_page() !== 'wpseo_dashboard'
[199] Fix | Delete
);
[200] Fix | Delete
}
[201] Fix | Delete
[202] Fix | Delete
/**
[203] Fix | Delete
* Show the search engines discouraged notice.
[204] Fix | Delete
*
[205] Fix | Delete
* @return void
[206] Fix | Delete
*/
[207] Fix | Delete
protected function show_search_engines_discouraged_notice() {
[208] Fix | Delete
\printf(
[209] Fix | Delete
'<div id="robotsmessage" class="notice notice-error">%1$s</div>',
[210] Fix | Delete
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output from present() is considered safe.
[211] Fix | Delete
$this->presenter->present()
[212] Fix | Delete
);
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
/**
[216] Fix | Delete
* Returns an instance of the notification.
[217] Fix | Delete
*
[218] Fix | Delete
* @return Yoast_Notification The notification to show.
[219] Fix | Delete
*/
[220] Fix | Delete
protected function notification() {
[221] Fix | Delete
return new Yoast_Notification(
[222] Fix | Delete
$this->presenter->present(),
[223] Fix | Delete
[
[224] Fix | Delete
'type' => Yoast_Notification::ERROR,
[225] Fix | Delete
'id' => self::NOTIFICATION_ID,
[226] Fix | Delete
'capabilities' => 'wpseo_manage_options',
[227] Fix | Delete
'priority' => 1,
[228] Fix | Delete
]
[229] Fix | Delete
);
[230] Fix | Delete
}
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function