Skip to content

Commit

Permalink
Merge pull request #7694 from ampproject/fix/efficient-string-replace…
Browse files Browse the repository at this point in the history
…ment

Use more efficient string replacement and prevent validation errors from Interactivity API experiment
  • Loading branch information
westonruter authored Dec 18, 2023
2 parents f9c4c01 + 4248179 commit 8f79eec
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
11 changes: 11 additions & 0 deletions includes/class-amp-theme-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,17 @@ static function() {
},
0
);

// Prevent Interactivity API scripts from being enqueued.
// TODO: This will need to be updated once Interactivity API is merged from Gutenberg into core.
remove_action( 'wp_enqueue_scripts', 'gutenberg_register_interactivity_module' );

if ( class_exists( 'Gutenberg_Modules' ) ) {
remove_action( 'wp_head', [ 'Gutenberg_Modules', 'print_import_map' ] );
remove_action( 'wp_head', [ 'Gutenberg_Modules', 'print_enqueued_modules' ] );
remove_action( 'wp_head', [ 'Gutenberg_Modules', 'print_module_preloads' ] );
remove_action( 'wp_footer', [ 'Gutenberg_Modules', 'print_import_map_polyfill' ], 11 );
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/DevTools/UserAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public function update_user_setting( $user_id ) {
* Provides the user's dev tools enabled setting.
*
* @param array $user Array of user data prepared for REST.
* @return null|boolean Whether tools are enabled for the user, or null if the option has not been set.
* @return bool Whether dev tools are enabled for the user.
*/
public function rest_get_dev_tools_enabled( $user ) {
return $this->is_user_enabled( $user['id'] );
Expand Down
2 changes: 1 addition & 1 deletion src/MobileRedirection.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ public function add_mobile_redirect_script() {
'isAmpDevMode' => amp_is_dev_mode(),
];

$source = preg_replace( '/\bAMP_MOBILE_REDIRECTION\b/', wp_json_encode( $exports ), $source );
$source = str_replace( 'AMP_MOBILE_REDIRECTION', wp_json_encode( $exports ), $source );

if ( function_exists( 'wp_print_inline_script_tag' ) ) {
wp_print_inline_script_tag( $source );
Expand Down
2 changes: 1 addition & 1 deletion src/OptionsRESTController.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private function get_nested_supportable_templates( $supportable_templates, $pare
* Updates AMP plugin options.
*
* @param WP_REST_Request $request Full details about the request.
* @return array|WP_Error Array on success, or error object on failure.
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function update_items( $request ) {
$params = $request->get_params();
Expand Down
2 changes: 1 addition & 1 deletion src/ReaderThemeLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public function get_reader_theme() {
*
* The theme that was active before switching to the Reader theme.
*
* @return WP_Theme|null
* @return WP_Theme WP_Theme instance.
*/
public function get_active_theme() {
return $this->active_theme;
Expand Down

0 comments on commit 8f79eec

Please sign in to comment.