HEX
Server: Apache/2.4.65 (Debian)
System: Linux 88f31f35b0b8 6.1.0-38-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.147-1 (2025-08-02) x86_64
User: www-data (33)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/plugins/wp-asset-clean-up/classes/OptimiseAssets/DynamicLoadedAssets.php
<?php
/** @noinspection MultipleReturnStatementsInspection */

namespace WpAssetCleanUp\OptimiseAssets;

/**
 * Class DynamicLoadedAssets
 * @package WpAssetCleanUp
 */
class DynamicLoadedAssets
{
	/**
	 * @param $from
	 * @param $value
	 *
	 * @return bool|mixed|string
     * @noinspection NestedPositiveIfStatementsInspection
     */
	public static function getAssetContentFrom($from, $value)
	{
		$assetContent = '';

		if ($from === 'simple-custom-css') {
			/*
			 * Special Case: "Simple Custom CSS" Plugin
			 *
			 * /?sccss=1
			 *
			 * As it is (no minification or optimization), it adds extra load time to the page
			 * as the CSS is read via PHP and all the WP environment is loading
			 */
			if (! $assetContent = self::getSimpleCustomCss()) {
				return false;
			}
		}

		if ($from === 'dynamic') { // /? .php? etc.
			if (! OptimizeCommon::isSourceFromSameHost($value->src)) {
				return array();
			}

			$response = wp_remote_get(
				$value->src
				);

			if (wp_remote_retrieve_response_code($response) !== 200) {
				return false;
			}

			if (! $assetContent = wp_remote_retrieve_body($response)) {
				return false;
			}
		}

		return $assetContent;
	}

	/**
	 * "Simple Custom CSS" (better retrieval, especially for localhost and password-protected sites)
	 *
	 * @return string
	 */
	public static function getSimpleCustomCss()
	{
		$sccssOptions    = get_option('sccss_settings');
		$sccssRawContent = isset($sccssOptions['sccss-content']) ? $sccssOptions['sccss-content'] : '';
		$cssContent      = wp_kses($sccssRawContent, array('\'', '\"'));
		$cssContent      = str_replace('&gt;', '>', $cssContent);

		return trim($cssContent);
	}
}