HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux aritmodecarnaval.es 5.15.0-79-generic #86-Ubuntu SMP Mon Jul 10 16:07:21 UTC 2023 x86_64
User: www-data (33)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /home/www/aritmodecarnaval/wp-content/plugins/youtube-embed/includes/caching.php
<?php
/**
 * Transient Functions
 *
 * Functions to save cache data and housekeep it
 *
 * @package youtube-embed
 */

/**
 * Save a transient
 *
 * Generate a transient name and save it
 *
 * @param  string $name     The name of the transient.
 * @param  string $data     The data to store.
 * @param  string $cache    How long to cache the data for.
 * @param  string $hash     Whether to hash the name (true or false).
 * @return string           True or false, indicating success.
 */
function ye_set_transient( $name, $data, $cache, $hash = false ) {

	if ( $hash ) {
		$name = hash( 'ripemd128', $name );
	}

	$result = set_transient( 'youtubeembed_' . $name, $data, $cache );

	return $result;
}

/**
 * Get a transient
 *
 * Generate a transient name and fetch it
 *
 * @param  string $name   The name of the transient.
 * @param  string $hash   Whether to hash the name (true or false).
 * @return string         The transient result or false, if failed.
 */
function ye_get_transient( $name, $hash = false ) {

	if ( $hash ) {
		$name = hash( 'ripemd128', $name );
	}

	$result = get_transient( 'youtubeembed_' . $name );

	return $result;
}

/**
 * Set up the scheduler
 *
 * Set up the scheduler for midnight to run the housekeeping
 */
function ye_set_up_scheduler() {

	if ( ! wp_next_scheduled( 'housekeep_ye_transients' ) ) {
		wp_schedule_event( strtotime( '00:00' ), 'daily', 'housekeep_ye_transients' );
	}
}

add_action( 'init', 'ye_set_up_scheduler' );

/**
 * Housekeep the transients
 *
 * Remove any expired transients, relevant to this plugin
 */
function ye_housekeep_transients() {

	$sql = "
		DELETE
			a, b
		FROM
			{$wpdb->options} a, {$wpdb->options} b
		WHERE
			a.option_name LIKE '%_transient_youtubeembed_%' AND
			a.option_name NOT LIKE '%_transient_timeout_youtubeembed_%' AND
			b.option_name = CONCAT(
				'_transient_timeout_',
				SUBSTRING(
					a.option_name,
					CHAR_LENGTH('_transient_') + 1
				)
			)
		AND b.option_value < UNIX_TIMESTAMP()
	";

	$wpdb->query( $sql );
}

add_action( 'ye_housekeep_transients', 'ye_clean_transients' );