WP_AI_Client_Cache::ttl_to_seconds │ private │ WP 7.0.0

Converts a PSR-16 TTL value to seconds for WordPress cache functions.

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

Хуков нет.

Возвращает

int. The TTL in seconds, or 0 for no expiration.

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

// private - только в коде основоного (родительского) класса
$result = $this->ttl_to_seconds( $ttl ): int;
$ttl(null|int|DateInterval) (обязательный)
The TTL value.

Список изменений

С версии 7.0.0 Введена.

Код WP_AI_Client_Cache::ttl_to_seconds() WP 7.1.4

private function ttl_to_seconds( $ttl ): int {
	if ( null === $ttl ) {
		return 0;
	}

	if ( $ttl instanceof DateInterval ) {
		$now = new DateTime();
		$end = ( clone $now )->add( $ttl );

		return $end->getTimestamp() - $now->getTimestamp();
	}

	return max( 0, (int) $ttl );
}