Yoast\WP\SEO\Introductions\Application

Delayed_Premium_Upsell::is_last_introduction_seen_older_than_a_week │ private │ Yoast 1.0

Checks if the last introduction seen is older than a week.

Метод класса: Delayed_Premium_Upsell{}

Хуков нет.

Возвращает

bool. True if the last introduction seen is older than a week, false otherwise.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->is_last_introduction_seen_older_than_a_week(): bool;

Код Delayed_Premium_Upsell::is_last_introduction_seen_older_than_a_week() Yoast 28.9

private function is_last_introduction_seen_older_than_a_week(): bool {
	$seen_introductions = $this->introductions_seen_repository->get_all_introductions( \get_current_user_id() );
	// No other introduction has been seen.
	if ( empty( $seen_introductions ) ) {
		return true;
	}

	$old_format_introductions = \array_filter(
		$seen_introductions,
		static function ( $item ) {
			return \is_bool( $item );
		},
	);

	if ( ! empty( $old_format_introductions ) ) {
		// There are introductions in the old format, so we cannot determine when they were seen.
		// To be safe, we assume the user has seen an introduction recently.
		return false;
	}

	// Find the most recent introduction seen.
	$most_recent_introduction = \array_reduce(
		$seen_introductions,
		static function ( $carry, $item ) {
			if ( $carry === null || $item['seen_on'] > $carry['seen_on'] ) {
				return $item;
			}
			return $carry;
		},
	);

	// If the most recent introduction seen is older than a week, return true.
	if ( ( \time() - $most_recent_introduction['seen_on'] ) >= ( 7 * \DAY_IN_SECONDS ) ) {
		return true;
	}

	return false;
}