Skip to content

Commit

Permalink
Add AMP v0.js during post-processing instead of wp_head action
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Aug 22, 2019
1 parent c1f14c1 commit 5fff2fa
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
3 changes: 0 additions & 3 deletions includes/class-amp-story-post-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,6 @@ function() {
add_action(
'amp_story_head',
function() {
// @todo Temporary until sanitizer automatically supplies runtime.
wp_scripts()->do_items( [ 'amp-runtime' ] ); // @todo Duplicate with AMP_Theme_Support::enqueue_assets().

wp_styles()->do_items();
}
);
Expand Down
8 changes: 5 additions & 3 deletions includes/class-amp-theme-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -1646,8 +1646,12 @@ public static function ensure_required_markup( DOMDocument $dom, $script_handles

// "5. Load the AMP runtime."
if ( isset( $amp_scripts['amp-runtime'] ) ) {
// @todo What if not present?
$ordered_scripts['amp-runtime'] = $amp_scripts['amp-runtime'];
} else {
$script = $dom->createElement( 'script' );
$script->setAttribute( 'async', '' );
$script->setAttribute( 'src', $runtime_src );
$ordered_scripts['amp-runtime'] = $script;
}

/*
Expand Down Expand Up @@ -2337,8 +2341,6 @@ public static function whitelist_layout_in_wp_kses_allowed_html( $context ) {
* @return void
*/
public static function enqueue_assets() {
wp_enqueue_script( 'amp-runtime' );

// Enqueue default styles expected by sanitizer.
wp_enqueue_style( 'amp-default', amp_get_asset_url( 'css/amp-default.css' ), [], AMP__VERSION );
wp_styles()->add_data( 'amp-default', 'rtl', 'replace' );
Expand Down
3 changes: 0 additions & 3 deletions tests/php/test-class-amp-theme-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -1903,12 +1903,9 @@ static function( $url ) use ( &$redirects ) {
* @covers AMP_Theme_Support::enqueue_assets()
*/
public function test_enqueue_assets() {
$script_slug = 'amp-runtime';
$style_slug = 'amp-default';
wp_dequeue_script( $script_slug );
wp_dequeue_style( $style_slug );
AMP_Theme_Support::enqueue_assets();
$this->assertContains( $script_slug, wp_scripts()->queue );
$this->assertContains( $style_slug, wp_styles()->queue );
}

Expand Down

0 comments on commit 5fff2fa

Please sign in to comment.