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.../public_h.../wp-conte.../plugins/wordpres.../src/generato.../schema
File: breadcrumb.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Generators\Schema;
[2] Fix | Delete
[3] Fix | Delete
use Yoast\WP\SEO\Config\Schema_IDs;
[4] Fix | Delete
[5] Fix | Delete
/**
[6] Fix | Delete
* Returns schema Breadcrumb data.
[7] Fix | Delete
*/
[8] Fix | Delete
class Breadcrumb extends Abstract_Schema_Piece {
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* Determine if we should add a breadcrumb attribute.
[12] Fix | Delete
*
[13] Fix | Delete
* @return bool
[14] Fix | Delete
*/
[15] Fix | Delete
public function is_needed() {
[16] Fix | Delete
if ( $this->context->indexable->object_type === 'unknown' ) {
[17] Fix | Delete
return false;
[18] Fix | Delete
}
[19] Fix | Delete
[20] Fix | Delete
if ( $this->context->indexable->object_type === 'system-page' && $this->context->indexable->object_sub_type === '404' ) {
[21] Fix | Delete
return false;
[22] Fix | Delete
}
[23] Fix | Delete
[24] Fix | Delete
return true;
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Returns Schema breadcrumb data to allow recognition of page's position in the site hierarchy.
[29] Fix | Delete
*
[30] Fix | Delete
* @link https://developers.google.com/search/docs/data-types/breadcrumb
[31] Fix | Delete
*
[32] Fix | Delete
* @return bool|array Array on success, false on failure.
[33] Fix | Delete
*/
[34] Fix | Delete
public function generate() {
[35] Fix | Delete
$breadcrumbs = $this->context->presentation->breadcrumbs;
[36] Fix | Delete
$list_elements = [];
[37] Fix | Delete
[38] Fix | Delete
// In case of pagination, replace the last breadcrumb, because it only contains "Page [number]" and has no URL.
[39] Fix | Delete
if (
[40] Fix | Delete
(
[41] Fix | Delete
$this->helpers->current_page->is_paged()
[42] Fix | Delete
|| $this->context->indexable->number_of_pages > 1
[43] Fix | Delete
) && (
[44] Fix | Delete
// Do not replace the last breadcrumb on static post pages.
[45] Fix | Delete
! $this->helpers->current_page->is_static_posts_page()
[46] Fix | Delete
// Do not remove the last breadcrumb if only one exists (bugfix for custom paginated frontpages).
[47] Fix | Delete
&& \count( $breadcrumbs ) > 1
[48] Fix | Delete
)
[49] Fix | Delete
) {
[50] Fix | Delete
\array_pop( $breadcrumbs );
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
// Only output breadcrumbs that are not hidden.
[54] Fix | Delete
$breadcrumbs = \array_filter( $breadcrumbs, [ $this, 'not_hidden' ] );
[55] Fix | Delete
[56] Fix | Delete
\reset( $breadcrumbs );
[57] Fix | Delete
[58] Fix | Delete
/*
[59] Fix | Delete
* Check whether at least one of the breadcrumbs is broken.
[60] Fix | Delete
* If so, do not output anything.
[61] Fix | Delete
*/
[62] Fix | Delete
foreach ( $breadcrumbs as $breadcrumb ) {
[63] Fix | Delete
if ( $this->is_broken( $breadcrumb ) ) {
[64] Fix | Delete
return false;
[65] Fix | Delete
}
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
// Create the last breadcrumb.
[69] Fix | Delete
$last_breadcrumb = \array_pop( $breadcrumbs );
[70] Fix | Delete
$breadcrumbs[] = $this->format_last_breadcrumb( $last_breadcrumb );
[71] Fix | Delete
[72] Fix | Delete
// If this is a static front page, prevent nested pages from creating a trail.
[73] Fix | Delete
if ( $this->helpers->current_page->is_home_static_page() ) {
[74] Fix | Delete
[75] Fix | Delete
// Check if we're dealing with a nested page.
[76] Fix | Delete
if ( \count( $breadcrumbs ) > 1 ) {
[77] Fix | Delete
[78] Fix | Delete
// Store the breadcrumbs home variable before dropping the parent page from the Schema.
[79] Fix | Delete
$breadcrumbs_home = $breadcrumbs[0]['text'];
[80] Fix | Delete
$breadcrumbs = [ \array_pop( $breadcrumbs ) ];
[81] Fix | Delete
[82] Fix | Delete
// Make the child page show the breadcrumbs home variable rather than its own title.
[83] Fix | Delete
$breadcrumbs[0]['text'] = $breadcrumbs_home;
[84] Fix | Delete
}
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
$breadcrumbs = \array_filter( $breadcrumbs, [ $this, 'not_empty_text' ] );
[88] Fix | Delete
$breadcrumbs = \array_values( $breadcrumbs );
[89] Fix | Delete
[90] Fix | Delete
// Create intermediate breadcrumbs.
[91] Fix | Delete
foreach ( $breadcrumbs as $index => $breadcrumb ) {
[92] Fix | Delete
$list_elements[] = $this->create_breadcrumb( $index, $breadcrumb );
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
return [
[96] Fix | Delete
'@type' => 'BreadcrumbList',
[97] Fix | Delete
'@id' => $this->context->canonical . Schema_IDs::BREADCRUMB_HASH,
[98] Fix | Delete
'itemListElement' => $list_elements,
[99] Fix | Delete
];
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
/**
[103] Fix | Delete
* Returns a breadcrumb array.
[104] Fix | Delete
*
[105] Fix | Delete
* @param int $index The position in the list.
[106] Fix | Delete
* @param array $breadcrumb The position in the list.
[107] Fix | Delete
*
[108] Fix | Delete
* @return array A breadcrumb listItem.
[109] Fix | Delete
*/
[110] Fix | Delete
private function create_breadcrumb( $index, $breadcrumb ) {
[111] Fix | Delete
$crumb = [
[112] Fix | Delete
'@type' => 'ListItem',
[113] Fix | Delete
'position' => ( $index + 1 ),
[114] Fix | Delete
'name' => $this->helpers->schema->html->smart_strip_tags( $breadcrumb['text'] ),
[115] Fix | Delete
];
[116] Fix | Delete
[117] Fix | Delete
if ( ! empty( $breadcrumb['url'] ) ) {
[118] Fix | Delete
$crumb['item'] = $breadcrumb['url'];
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
return $crumb;
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
/**
[125] Fix | Delete
* Creates the last breadcrumb in the breadcrumb list, omitting the URL per Google's spec.
[126] Fix | Delete
*
[127] Fix | Delete
* @link https://developers.google.com/search/docs/data-types/breadcrumb
[128] Fix | Delete
*
[129] Fix | Delete
* @param array $breadcrumb The position in the list.
[130] Fix | Delete
*
[131] Fix | Delete
* @return array The last of the breadcrumbs.
[132] Fix | Delete
*/
[133] Fix | Delete
private function format_last_breadcrumb( $breadcrumb ) {
[134] Fix | Delete
unset( $breadcrumb['url'] );
[135] Fix | Delete
[136] Fix | Delete
return $breadcrumb;
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
/**
[140] Fix | Delete
* Tests if the breadcrumb is broken.
[141] Fix | Delete
* A breadcrumb is considered broken:
[142] Fix | Delete
* - when it is not an array.
[143] Fix | Delete
* - when it has no URL or text.
[144] Fix | Delete
*
[145] Fix | Delete
* @param array $breadcrumb The breadcrumb to test.
[146] Fix | Delete
*
[147] Fix | Delete
* @return bool `true` if the breadcrumb is broken.
[148] Fix | Delete
*/
[149] Fix | Delete
private function is_broken( $breadcrumb ) {
[150] Fix | Delete
// A breadcrumb is broken if it is not an array.
[151] Fix | Delete
if ( ! \is_array( $breadcrumb ) ) {
[152] Fix | Delete
return true;
[153] Fix | Delete
}
[154] Fix | Delete
[155] Fix | Delete
// A breadcrumb is broken if it does not contain a URL or text.
[156] Fix | Delete
if ( ! \array_key_exists( 'url', $breadcrumb ) || ! \array_key_exists( 'text', $breadcrumb ) ) {
[157] Fix | Delete
return true;
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
return false;
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
/**
[164] Fix | Delete
* Checks whether the breadcrumb is not set to be hidden.
[165] Fix | Delete
*
[166] Fix | Delete
* @param array $breadcrumb The breadcrumb array.
[167] Fix | Delete
*
[168] Fix | Delete
* @return bool If the breadcrumb should not be hidden.
[169] Fix | Delete
*/
[170] Fix | Delete
private function not_hidden( $breadcrumb ) {
[171] Fix | Delete
return empty( $breadcrumb['hide_in_schema'] );
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
/**
[175] Fix | Delete
* Checks whether the breadcrumb has a not empty text.
[176] Fix | Delete
*
[177] Fix | Delete
* @param array $breadcrumb The breadcrumb array.
[178] Fix | Delete
*
[179] Fix | Delete
* @return bool If the breadcrumb has a not empty text.
[180] Fix | Delete
*/
[181] Fix | Delete
private function not_empty_text( $breadcrumb ) {
[182] Fix | Delete
return ! empty( $breadcrumb['text'] );
[183] Fix | Delete
}
[184] Fix | Delete
}
[185] Fix | Delete
[186] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function