get( 'amp_component_scripts', array() ); foreach ( $scripts as $element => $script ) : ?> get( 'font_urls', array() ); foreach( $font_urls as $slug => $url ) : ?> get( 'metadata' ); if ( empty( $metadata ) ) { return; } ?> get( 'post_amp_styles' ); if ( ! empty( $styles ) ) { echo '/* Inline styles */' . PHP_EOL; foreach ( $styles as $selector => $declarations ) { $declarations = implode( ";", $declarations ) . ";"; printf( '%1$s{%2$s}', $selector, $declarations ); } } } add_action( 'amp_post_template_data', 'amp_post_template_add_analytics_script' ); function amp_post_template_add_analytics_script( $data ) { if ( ! empty( $data['amp_analytics'] ) ) { $data['amp_component_scripts']['amp-analytics'] = 'https://cdn.ampproject.org/v0/amp-analytics-0.1.js'; } return $data; } add_action( 'amp_post_template_footer', 'amp_post_template_add_analytics_data' ); function amp_post_template_add_analytics_data( $amp_template ) { $analytics_entries = $amp_template->get( 'amp_analytics' ); if ( empty( $analytics_entries ) ) { return; } foreach ( $analytics_entries as $id => $analytics_entry ) { if ( ! isset( $analytics_entry['type'], $analytics_entry['attributes'], $analytics_entry['config_data'] ) ) { _doing_it_wrong( __FUNCTION__, sprintf( __( 'Analytics entry for %s is missing one of the following keys: `type`, `attributes`, or `config_data` (array keys: %s)', 'amp' ), esc_html( $id ), esc_html( implode( ', ', array_keys( $analytics_entry ) ) ) ), '0.3.2' ); continue; } $script_element = AMP_HTML_Utils::build_tag( 'script', array( 'type' => 'application/json', ), json_encode( $analytics_entry['config_data'] ) ); $amp_analytics_attr = array_merge( array( 'id' => $id, 'type' => $analytics_entry['type'], ), $analytics_entry['attributes'] ); echo AMP_HTML_Utils::build_tag( 'amp-analytics', $amp_analytics_attr, $script_element ); } }