Skip to content

Commit

Permalink
Use wp_get_inline_script_tag for Gist embed (#2323)
Browse files Browse the repository at this point in the history
* Utilize wp_get_inline_script_tag for gist embed

* Add missing noscript opening tag

* Add expected linebreaks in test assertion
  • Loading branch information
jrtashjian committed Mar 14, 2022
1 parent 70b60c1 commit 0beb43f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .dev/tests/phpunit/src/blocks/gist/test-index.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function test_coblocks_block_gist_handler_returns_valid_embed() {

$this->assertEquals(
coblocks_block_gist_handler( array( $gist_url, $gist_path ) ),
'<script src="https://gist.github.com/' . $gist_path . '.js"></script><noscript><a href="' . $gist_url . '">View this gist on GitHub</a></noscript>'
"<script src=\"https://gist.github.com/${gist_path}.js\">\n\n</script>\n<noscript><a href=\"${gist_url}\">View this gist on GitHub</a></noscript>"
);
}

Expand Down
5 changes: 2 additions & 3 deletions src/blocks/gist/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ function( $file ) {
}

return sprintf(
// phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript
'<script src="https://gist.github.com/%1$s"></script><noscript><a href="%2$s">%3$s</a></noscript>',
esc_attr( $script_src ),
'%1$s<noscript><a href="%2$s">%3$s</a></noscript>',
wp_get_inline_script_tag( null, array( 'src' => esc_url( 'https://gist.github.com/' . $script_src ) ) ),
esc_url( $gist_url ),
esc_html( __( 'View this gist on GitHub', 'coblocks' ) )
);
Expand Down

0 comments on commit 0beb43f

Please sign in to comment.