Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Site Scan & AMP: Include toolbar scripts for Site Scan have data-ampdevmode on AMP requests #17034

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion modules/scan/class-admin-bar-notice.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ private function init_hooks() {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_toolbar_script' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_toolbar_script' ) );
add_action( 'admin_bar_menu', array( $this, 'add_threats_to_toolbar' ), 999 );

// Inject the data-ampdevmode attribute into the inline <script> output via wp_localize_script(). To revisit after https://github.com/ampproject/amp-wp/issues/4598.
add_filter(
'amp_dev_mode_element_xpaths',
static function ( $expressions ) {
$expressions[] = '//script[ contains( text(), "Jetpack_Scan" ) ]';
return $expressions;
}
);
}

/**
Expand Down Expand Up @@ -90,7 +99,7 @@ public function enqueue_toolbar_script() {
}

// We don't know about threats in the cache lets load the JS that fetches the info and updates the admin bar.
Assets::enqueue_async_script( self::SCRIPT_NAME, '_inc/build/scan/admin-bar-notice.min.js', 'modules/scan/admin-bar-notice.js', array(), self::SCRIPT_VERSION, true );
Assets::enqueue_async_script( self::SCRIPT_NAME, '_inc/build/scan/admin-bar-notice.min.js', 'modules/scan/admin-bar-notice.js', array( 'admin-bar' ), self::SCRIPT_VERSION, true );

$script_data = array(
'nonce' => wp_create_nonce( 'wp_rest' ),
Expand Down