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/introduc.../infrastr...
File: introductions-seen-repository.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Introductions\Infrastructure;
[2] Fix | Delete
[3] Fix | Delete
use Yoast\WP\SEO\Helpers\User_Helper;
[4] Fix | Delete
use Yoast\WP\SEO\Introductions\Domain\Invalid_User_Id_Exception;
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Stores and retrieves whether the user has seen certain introductions.
[8] Fix | Delete
*/
[9] Fix | Delete
class Introductions_Seen_Repository {
[10] Fix | Delete
[11] Fix | Delete
public const USER_META_KEY = '_yoast_wpseo_introductions';
[12] Fix | Delete
[13] Fix | Delete
public const DEFAULT_VALUE = [];
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* Holds the User_Helper instance.
[17] Fix | Delete
*
[18] Fix | Delete
* @var User_Helper
[19] Fix | Delete
*/
[20] Fix | Delete
private $user_helper;
[21] Fix | Delete
[22] Fix | Delete
/**
[23] Fix | Delete
* Constructs the class.
[24] Fix | Delete
*
[25] Fix | Delete
* @param User_Helper $user_helper The User_Helper.
[26] Fix | Delete
*/
[27] Fix | Delete
public function __construct( User_Helper $user_helper ) {
[28] Fix | Delete
$this->user_helper = $user_helper;
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* Retrieves the introductions.
[33] Fix | Delete
*
[34] Fix | Delete
* @param int $user_id User ID.
[35] Fix | Delete
*
[36] Fix | Delete
* @return array The introductions.
[37] Fix | Delete
*
[38] Fix | Delete
* @throws Invalid_User_Id_Exception If an invalid user ID is supplied.
[39] Fix | Delete
*/
[40] Fix | Delete
public function get_all_introductions( $user_id ): array {
[41] Fix | Delete
$seen_introductions = $this->user_helper->get_meta( $user_id, self::USER_META_KEY, true );
[42] Fix | Delete
if ( $seen_introductions === false ) {
[43] Fix | Delete
throw new Invalid_User_Id_Exception();
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
if ( \is_array( $seen_introductions ) ) {
[47] Fix | Delete
return $seen_introductions;
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
/**
[51] Fix | Delete
* Why could $value be invalid?
[52] Fix | Delete
* - When the database row does not exist yet, $value can be an empty string.
[53] Fix | Delete
* - Faulty data was stored?
[54] Fix | Delete
*/
[55] Fix | Delete
return self::DEFAULT_VALUE;
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
/**
[59] Fix | Delete
* Sets the introductions.
[60] Fix | Delete
*
[61] Fix | Delete
* @param int $user_id The user ID.
[62] Fix | Delete
* @param array $introductions The introductions.
[63] Fix | Delete
*
[64] Fix | Delete
* @return bool True on successful update, false on failure or if the value passed to the function is the same as
[65] Fix | Delete
* the one that is already in the database.
[66] Fix | Delete
*/
[67] Fix | Delete
public function set_all_introductions( $user_id, array $introductions ): bool {
[68] Fix | Delete
return $this->user_helper->update_meta( $user_id, self::USER_META_KEY, $introductions ) !== false;
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
/**
[72] Fix | Delete
* Retrieves whether an introduction is seen.
[73] Fix | Delete
*
[74] Fix | Delete
* @param int $user_id User ID.
[75] Fix | Delete
* @param string $introduction_id The introduction ID.
[76] Fix | Delete
*
[77] Fix | Delete
* @return bool Whether the introduction is seen.
[78] Fix | Delete
*
[79] Fix | Delete
* @throws Invalid_User_Id_Exception If an invalid user ID is supplied.
[80] Fix | Delete
*/
[81] Fix | Delete
public function is_introduction_seen( $user_id, string $introduction_id ): bool {
[82] Fix | Delete
$introductions = $this->get_all_introductions( $user_id );
[83] Fix | Delete
[84] Fix | Delete
if ( \array_key_exists( $introduction_id, $introductions ) ) {
[85] Fix | Delete
return (bool) $introductions[ $introduction_id ];
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
return false;
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Sets the introduction as seen.
[93] Fix | Delete
*
[94] Fix | Delete
* @param int $user_id The user ID.
[95] Fix | Delete
* @param string $introduction_id The introduction ID.
[96] Fix | Delete
* @param bool $is_seen Whether the introduction is seen. Defaults to true.
[97] Fix | Delete
*
[98] Fix | Delete
* @return bool False on failure. Not having to update is a success.
[99] Fix | Delete
*
[100] Fix | Delete
* @throws Invalid_User_Id_Exception If an invalid user ID is supplied.
[101] Fix | Delete
*/
[102] Fix | Delete
public function set_introduction( $user_id, string $introduction_id, bool $is_seen = true ): bool {
[103] Fix | Delete
$introductions = $this->get_all_introductions( $user_id );
[104] Fix | Delete
[105] Fix | Delete
// Check if the wanted value is already set.
[106] Fix | Delete
if ( \array_key_exists( $introduction_id, $introductions ) && $introductions[ $introduction_id ] === $is_seen ) {
[107] Fix | Delete
return true;
[108] Fix | Delete
}
[109] Fix | Delete
$introductions[ $introduction_id ] = $is_seen;
[110] Fix | Delete
[111] Fix | Delete
return $this->set_all_introductions( $user_id, $introductions );
[112] Fix | Delete
}
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function