Skip to content

Commit

Permalink
fix: strip script tag on amp modes fix #203
Browse files Browse the repository at this point in the history
  • Loading branch information
selul committed Jan 14, 2020
1 parent 04cad07 commit 35f59f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
19 changes: 10 additions & 9 deletions inc/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@ public function __construct() {
*/
public function register_public_actions() {
add_action( 'wp_head', array( $this, 'generator' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
add_filter( 'wp_resource_hints', array( $this, 'add_dns_prefetch' ), 10, 2 );

if ( $this->settings->use_lazyload() ) {
add_filter( 'body_class', array( $this, 'adds_body_classes' ) );
add_action( 'wp_head', array( $this, 'inline_bootstrap_script' ) );
if ( ! $this->settings->use_lazyload() ) {
return;
}
if ( Optml_Manager::should_ignore_image_tags() ) {
return;
}
add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
add_filter( 'body_class', array( $this, 'adds_body_classes' ) );
add_action( 'wp_head', array( $this, 'inline_bootstrap_script' ) );

}

/**
Expand Down Expand Up @@ -318,10 +323,6 @@ protected function get_background_lazy_css() {
* Enqueue frontend scripts.
*/
public function frontend_scripts() {

if ( ! $this->settings->use_lazyload() ) {
return;
}
$bg_css = $this->get_background_lazy_css();

wp_register_style( 'optm_lazyload_noscript_style', false );
Expand Down Expand Up @@ -418,7 +419,7 @@ public function add_dns_prefetch( $hints, $relation_type ) {
}
$hints[] = sprintf( 'https://%s', $this->settings->get_cdn_url() );

if ( $this->settings->use_lazyload() ) {
if ( ! $this->settings->use_lazyload() && ! Optml_Manager::should_ignore_image_tags() ) {
$hints[] = sprintf( 'https://%s', OPTML_JS_CDN );
}

Expand Down
4 changes: 2 additions & 2 deletions inc/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public function replace_content( $html ) {
* @return mixed
*/
public function process_images_from_content( $content ) {
if ( $this->should_ignore_image_tags() ) {
if ( self::should_ignore_image_tags() ) {
return $content;
}
$images = self::parse_images_from_html( $content );
Expand All @@ -313,7 +313,7 @@ public function process_images_from_content( $content ) {
*
* @return bool
*/
protected function should_ignore_image_tags() {
public static function should_ignore_image_tags() {
// Ignore image tags replacement in amp context as they are not available.
if ( function_exists( 'is_amp_endpoint' ) ) {
return is_amp_endpoint();
Expand Down

0 comments on commit 35f59f3

Please sign in to comment.