Skip to content

Commit 6253cc1

Browse files
committed
Add missing JSON-encoding flags
1 parent 053717d commit 6253cc1

File tree

1 file changed

+18
-13
lines changed
  • plugins/performance-lab/includes/admin

1 file changed

+18
-13
lines changed

plugins/performance-lab/includes/admin/load.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,11 @@ function perflab_admin_pointer( ?string $hook_suffix = '' ): void {
152152
return;
153153
}
154154

155-
// Get installed plugins to check if these feature plugins are already installed.
155+
/**
156+
* Installed plugin slugs.
157+
*
158+
* @var non-empty-string[] $installed_plugin_slugs
159+
*/
156160
$installed_plugin_slugs = array_map(
157161
static function ( $name ) {
158162
return strtok( $name, '/' );
@@ -166,14 +170,14 @@ static function ( $name ) {
166170
'perflab-feature-nocache-bfcache' => 'nocache-bfcache',
167171
);
168172

173+
// Make sure that the dismissed pointers include any plugins that are already installed.
169174
$dismissed_pointers_updated = false;
170175
foreach ( $plugin_dependent_pointers as $pointer_id => $slug ) {
171176
if ( in_array( $slug, $installed_plugin_slugs, true ) && ! in_array( $pointer_id, $dismissed_pointer_ids, true ) ) {
172177
$dismissed_pointer_ids[] = $pointer_id;
173178
$dismissed_pointers_updated = true;
174179
}
175180
}
176-
177181
if ( $dismissed_pointers_updated ) {
178182
update_user_meta(
179183
get_current_user_id(),
@@ -182,21 +186,22 @@ static function ( $name ) {
182186
);
183187
}
184188

185-
if ( count( array_diff( $admin_pointer_ids, $dismissed_pointer_ids ) ) === 0 ) {
186-
return;
187-
}
188-
189-
// Enqueue pointer CSS and JS.
190-
wp_enqueue_style( 'wp-pointer' );
191-
wp_enqueue_script( 'wp-pointer' );
192-
193189
$new_install_pointer_id = 'perflab-admin-pointer';
194190
if ( ! in_array( $new_install_pointer_id, $dismissed_pointer_ids, true ) ) {
195191
$needed_pointer_ids = array( $new_install_pointer_id );
196192
} else {
197193
$needed_pointer_ids = array_diff( $admin_pointer_ids, $dismissed_pointer_ids );
198194
}
199195

196+
// No admin pointers are needed, so abort.
197+
if ( count( $needed_pointer_ids ) === 0 ) {
198+
return;
199+
}
200+
201+
// Enqueue pointer CSS and JS.
202+
wp_enqueue_style( 'wp-pointer' );
203+
wp_enqueue_script( 'wp-pointer' );
204+
200205
$args = array(
201206
'heading' => __( 'Performance Lab', 'performance-lab' ),
202207
);
@@ -231,8 +236,8 @@ static function ( string $needed_pointer ) use ( $admin_pointers ): string {
231236
?>
232237
<script>
233238
jQuery( function() {
234-
const pointerIdsToDismiss = <?php echo wp_json_encode( $pointer_ids_to_dismiss, JSON_OBJECT_AS_ARRAY ); ?>;
235-
const nonce = <?php echo wp_json_encode( wp_create_nonce( 'dismiss_pointer' ) ); ?>;
239+
const pointerIdsToDismiss = <?php echo wp_json_encode( $pointer_ids_to_dismiss, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_OBJECT_AS_ARRAY ); ?>;
240+
const nonce = <?php echo wp_json_encode( wp_create_nonce( 'dismiss_pointer' ), JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); ?>;
236241

237242
function dismissNextPointer() {
238243
const pointerId = pointerIdsToDismiss.shift();
@@ -252,7 +257,7 @@ function dismissNextPointer() {
252257

253258
// Pointer Options.
254259
const options = {
255-
content: <?php echo wp_json_encode( '<h3>' . esc_html( $args['heading'] ) . '</h3>' . wp_kses( $args['content'], $wp_kses_options ) ); ?>,
260+
content: <?php echo wp_json_encode( '<h3>' . esc_html( $args['heading'] ) . '</h3>' . wp_kses( $args['content'], $wp_kses_options ), JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); ?>,
256261
position: {
257262
edge: 'left',
258263
align: 'right',

0 commit comments

Comments
 (0)