diff --git a/amp.php b/amp.php
index c357adb6409..b773c77e7a7 100644
--- a/amp.php
+++ b/amp.php
@@ -150,12 +150,13 @@ function amp_load_classes() {
}
function amp_add_frontend_actions() {
- AMP_Frontend_Actions::register_hooks();
+ require_once AMP__DIR__ . '/includes/amp-frontend-actions.php';
}
function amp_add_post_template_actions() {
- AMP_Paired_Post_Actions::register_hooks();
- require_once( AMP__DIR__ . '/includes/amp-post-template-functions.php' );
+ require_once AMP__DIR__ . '/includes/amp-post-template-actions.php';
+ require_once AMP__DIR__ . '/includes/amp-post-template-functions.php';
+ amp_post_template_init_hooks();
}
function amp_prepare_render() {
diff --git a/includes/actions/class-amp-actions.php b/includes/actions/class-amp-actions.php
deleted file mode 100644
index 4a95034e66d..00000000000
--- a/includes/actions/class-amp-actions.php
+++ /dev/null
@@ -1,20 +0,0 @@
-', esc_url( $amp_url ) );
- }
-}
diff --git a/includes/actions/class-amp-paired-post-actions.php b/includes/actions/class-amp-paired-post-actions.php
deleted file mode 100644
index a544ac878f6..00000000000
--- a/includes/actions/class-amp-paired-post-actions.php
+++ /dev/null
@@ -1,178 +0,0 @@
-
-
get( 'document_title' ) ); ?>
-
-
- get( 'amp_component_scripts', array() );
- foreach ( $scripts as $element => $script ) :
- $custom_type = ( 'amp-mustache' === $element ) ? 'template' : 'element';
- ?>
-
-
-
- get( 'font_urls', array() );
- ?>
- $url ) : ?>
-
-
-
-
- get( 'metadata' );
- if ( empty( $metadata ) ) {
- return;
- }
- ?>
-
- get( 'post_amp_styles' );
- if ( ! empty( $styles ) ) {
- echo '/* Inline styles */' . PHP_EOL; // WPCS: XSS OK.
- foreach ( $styles as $selector => $declarations ) {
- $declarations = implode( ';', $declarations ) . ';';
- printf( '%1$s{%2$s}', $selector, $declarations ); // WPCS: XSS OK.
- }
- }
- }
-
- /**
- * Add analytics scripts.
- *
- * @param array $data Data.
- * @return array Data.
- */
- public static function add_analytics_scripts( $data ) {
- if ( ! empty( $data['amp_analytics'] ) ) {
- $data['amp_component_scripts']['amp-analytics'] = 'https://cdn.ampproject.org/v0/amp-analytics-0.1.js';
- }
- return $data;
- }
-
- /**
- * Print analytics data.
- *
- * @param AMP_Post_Template $amp_template Template.
- */
- public static function 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'] ) ) {
- /* translators: %1$s is analytics entry ID, %2$s is actual entry keys. */
- _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'Analytics entry for %1$s is missing one of the following keys: `type`, `attributes`, or `config_data` (array keys: %2$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',
- ), wp_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 ); // WPCS: XSS OK.
- }
- }
-
- /**
- * Print AMP generator metadata.
- *
- * @param AMP_Post_Template $amp_template AMP_Post_Template object.
- * @since 0.6
- */
- public static function add_generator_metadata( $amp_template ) {
- ?>
-
- ', esc_url( $amp_url ) );
+}
diff --git a/includes/amp-post-template-actions.php b/includes/amp-post-template-actions.php
new file mode 100644
index 00000000000..711e5bbe023
--- /dev/null
+++ b/includes/amp-post-template-actions.php
@@ -0,0 +1,170 @@
+
+ get( 'document_title' ) ); ?>
+
+
+ get( 'amp_component_scripts', array() );
+ foreach ( $scripts as $element => $script ) {
+ $custom_type = ( 'amp-mustache' === $element ) ? 'template' : 'element';
+ printf(
+ '', // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript
+ esc_attr( $custom_type ),
+ esc_attr( $element ),
+ esc_url( $script )
+ );
+ }
+ printf(
+ '', // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript
+ esc_url( $amp_template->get( 'amp_runtime_script' ) )
+ );
+}
+
+/**
+ * Print fonts.
+ *
+ * @param AMP_Post_Template $amp_template Template.
+ */
+function amp_post_template_add_fonts( $amp_template ) {
+ $font_urls = $amp_template->get( 'font_urls', array() );
+ foreach ( $font_urls as $slug => $url ) {
+ printf( '', esc_url( esc_url( $url ) ) ); // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet
+ }
+}
+
+/**
+ * Print boilerplate CSS.
+ */
+function amp_post_template_add_boilerplate_css() {
+ ?>
+
+ get( 'metadata' );
+ if ( empty( $metadata ) ) {
+ return;
+ }
+ ?>
+
+ get( 'post_amp_styles' );
+ if ( ! empty( $styles ) ) {
+ echo '/* Inline styles */' . PHP_EOL; // WPCS: XSS OK.
+ foreach ( $styles as $selector => $declarations ) {
+ $declarations = implode( ';', $declarations ) . ';';
+ printf( '%1$s{%2$s}', $selector, $declarations ); // WPCS: XSS OK.
+ }
+ }
+}
+
+/**
+ * Add analytics scripts.
+ *
+ * @param array $data Data.
+ * @return array Data.
+ */
+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;
+}
+
+/**
+ * Print analytics data.
+ *
+ * @param AMP_Post_Template $amp_template Template.
+ */
+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'] ) ) {
+ /* translators: %1$s is analytics entry ID, %2$s is actual entry keys. */
+ _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'Analytics entry for %1$s is missing one of the following keys: `type`, `attributes`, or `config_data` (array keys: %2$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',
+ ), wp_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 ); // WPCS: XSS OK.
+ }
+}
+
+/**
+ * Add generator metadata.
+ *
+ * @since 6.0
+ */
+function amp_add_generator_metadata() {
+ printf( '', esc_attr( 'AMP Plugin v' . AMP__VERSION ) );
+}
diff --git a/includes/class-amp-autoloader.php b/includes/class-amp-autoloader.php
index 082988c34a4..281126786f8 100644
--- a/includes/class-amp-autoloader.php
+++ b/includes/class-amp-autoloader.php
@@ -29,9 +29,6 @@ class AMP_Autoloader {
* @var string[]
*/
private static $_classmap = array(
- 'AMP_Actions' => 'includes/actions/class-amp-actions',
- 'AMP_Frontend_Actions' => 'includes/actions/class-amp-frontend-actions',
- 'AMP_Paired_Post_Actions' => 'includes/actions/class-amp-paired-post-actions',
'AMP_Template_Customizer' => 'includes/admin/class-amp-customizer',
'AMP_Post_Meta_Box' => 'includes/admin/class-amp-post-meta-box',
'AMP_Post_Type_Support' => 'includes/class-amp-post-type-support',