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.../front-en...
File: wp-robots-integration.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Integrations\Front_End;
[2] Fix | Delete
[3] Fix | Delete
use Yoast\WP\SEO\Conditionals\Front_End_Conditional;
[4] Fix | Delete
use Yoast\WP\SEO\Conditionals\WP_Robots_Conditional;
[5] Fix | Delete
use Yoast\WP\SEO\Integrations\Integration_Interface;
[6] Fix | Delete
use Yoast\WP\SEO\Memoizers\Meta_Tags_Context_Memoizer;
[7] Fix | Delete
use Yoast\WP\SEO\Presenters\Robots_Presenter;
[8] Fix | Delete
[9] Fix | Delete
/**
[10] Fix | Delete
* Class WP_Robots_Integration
[11] Fix | Delete
*
[12] Fix | Delete
* @package Yoast\WP\SEO\Integrations\Front_End
[13] Fix | Delete
*/
[14] Fix | Delete
class WP_Robots_Integration implements Integration_Interface {
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* The meta tags context memoizer.
[18] Fix | Delete
*
[19] Fix | Delete
* @var Meta_Tags_Context_Memoizer
[20] Fix | Delete
*/
[21] Fix | Delete
protected $context_memoizer;
[22] Fix | Delete
[23] Fix | Delete
/**
[24] Fix | Delete
* Sets the dependencies for this integration.
[25] Fix | Delete
*
[26] Fix | Delete
* @param Meta_Tags_Context_Memoizer $context_memoizer The meta tags context memoizer.
[27] Fix | Delete
*/
[28] Fix | Delete
public function __construct( Meta_Tags_Context_Memoizer $context_memoizer ) {
[29] Fix | Delete
$this->context_memoizer = $context_memoizer;
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* Initializes the integration.
[34] Fix | Delete
*
[35] Fix | Delete
* This is the place to register hooks and filters.
[36] Fix | Delete
*
[37] Fix | Delete
* @return void
[38] Fix | Delete
*/
[39] Fix | Delete
public function register_hooks() {
[40] Fix | Delete
/**
[41] Fix | Delete
* Allow control of the `wp_robots` filter by prioritizing our hook 10 less than max.
[42] Fix | Delete
* Use the `wpseo_robots` filter to filter the Yoast robots output, instead of WordPress core.
[43] Fix | Delete
*/
[44] Fix | Delete
\add_filter( 'wp_robots', [ $this, 'add_robots' ], ( \PHP_INT_MAX - 10 ) );
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* Returns the conditionals based on which this loadable should be active.
[49] Fix | Delete
*
[50] Fix | Delete
* @return array The conditionals.
[51] Fix | Delete
*/
[52] Fix | Delete
public static function get_conditionals() {
[53] Fix | Delete
return [
[54] Fix | Delete
Front_End_Conditional::class,
[55] Fix | Delete
WP_Robots_Conditional::class,
[56] Fix | Delete
];
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Adds our robots tag value to the WordPress robots tag output.
[61] Fix | Delete
*
[62] Fix | Delete
* @param array $robots The current robots data.
[63] Fix | Delete
*
[64] Fix | Delete
* @return array The robots data.
[65] Fix | Delete
*/
[66] Fix | Delete
public function add_robots( $robots ) {
[67] Fix | Delete
if ( ! \is_array( $robots ) ) {
[68] Fix | Delete
return $this->get_robots_value();
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
$merged_robots = \array_merge( $robots, $this->get_robots_value() );
[72] Fix | Delete
$filtered_robots = $this->enforce_robots_congruence( $merged_robots );
[73] Fix | Delete
$sorted_robots = $this->sort_robots( $filtered_robots );
[74] Fix | Delete
[75] Fix | Delete
// Filter all falsy-null robot values.
[76] Fix | Delete
return \array_filter( $sorted_robots );
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
* Retrieves the robots key-value pairs.
[81] Fix | Delete
*
[82] Fix | Delete
* @return array The robots key-value pairs.
[83] Fix | Delete
*/
[84] Fix | Delete
protected function get_robots_value() {
[85] Fix | Delete
$context = $this->context_memoizer->for_current_page();
[86] Fix | Delete
[87] Fix | Delete
$robots_presenter = new Robots_Presenter();
[88] Fix | Delete
$robots_presenter->presentation = $context->presentation;
[89] Fix | Delete
return $this->format_robots( $robots_presenter->get() );
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
/**
[93] Fix | Delete
* Formats our robots fields, to match the pattern WordPress is using.
[94] Fix | Delete
*
[95] Fix | Delete
* Our format: `[ 'index' => 'noindex', 'max-image-preview' => 'max-image-preview:large', ... ]`
[96] Fix | Delete
* WordPress format: `[ 'noindex' => true, 'max-image-preview' => 'large', ... ]`
[97] Fix | Delete
*
[98] Fix | Delete
* @param array $robots Our robots value.
[99] Fix | Delete
*
[100] Fix | Delete
* @return array The formatted robots.
[101] Fix | Delete
*/
[102] Fix | Delete
protected function format_robots( $robots ) {
[103] Fix | Delete
foreach ( $robots as $key => $value ) {
[104] Fix | Delete
// When the entry represents for example: max-image-preview:large.
[105] Fix | Delete
$colon_position = \strpos( $value, ':' );
[106] Fix | Delete
if ( $colon_position !== false ) {
[107] Fix | Delete
$robots[ $key ] = \substr( $value, ( $colon_position + 1 ) );
[108] Fix | Delete
[109] Fix | Delete
continue;
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
// When index => noindex, we want a separate noindex as entry in array.
[113] Fix | Delete
if ( \strpos( $value, 'no' ) === 0 ) {
[114] Fix | Delete
$robots[ $key ] = false;
[115] Fix | Delete
$robots[ $value ] = true;
[116] Fix | Delete
[117] Fix | Delete
continue;
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
// When the key is equal to the value, just make its value a boolean.
[121] Fix | Delete
if ( $key === $value ) {
[122] Fix | Delete
$robots[ $key ] = true;
[123] Fix | Delete
}
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
return $robots;
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
/**
[130] Fix | Delete
* Ensures all other possible robots values are congruent with nofollow and or noindex.
[131] Fix | Delete
*
[132] Fix | Delete
* WordPress might add some robot values again.
[133] Fix | Delete
* When the page is set to noindex we want to filter out these values.
[134] Fix | Delete
*
[135] Fix | Delete
* @param array $robots The robots.
[136] Fix | Delete
*
[137] Fix | Delete
* @return array The filtered robots.
[138] Fix | Delete
*/
[139] Fix | Delete
protected function enforce_robots_congruence( $robots ) {
[140] Fix | Delete
if ( ! empty( $robots['nofollow'] ) ) {
[141] Fix | Delete
$robots['follow'] = null;
[142] Fix | Delete
}
[143] Fix | Delete
if ( ! empty( $robots['noarchive'] ) ) {
[144] Fix | Delete
$robots['archive'] = null;
[145] Fix | Delete
}
[146] Fix | Delete
if ( ! empty( $robots['noimageindex'] ) ) {
[147] Fix | Delete
$robots['imageindex'] = null;
[148] Fix | Delete
[149] Fix | Delete
// `max-image-preview` should set be to `none` when `noimageindex` is present.
[150] Fix | Delete
// Using `isset` rather than `! empty` here so that in the rare case of `max-image-preview`
[151] Fix | Delete
// being equal to an empty string due to filtering, its value would still be set to `none`.
[152] Fix | Delete
if ( isset( $robots['max-image-preview'] ) ) {
[153] Fix | Delete
$robots['max-image-preview'] = 'none';
[154] Fix | Delete
}
[155] Fix | Delete
}
[156] Fix | Delete
if ( ! empty( $robots['nosnippet'] ) ) {
[157] Fix | Delete
$robots['snippet'] = null;
[158] Fix | Delete
}
[159] Fix | Delete
if ( ! empty( $robots['noindex'] ) ) {
[160] Fix | Delete
$robots['index'] = null;
[161] Fix | Delete
$robots['imageindex'] = null;
[162] Fix | Delete
$robots['noimageindex'] = null;
[163] Fix | Delete
$robots['archive'] = null;
[164] Fix | Delete
$robots['noarchive'] = null;
[165] Fix | Delete
$robots['snippet'] = null;
[166] Fix | Delete
$robots['nosnippet'] = null;
[167] Fix | Delete
$robots['max-snippet'] = null;
[168] Fix | Delete
$robots['max-image-preview'] = null;
[169] Fix | Delete
$robots['max-video-preview'] = null;
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
return $robots;
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
/**
[176] Fix | Delete
* Sorts the robots array.
[177] Fix | Delete
*
[178] Fix | Delete
* @param array $robots The robots array.
[179] Fix | Delete
*
[180] Fix | Delete
* @return array The sorted robots array.
[181] Fix | Delete
*/
[182] Fix | Delete
protected function sort_robots( $robots ) {
[183] Fix | Delete
\uksort(
[184] Fix | Delete
$robots,
[185] Fix | Delete
static function ( $a, $b ) {
[186] Fix | Delete
$order = [
[187] Fix | Delete
'index' => 0,
[188] Fix | Delete
'noindex' => 1,
[189] Fix | Delete
'follow' => 2,
[190] Fix | Delete
'nofollow' => 3,
[191] Fix | Delete
];
[192] Fix | Delete
$ai = ( $order[ $a ] ?? 4 );
[193] Fix | Delete
$bi = ( $order[ $b ] ?? 4 );
[194] Fix | Delete
[195] Fix | Delete
return ( $ai - $bi );
[196] Fix | Delete
}
[197] Fix | Delete
);
[198] Fix | Delete
[199] Fix | Delete
return $robots;
[200] Fix | Delete
}
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function