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.../third-pa...
File: woocommerce.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Integrations\Third_Party;
[2] Fix | Delete
[3] Fix | Delete
use WPSEO_Replace_Vars;
[4] Fix | Delete
use Yoast\WP\SEO\Conditionals\Front_End_Conditional;
[5] Fix | Delete
use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional;
[6] Fix | Delete
use Yoast\WP\SEO\Helpers\Options_Helper;
[7] Fix | Delete
use Yoast\WP\SEO\Helpers\Pagination_Helper;
[8] Fix | Delete
use Yoast\WP\SEO\Helpers\Woocommerce_Helper;
[9] Fix | Delete
use Yoast\WP\SEO\Integrations\Integration_Interface;
[10] Fix | Delete
use Yoast\WP\SEO\Memoizers\Meta_Tags_Context_Memoizer;
[11] Fix | Delete
use Yoast\WP\SEO\Models\Indexable;
[12] Fix | Delete
use Yoast\WP\SEO\Presentations\Indexable_Presentation;
[13] Fix | Delete
use Yoast\WP\SEO\Repositories\Indexable_Repository;
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* WooCommerce integration.
[17] Fix | Delete
*/
[18] Fix | Delete
class WooCommerce implements Integration_Interface {
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* The options helper.
[22] Fix | Delete
*
[23] Fix | Delete
* @var Options_Helper
[24] Fix | Delete
*/
[25] Fix | Delete
private $options;
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* The WPSEO Replace Vars object.
[29] Fix | Delete
*
[30] Fix | Delete
* @var WPSEO_Replace_Vars
[31] Fix | Delete
*/
[32] Fix | Delete
private $replace_vars;
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* The memoizer for the meta tags context.
[36] Fix | Delete
*
[37] Fix | Delete
* @var Meta_Tags_Context_Memoizer
[38] Fix | Delete
*/
[39] Fix | Delete
protected $context_memoizer;
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* The indexable repository.
[43] Fix | Delete
*
[44] Fix | Delete
* @var Indexable_Repository
[45] Fix | Delete
*/
[46] Fix | Delete
private $repository;
[47] Fix | Delete
[48] Fix | Delete
/**
[49] Fix | Delete
* The pagination helper.
[50] Fix | Delete
*
[51] Fix | Delete
* @var Pagination_Helper
[52] Fix | Delete
*/
[53] Fix | Delete
protected $pagination_helper;
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* The WooCommerce helper.
[57] Fix | Delete
*
[58] Fix | Delete
* @var Woocommerce_Helper
[59] Fix | Delete
*/
[60] Fix | Delete
private $woocommerce_helper;
[61] Fix | Delete
[62] Fix | Delete
/**
[63] Fix | Delete
* Returns the conditionals based in which this loadable should be active.
[64] Fix | Delete
*
[65] Fix | Delete
* @return array
[66] Fix | Delete
*/
[67] Fix | Delete
public static function get_conditionals() {
[68] Fix | Delete
return [ WooCommerce_Conditional::class, Front_End_Conditional::class ];
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
/**
[72] Fix | Delete
* WooCommerce constructor.
[73] Fix | Delete
*
[74] Fix | Delete
* @param Options_Helper $options The options helper.
[75] Fix | Delete
* @param WPSEO_Replace_Vars $replace_vars The replace vars helper.
[76] Fix | Delete
* @param Meta_Tags_Context_Memoizer $context_memoizer The meta tags context memoizer.
[77] Fix | Delete
* @param Indexable_Repository $repository The indexable repository.
[78] Fix | Delete
* @param Pagination_Helper $pagination_helper The paginataion helper.
[79] Fix | Delete
* @param Woocommerce_Helper $woocommerce_helper The WooCommerce helper.
[80] Fix | Delete
*/
[81] Fix | Delete
public function __construct(
[82] Fix | Delete
Options_Helper $options,
[83] Fix | Delete
WPSEO_Replace_Vars $replace_vars,
[84] Fix | Delete
Meta_Tags_Context_Memoizer $context_memoizer,
[85] Fix | Delete
Indexable_Repository $repository,
[86] Fix | Delete
Pagination_Helper $pagination_helper,
[87] Fix | Delete
Woocommerce_Helper $woocommerce_helper
[88] Fix | Delete
) {
[89] Fix | Delete
$this->options = $options;
[90] Fix | Delete
$this->replace_vars = $replace_vars;
[91] Fix | Delete
$this->context_memoizer = $context_memoizer;
[92] Fix | Delete
$this->repository = $repository;
[93] Fix | Delete
$this->pagination_helper = $pagination_helper;
[94] Fix | Delete
$this->woocommerce_helper = $woocommerce_helper;
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
/**
[98] Fix | Delete
* Initializes the integration.
[99] Fix | Delete
*
[100] Fix | Delete
* This is the place to register hooks and filters.
[101] Fix | Delete
*
[102] Fix | Delete
* @return void
[103] Fix | Delete
*/
[104] Fix | Delete
public function register_hooks() {
[105] Fix | Delete
\add_filter( 'wpseo_frontend_page_type_simple_page_id', [ $this, 'get_page_id' ] );
[106] Fix | Delete
\add_filter( 'wpseo_breadcrumb_indexables', [ $this, 'add_shop_to_breadcrumbs' ] );
[107] Fix | Delete
[108] Fix | Delete
\add_filter( 'wpseo_title', [ $this, 'title' ], 10, 2 );
[109] Fix | Delete
\add_filter( 'wpseo_metadesc', [ $this, 'description' ], 10, 2 );
[110] Fix | Delete
\add_filter( 'wpseo_canonical', [ $this, 'canonical' ], 10, 2 );
[111] Fix | Delete
\add_filter( 'wpseo_adjacent_rel_url', [ $this, 'adjacent_rel_url' ], 10, 3 );
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
/**
[115] Fix | Delete
* Returns the correct canonical when WooCommerce is enabled.
[116] Fix | Delete
*
[117] Fix | Delete
* @param string $canonical The current canonical.
[118] Fix | Delete
* @param Indexable_Presentation|null $presentation The indexable presentation.
[119] Fix | Delete
*
[120] Fix | Delete
* @return string The correct canonical.
[121] Fix | Delete
*/
[122] Fix | Delete
public function canonical( $canonical, $presentation = null ) {
[123] Fix | Delete
if ( ! $this->woocommerce_helper->is_shop_page() ) {
[124] Fix | Delete
return $canonical;
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
$url = $this->get_shop_paginated_link( 'curr', $presentation );
[128] Fix | Delete
[129] Fix | Delete
if ( $url ) {
[130] Fix | Delete
return $url;
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
return $canonical;
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
/**
[137] Fix | Delete
* Returns correct adjacent pages when WooCommerce is enabled.
[138] Fix | Delete
*
[139] Fix | Delete
* @param string $link The current link.
[140] Fix | Delete
* @param string $rel Link relationship, prev or next.
[141] Fix | Delete
* @param Indexable_Presentation|null $presentation The indexable presentation.
[142] Fix | Delete
*
[143] Fix | Delete
* @return string The correct link.
[144] Fix | Delete
*/
[145] Fix | Delete
public function adjacent_rel_url( $link, $rel, $presentation = null ) {
[146] Fix | Delete
if ( ! $this->woocommerce_helper->is_shop_page() ) {
[147] Fix | Delete
return $link;
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
if ( $rel !== 'next' && $rel !== 'prev' ) {
[151] Fix | Delete
return $link;
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
$url = $this->get_shop_paginated_link( $rel, $presentation );
[155] Fix | Delete
[156] Fix | Delete
if ( $url ) {
[157] Fix | Delete
return $url;
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
return $link;
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
/**
[164] Fix | Delete
* Adds a breadcrumb for the shop page.
[165] Fix | Delete
*
[166] Fix | Delete
* @param Indexable[] $indexables The array with indexables.
[167] Fix | Delete
*
[168] Fix | Delete
* @return Indexable[] The indexables to be shown in the breadcrumbs, with the shop page added.
[169] Fix | Delete
*/
[170] Fix | Delete
public function add_shop_to_breadcrumbs( $indexables ) {
[171] Fix | Delete
$shop_page_id = $this->woocommerce_helper->get_shop_page_id();
[172] Fix | Delete
[173] Fix | Delete
if ( ! \is_int( $shop_page_id ) || $shop_page_id < 1 ) {
[174] Fix | Delete
return $indexables;
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
foreach ( $indexables as $index => $indexable ) {
[178] Fix | Delete
if ( $indexable->object_type === 'post-type-archive' && $indexable->object_sub_type === 'product' ) {
[179] Fix | Delete
$shop_page_indexable = $this->repository->find_by_id_and_type( $shop_page_id, 'post' );
[180] Fix | Delete
if ( \is_a( $shop_page_indexable, Indexable::class ) ) {
[181] Fix | Delete
$indexables[ $index ] = $shop_page_indexable;
[182] Fix | Delete
}
[183] Fix | Delete
}
[184] Fix | Delete
}
[185] Fix | Delete
[186] Fix | Delete
return $indexables;
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
/**
[190] Fix | Delete
* Returns the ID of the WooCommerce shop page when the currently opened page is the shop page.
[191] Fix | Delete
*
[192] Fix | Delete
* @param int $page_id The page id.
[193] Fix | Delete
*
[194] Fix | Delete
* @return int The Page ID of the shop.
[195] Fix | Delete
*/
[196] Fix | Delete
public function get_page_id( $page_id ) {
[197] Fix | Delete
if ( ! $this->woocommerce_helper->is_shop_page() ) {
[198] Fix | Delete
return $page_id;
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
return $this->woocommerce_helper->get_shop_page_id();
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
/**
[205] Fix | Delete
* Handles the title.
[206] Fix | Delete
*
[207] Fix | Delete
* @param string $title The title.
[208] Fix | Delete
* @param Indexable_Presentation|null $presentation The indexable presentation.
[209] Fix | Delete
*
[210] Fix | Delete
* @return string The title to use.
[211] Fix | Delete
*/
[212] Fix | Delete
public function title( $title, $presentation = null ) {
[213] Fix | Delete
$presentation = $this->ensure_presentation( $presentation );
[214] Fix | Delete
[215] Fix | Delete
if ( $presentation->model->title ) {
[216] Fix | Delete
return $title;
[217] Fix | Delete
}
[218] Fix | Delete
[219] Fix | Delete
if ( ! $this->woocommerce_helper->is_shop_page() ) {
[220] Fix | Delete
return $title;
[221] Fix | Delete
}
[222] Fix | Delete
[223] Fix | Delete
if ( ! \is_archive() ) {
[224] Fix | Delete
return $title;
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
$shop_page_id = $this->woocommerce_helper->get_shop_page_id();
[228] Fix | Delete
if ( $shop_page_id < 1 ) {
[229] Fix | Delete
return $title;
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
$product_template_title = $this->get_product_template( 'title-product', $shop_page_id );
[233] Fix | Delete
if ( $product_template_title ) {
[234] Fix | Delete
return $product_template_title;
[235] Fix | Delete
}
[236] Fix | Delete
[237] Fix | Delete
return $title;
[238] Fix | Delete
}
[239] Fix | Delete
[240] Fix | Delete
/**
[241] Fix | Delete
* Handles the meta description.
[242] Fix | Delete
*
[243] Fix | Delete
* @param string $description The title.
[244] Fix | Delete
* @param Indexable_Presentation|null $presentation The indexable presentation.
[245] Fix | Delete
*
[246] Fix | Delete
* @return string The description to use.
[247] Fix | Delete
*/
[248] Fix | Delete
public function description( $description, $presentation = null ) {
[249] Fix | Delete
$presentation = $this->ensure_presentation( $presentation );
[250] Fix | Delete
[251] Fix | Delete
if ( $presentation->model->description ) {
[252] Fix | Delete
return $description;
[253] Fix | Delete
}
[254] Fix | Delete
[255] Fix | Delete
if ( ! $this->woocommerce_helper->is_shop_page() ) {
[256] Fix | Delete
return $description;
[257] Fix | Delete
}
[258] Fix | Delete
[259] Fix | Delete
if ( ! \is_archive() ) {
[260] Fix | Delete
return $description;
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
$shop_page_id = $this->woocommerce_helper->get_shop_page_id();
[264] Fix | Delete
if ( $shop_page_id < 1 ) {
[265] Fix | Delete
return $description;
[266] Fix | Delete
}
[267] Fix | Delete
[268] Fix | Delete
$product_template_description = $this->get_product_template( 'metadesc-product', $shop_page_id );
[269] Fix | Delete
if ( $product_template_description ) {
[270] Fix | Delete
return $product_template_description;
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
return $description;
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
/**
[277] Fix | Delete
* Uses template for the given option name and replace the replacement variables on it.
[278] Fix | Delete
*
[279] Fix | Delete
* @param string $option_name The option name to get the template for.
[280] Fix | Delete
* @param string $shop_page_id The page id to retrieve template for.
[281] Fix | Delete
*
[282] Fix | Delete
* @return string The rendered value.
[283] Fix | Delete
*/
[284] Fix | Delete
protected function get_product_template( $option_name, $shop_page_id ) {
[285] Fix | Delete
$template = $this->options->get( $option_name );
[286] Fix | Delete
$page = \get_post( $shop_page_id );
[287] Fix | Delete
[288] Fix | Delete
return $this->replace_vars->replace( $template, $page );
[289] Fix | Delete
}
[290] Fix | Delete
[291] Fix | Delete
/**
[292] Fix | Delete
* Get paginated link for shop page.
[293] Fix | Delete
*
[294] Fix | Delete
* @param string $rel Link relationship, prev or next or curr.
[295] Fix | Delete
* @param Indexable_Presentation|null $presentation The indexable presentation.
[296] Fix | Delete
*
[297] Fix | Delete
* @return string|null The link.
[298] Fix | Delete
*/
[299] Fix | Delete
protected function get_shop_paginated_link( $rel, $presentation = null ) {
[300] Fix | Delete
$presentation = $this->ensure_presentation( $presentation );
[301] Fix | Delete
[302] Fix | Delete
$permalink = $presentation->permalink;
[303] Fix | Delete
if ( ! $permalink ) {
[304] Fix | Delete
return null;
[305] Fix | Delete
}
[306] Fix | Delete
[307] Fix | Delete
$current_page = \max( 1, $this->pagination_helper->get_current_archive_page_number() );
[308] Fix | Delete
[309] Fix | Delete
if ( $rel === 'curr' && $current_page === 1 ) {
[310] Fix | Delete
return $permalink;
[311] Fix | Delete
}
[312] Fix | Delete
[313] Fix | Delete
if ( $rel === 'curr' && $current_page > 1 ) {
[314] Fix | Delete
return $this->pagination_helper->get_paginated_url( $permalink, $current_page );
[315] Fix | Delete
}
[316] Fix | Delete
[317] Fix | Delete
if ( $rel === 'prev' && $current_page === 2 ) {
[318] Fix | Delete
return $permalink;
[319] Fix | Delete
}
[320] Fix | Delete
[321] Fix | Delete
if ( $rel === 'prev' && $current_page > 2 ) {
[322] Fix | Delete
return $this->pagination_helper->get_paginated_url( $permalink, ( $current_page - 1 ) );
[323] Fix | Delete
}
[324] Fix | Delete
[325] Fix | Delete
if ( $rel === 'next' && $current_page < $this->pagination_helper->get_number_of_archive_pages() ) {
[326] Fix | Delete
return $this->pagination_helper->get_paginated_url( $permalink, ( $current_page + 1 ) );
[327] Fix | Delete
}
[328] Fix | Delete
[329] Fix | Delete
return null;
[330] Fix | Delete
}
[331] Fix | Delete
[332] Fix | Delete
/**
[333] Fix | Delete
* Ensures a presentation is available.
[334] Fix | Delete
*
[335] Fix | Delete
* @param Indexable_Presentation $presentation The indexable presentation.
[336] Fix | Delete
*
[337] Fix | Delete
* @return Indexable_Presentation The presentation, taken from the current page if the input was invalid.
[338] Fix | Delete
*/
[339] Fix | Delete
protected function ensure_presentation( $presentation ) {
[340] Fix | Delete
if ( \is_a( $presentation, Indexable_Presentation::class ) ) {
[341] Fix | Delete
return $presentation;
[342] Fix | Delete
}
[343] Fix | Delete
[344] Fix | Delete
$context = $this->context_memoizer->for_current_page();
[345] Fix | Delete
[346] Fix | Delete
return $context->presentation;
[347] Fix | Delete
}
[348] Fix | Delete
}
[349] Fix | Delete
[350] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function