HEX
Server: LiteSpeed
System: Linux s166.bitcommand.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
User: h340499 (1922)
PHP: 8.2.16
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/h340499/public_html/wp-content/plugins/thim-elementor-kit/inc/modules/class-cache.php
<?php

namespace Thim_EL_Kit\Modules;

use Thim_EL_Kit\SingletonTrait;

class Cache {

	use SingletonTrait;

	public $conditions = array();

	const OPTION_NAME = 'thim_ekits_option_conditions';

	const CONDITION_META_KEY = 'thim_ekits_conditions';

	public function __construct() {
		$this->refresh();
	}

	public function save() {
		return update_option(
			apply_filters( 'thim_ekit/cache/thim_ekits_option_conditions', self::OPTION_NAME ),
			$this->conditions
		);
	}

	public function refresh() {
		$this->conditions = get_option(
			apply_filters( 'thim_ekit/cache/thim_ekits_option_conditions', self::OPTION_NAME ),
			array()
		);
	}

	public function clear() {
		$this->conditions = array();
	}

	public function get( $type ) {
		return isset( $this->conditions[ $type ] ) ? $this->conditions[ $type ] : array();
	}

	public function add( $type, $conditions, $post_id ) {
		if ( $type ) {
			if ( ! isset( $this->conditions[ $type ] ) ) {
				$this->conditions[ $type ] = array();
			}
			$this->conditions[ $type ][ $post_id ] = $conditions;
		}

		return $this;
	}

	public function remove( $post_id ) {
		$post_id = absint( $post_id );

		foreach ( $this->conditions as $type => $templates ) {
			foreach ( $templates as $id => $template ) {
				if ( $post_id === $id ) {
					unset( $this->conditions[ $type ][ $id ] );
				}
			}
		}

		return $this;
	}

	public function regenerate() {
		$this->clear();

		$query = new \WP_Query(
			array(
				'posts_per_page' => - 1,
				'post_type'      => \Thim_EL_Kit\Custom_Post_Type::CPT,
				'fields'         => 'ids',
				'meta_key'       => self::CONDITION_META_KEY,
				// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
			)
		);

		foreach ( $query->posts as $post_id ) {
			$conditions = get_post_meta( $post_id, self::CONDITION_META_KEY, true );
			$type       = get_post_meta( $post_id, 'thim_elementor_type', true );

			$this->add( $type, $conditions, $post_id );
		}

		$this->save();

		return $this;
	}
}