Server IP : 162.0.217.223 / Your IP : 216.73.216.168 Web Server : LiteSpeed System : Linux premium269.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : mypckeys ( 1539) PHP Version : 8.1.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/mypckeys/www/wp-content/themes/woodmart/inc/modules/layouts/admin/ |
Upload File : |
<?php /** * Layout conditions cache class file. * * @package Woodmart */ namespace XTS\Modules\Layouts; use WP_Query; /** * Layout conditions cache class. */ class Conditions_Cache { /** * Option name. * * @var string */ private $option_name = 'wd_layouts_conditions'; /** * Post type. * * @var string */ private $post_type = 'woodmart_layout'; /** * Conditions meta key. * * @var string */ private $conditions_meta_key = 'wd_layout_conditions'; /** * Type meta key. * * @var string */ private $type_meta_key = 'wd_layout_type'; /** * Conditions. * * @var string */ private $conditions = array(); /** * Constructor. */ public function __construct() { $this->refresh(); } /** * Add. * * @param string $type Type. * @param array $conditions Conditions. * @param int $post_id Post id. * * @return $this */ public function add( $type, $conditions, $post_id ) { if ( $type ) { if ( ! isset( $this->conditions[ $type ] ) ) { $this->conditions[ $type ] = []; } $this->conditions[ $type ][ $post_id ] = $conditions; } return $this; } /** * Remove. * * @param int $post_id Post id. * * @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; } /** * Save. */ public function save() { return update_option( $this->option_name, $this->conditions ); } /** * Refresh. */ public function refresh() { $this->conditions = get_option( $this->option_name, array() ); } /** * Clear. */ public function clear() { $this->conditions = array(); } /** * Get. * * @param string $type Type. * * @return array */ public function get( $type ) { if ( isset( $this->conditions[ $type ] ) ) { return $this->conditions[ $type ]; } return array(); } /** * Regenerate. */ public function regenerate() { $this->clear(); $query = new WP_Query( array( 'posts_per_page' => - 1, 'post_type' => $this->post_type, 'fields' => 'ids', 'meta_key' => $this->conditions_meta_key, // phpcs:ignore 'suppress_filters' => true, ) ); foreach ( $query->posts as $post_id ) { $conditions = get_post_meta( $post_id, $this->conditions_meta_key, true ); $type = get_post_meta( $post_id, $this->type_meta_key, true ); $this->add( $type, $conditions, $post_id ); } $this->save(); return $this; } }