HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: /var/www/html/insiders/wp-load/wp-content/plugins/breadly/lib/style-variations.php
<?php

/*//////////////////////////////////////
// Automatically load CSS and PHP files for the active theme variation
//////////////////////////////////////*/

if ( ! class_exists( 'GTM_Style_Variations' ) ) {
	class GTM_Style_Variations {
		private static $instance = null;

		public $variation = '';
		public $handle    = 'gutenmate-style-variations';

		public static function get_instance() {
			if ( null === self::$instance ) {
				self::$instance = new self();
			}

			return self::$instance;
		}

		public function __construct() {
			add_action( 'wp_theme_json_data_user', [$this, 'filter_theme_json'], 99 );
		}

		public function filter_theme_json( $theme_json ) {
			$data      = $theme_json->get_data();
			$variation = $data['settings']['custom']['variation'] ?? false;

			// Process only variation and the variation style is not enqueued
			if ( $variation && ! wp_style_is( $this->handle ) ) {
				$this->variation = sanitize_file_name( $variation );
				add_action( 'init', [$this, 'init'], 11 );
			}

			return $theme_json;
		}

		public function init() {
			$css_file = "styles/{$this->variation}.css";
			if ( file_exists( get_theme_file_path( $css_file ) ) ) {
				add_editor_style( $css_file );

				if ( ! is_admin() ) {
					wp_enqueue_style( $this->handle, get_theme_file_uri( $css_file ), [], GTM_VERSION );
				}
			}

			$php_file = get_theme_file_path( "styles/{$this->variation}.php" );
			if ( file_exists( $php_file ) ) {
				include_once trim( $php_file ); // Sanitized. It's safe.
			}
		}
	}
}

GTM_Style_Variations::get_instance();