HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux vm8 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: afleverb (1000)
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: //var/www/drakkar_site/wp-content/plugins/optimole-wp/inc/v2/PageProfiler/Storage/Transients.php
<?php

namespace OptimoleWP\PageProfiler\Storage;

/**
 * Class Transients
 *
 * Handles storage and retrieval of page profiler data using WordPress transients.
 * Transients provide a way to temporarily store cached data with an expiration time.
 *
 * @package OptimoleWP\PageProfiler\Storage
 */
class Transients extends Base {
	/**
	 * Prefix for all transient keys to avoid conflicts with other plugins.
	 */
	const PREFIX = '_oprof_';

	/**
	 * Default expiration time for transients (7 days in seconds).
	 */
	const EXPIRATION_TIME = 7 * DAY_IN_SECONDS;

	/**
	 * The actual expiration time to use, which can be filtered.
	 *
	 * @var int
	 */
	private $expiration_time;

	/**
	 * Constructor.
	 *
	 * Sets up the expiration time, allowing it to be modified via WordPress filters.
	 */
	public function __construct() {
		$this->expiration_time = apply_filters( 'optml_page_profiler_transient_expiration', self::EXPIRATION_TIME );
	}

	/**
	 * Generates the full transient key with prefix.
	 *
	 * @param string $key The base key to prefix.
	 * @return string The prefixed key.
	 */
	private function get_key( string $key ) {
		return self::PREFIX . $key;
	}

	/**
	 * Stores data in a transient.
	 *
	 * @param string $key The key to store the data under.
	 * @param array  $data The data to store.
	 * @return void
	 */
	public function store( string $key, array $data ) {
		set_transient( $this->get_key( $key ), $data, $this->expiration_time );
		if ( OPTML_DEBUG ) {
			error_log( 'stored: ' . $this->get_key( $key ) . '|' . print_r( $data, true ) );
		}
	}

	/**
	 * Retrieves data from a transient.
	 *
	 * @param string $key The key to retrieve data for.
	 * @return mixed The stored data or false if the transient doesn't exist or has expired.
	 */
	public function get( string $key ) {
		return get_transient( $this->get_key( $key ) );
	}

	/**
	 * Deletes a specific transient.
	 *
	 * @param string $key The key of the transient to delete.
	 * @return void
	 */
	public function delete( string $key ) {
		delete_transient( $this->get_key( $key ) );
	}

	/**
	 * Deletes all transients created by this class.
	 *
	 * @return void
	 * @todo Implement this method to clear all transients with the defined prefix.
	 */
	public function delete_all() {
		// Not implemented for now.
	}
}