Skip to content

Commit

Permalink
Ensure that no duplicate hooks can be provided.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixarntz committed Aug 3, 2023
1 parent 6b5d12a commit 61f5ccc
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions server-timing/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ function perflab_sanitize_server_timing_setting( $value ) {
return array();
}

// Ensure that every element is an indexed array of hook names.
/*
* Ensure that every element is an indexed array of hook names.
* Any duplicates across a group of hooks are removed.
*/
return array_filter(
array_map(
static function( $hooks ) {
if ( ! is_array( $hooks ) ) {
$hooks = explode( "\n", $hooks );
}
return array_filter( array_map( 'sanitize_key', $hooks ) );
return array_unique( array_filter( array_map( 'sanitize_key', $hooks ) ) );
},
$value
)
Expand Down

0 comments on commit 61f5ccc

Please sign in to comment.