Yoast\WP\SEO\Introductions\Infrastructure
Introductions_Seen_Repository::set_introduction
Sets the introduction as seen.
Метод класса: Introductions_Seen_Repository{}
Хуков нет.
Возвращает
true|false. False on failure. Not having to update is a success.
Использование
$Introductions_Seen_Repository = new Introductions_Seen_Repository(); $Introductions_Seen_Repository->set_introduction( $user_id, $introduction_id, $is_seen ): bool;
- $user_id(int) (обязательный)
- The user ID.
- $introduction_id(строка) (обязательный)
- The introduction ID.
- $is_seen(true|false)
- Whether the introduction is seen.
По умолчанию:true
Код Introductions_Seen_Repository::set_introduction() Introductions Seen Repository::set introduction Yoast 27.6
public function set_introduction( $user_id, string $introduction_id, bool $is_seen = true ): bool {
$introductions = $this->get_all_introductions( $user_id );
// Check if the wanted value is already set.
if ( \array_key_exists( $introduction_id, $introductions ) ) {
if ( \is_array( $introductions[ $introduction_id ] ) ) {
// New format with seen_on timestamp.
if ( $introductions[ $introduction_id ]['is_seen'] === $is_seen ) {
return true;
}
}
// Old format with just a boolean.
elseif ( $introductions[ $introduction_id ] === $is_seen ) {
return true;
}
}
// If not, set it.
$introductions[ $introduction_id ] = [
'is_seen' => $is_seen,
'seen_on' => ( $is_seen === true ) ? \time() : 0,
];
return $this->set_all_introductions( $user_id, $introductions );
}