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/gutenmate/lib/amp/amp.php
<?php

include_once __DIR__ . '/class-gtm-amp.php';

GTM_AMP::get_instance();

function gtm_is_amp_request() {
	// Support AMP official plugin or detect it from query args
	return function_exists( 'amp_is_request' ) ? amp_is_request() : ! empty( $_GET['amp'] );
}

function gtm_has_amp_plugin() {
	// Check for AMP official plugin
	return defined( 'AMP__VERSION' );
}

/**
 * Enqueue AMP scripts
 * 
 * This still required since any amp blocks can be run on regular page
 *
 * @param string $script handle or raw script tag
 * @return void
 */
function gtm_use_amp_script( $script ) {
	if ( gtm_startsWith( $script, 'amp-' ) ) {
		if ( $script !== 'amp-runtime' ) {
			wp_enqueue_script( 'amp-runtime' );
		}

		if ( wp_script_is( $script, 'registered' ) ) {
			wp_enqueue_script( $script );
		}

	} else if ( stripos( $script, '<script' ) !== false ) {
		if ( gtm_has_amp_plugin() ) {
			if ( preg_match( '|custom-element=[\'"]([^\'"]+)[\'"]|', $script, $matches ) ) {
				if ( gtm_startsWith( $matches[1], 'amp-' ) ) {
					wp_enqueue_script( 'amp-runtime' );
					wp_enqueue_script( $matches[1] );
				}
			}
		} else {
			// Extract only amp script to prevent unwanted scripts
			if ( preg_match_all( '|https:\/\/cdn.ampproject.org\/v0\/(.+)-[0-9].+\.js|', $script, $matches, PREG_SET_ORDER ) ) {
				foreach ( $matches as $match ) {
					$scripts[$match[0]] = $match[1];
				}

				$src    = $match[0];
				$handle = $match[1];

				if ( ! wp_script_is( $handle, 'registered' ) ) {
					wp_register_script( $handle, $src );
				}

				wp_enqueue_script( $handle );
			}
		}
	}
}