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/introduc.../applicat...
File: introductions-collector.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Introductions\Application;
[2] Fix | Delete
[3] Fix | Delete
use Yoast\WP\SEO\Introductions\Domain\Introduction_Interface;
[4] Fix | Delete
use Yoast\WP\SEO\Introductions\Domain\Introduction_Item;
[5] Fix | Delete
use Yoast\WP\SEO\Introductions\Domain\Introductions_Bucket;
[6] Fix | Delete
use Yoast\WP\SEO\Introductions\Infrastructure\Introductions_Seen_Repository;
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Manages the collection of introductions.
[10] Fix | Delete
*/
[11] Fix | Delete
class Introductions_Collector {
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* Holds all the introductions.
[15] Fix | Delete
*
[16] Fix | Delete
* @var Introduction_Interface[]
[17] Fix | Delete
*/
[18] Fix | Delete
private $introductions;
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* Constructs the collector.
[22] Fix | Delete
*
[23] Fix | Delete
* @param Introduction_Interface ...$introductions All the introductions.
[24] Fix | Delete
*/
[25] Fix | Delete
public function __construct( Introduction_Interface ...$introductions ) {
[26] Fix | Delete
$this->introductions = $this->add_introductions( ...$introductions );
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
/**
[30] Fix | Delete
* Gets the data for the introductions.
[31] Fix | Delete
*
[32] Fix | Delete
* @param int $user_id The user ID.
[33] Fix | Delete
*
[34] Fix | Delete
* @return array The list of introductions.
[35] Fix | Delete
*/
[36] Fix | Delete
public function get_for( $user_id ) {
[37] Fix | Delete
$bucket = new Introductions_Bucket();
[38] Fix | Delete
$metadata = $this->get_metadata( $user_id );
[39] Fix | Delete
[40] Fix | Delete
foreach ( $this->introductions as $introduction ) {
[41] Fix | Delete
if ( ! $introduction->should_show() ) {
[42] Fix | Delete
continue;
[43] Fix | Delete
}
[44] Fix | Delete
if ( $this->is_seen( $introduction->get_id(), $metadata ) ) {
[45] Fix | Delete
continue;
[46] Fix | Delete
}
[47] Fix | Delete
$bucket->add_introduction(
[48] Fix | Delete
new Introduction_Item( $introduction->get_id(), $introduction->get_priority() )
[49] Fix | Delete
);
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
return $bucket->to_array();
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* Filters introductions with the 'wpseo_introductions' filter.
[57] Fix | Delete
*
[58] Fix | Delete
* @param Introduction_Interface ...$introductions The introductions.
[59] Fix | Delete
*
[60] Fix | Delete
* @return Introduction_Interface[]
[61] Fix | Delete
*/
[62] Fix | Delete
private function add_introductions( Introduction_Interface ...$introductions ) {
[63] Fix | Delete
/**
[64] Fix | Delete
* Filter: Adds the possibility to add additional introductions to be included.
[65] Fix | Delete
*
[66] Fix | Delete
* @internal
[67] Fix | Delete
*
[68] Fix | Delete
* @param Introduction_Interface $introductions This filter expects a list of Introduction_Interface instances and
[69] Fix | Delete
* expects only Introduction_Interface implementations to be added to the list.
[70] Fix | Delete
*/
[71] Fix | Delete
$filtered_introductions = (array) \apply_filters( 'wpseo_introductions', $introductions );
[72] Fix | Delete
[73] Fix | Delete
return \array_filter(
[74] Fix | Delete
$filtered_introductions,
[75] Fix | Delete
static function ( $introduction ) {
[76] Fix | Delete
return \is_a( $introduction, Introduction_Interface::class );
[77] Fix | Delete
}
[78] Fix | Delete
);
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
/**
[82] Fix | Delete
* Retrieves the introductions metadata for the user.
[83] Fix | Delete
*
[84] Fix | Delete
* @param int $user_id The user ID.
[85] Fix | Delete
*
[86] Fix | Delete
* @return array The introductions' metadata.
[87] Fix | Delete
*/
[88] Fix | Delete
private function get_metadata( $user_id ) {
[89] Fix | Delete
$metadata = \get_user_meta( $user_id, Introductions_Seen_Repository::USER_META_KEY, true );
[90] Fix | Delete
if ( \is_array( $metadata ) ) {
[91] Fix | Delete
return $metadata;
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
return [];
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
/**
[98] Fix | Delete
* Determines whether the user has seen the introduction.
[99] Fix | Delete
*
[100] Fix | Delete
* @param string $name The name.
[101] Fix | Delete
* @param string[] $metadata The metadata.
[102] Fix | Delete
*
[103] Fix | Delete
* @return bool Whether the user has seen the introduction.
[104] Fix | Delete
*/
[105] Fix | Delete
private function is_seen( $name, $metadata ) {
[106] Fix | Delete
if ( \array_key_exists( $name, $metadata ) ) {
[107] Fix | Delete
return (bool) $metadata[ $name ];
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
return false;
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
/**
[114] Fix | Delete
* Checks if the given introduction ID is a known ID to the system.
[115] Fix | Delete
*
[116] Fix | Delete
* @param string $introduction_id The introduction ID to check.
[117] Fix | Delete
*
[118] Fix | Delete
* @return bool
[119] Fix | Delete
*/
[120] Fix | Delete
public function is_available_introduction( string $introduction_id ): bool {
[121] Fix | Delete
foreach ( $this->introductions as $introduction ) {
[122] Fix | Delete
if ( $introduction->get_id() === $introduction_id ) {
[123] Fix | Delete
return true;
[124] Fix | Delete
}
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
return false;
[128] Fix | Delete
}
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function