WP_AI_Client_Cache::ttl_to_seconds( null|int|DateInterval $ttl ): int

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only by core. It is listed here for completeness.

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

Parameters

$ttlnull|int|DateIntervalrequired
The TTL value.

Return

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

Source

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 );
}

Changelog

VersionDescription
7.0.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.