Skip to content

Commit

Permalink
Remove unnecessary filter od_current_url_metrics_etag_active_theme
Browse files Browse the repository at this point in the history
Signed-off-by: Shyamsundar Gadde <[email protected]>
  • Loading branch information
ShyamGadde committed Dec 10, 2024
1 parent 65dc803 commit 1c0bdac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 30 deletions.
31 changes: 10 additions & 21 deletions plugins/optimization-detective/storage/data.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,31 +156,20 @@ function od_get_url_metrics_slug( array $query_vars ): string {
* @return non-empty-string Current ETag.
*/
function od_get_current_url_metrics_etag( OD_Tag_Visitor_Registry $tag_visitor_registry, WP_Query $wp_query, $current_template ): string {
$active_theme = array(
'template' => array(
'name' => get_template(),
'version' => wp_get_theme( get_template() )->get( 'Version' ),
),
'stylesheet' => array(
'name' => get_stylesheet(),
'version' => wp_get_theme()->get( 'Version' ),
),
);

/**
* Filters the active theme details used for computing the current ETag.
*
* @since n.e.x.t
*
* @param array<string, array<string, string|false>> $active_theme Active theme details.
*/
$active_theme = apply_filters( 'od_current_url_metrics_etag_active_theme', $active_theme );

$data = array(
'tag_visitors' => array_keys( iterator_to_array( $tag_visitor_registry ) ),
'queried_object' => $wp_query->get_queried_object(),
'queried_posts' => wp_list_pluck( $wp_query->posts, 'post_modified_gmt', 'ID' ),
'active_theme' => $active_theme,
'active_theme' => array(
'template' => array(
'name' => get_template(),
'version' => wp_get_theme( get_template() )->get( 'Version' ),
),
'stylesheet' => array(
'name' => get_stylesheet(),
'version' => wp_get_theme()->get( 'Version' ),
),
),
'current_template' => $current_template,
);

Expand Down
18 changes: 9 additions & 9 deletions plugins/optimization-detective/tests/storage/test-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ static function ( array $data ) use ( &$captured_etag_data ) {
PHP_INT_MAX
);
add_filter(
'od_current_url_metrics_etag_active_theme',
static function ( $active_theme ) {
$active_theme = array(
'od_current_url_metrics_etag_data',
static function ( $data ) {
$data['active_theme'] = array(
'template' => array(
'name' => 'od-theme',
'version' => '1.0.0',
Expand All @@ -320,7 +320,7 @@ static function ( $active_theme ) {
'version' => '1.0.0',
),
);
return $active_theme;
return $data;
}
);

Expand Down Expand Up @@ -401,11 +401,11 @@ static function ( $active_theme ) {

// Modify data using filters.
add_filter(
'od_current_url_metrics_etag_active_theme',
static function ( $active_theme ) {
$active_theme['template']['version'] = '2.0.0';
$active_theme['stylesheet']['version'] = '2.0.0';
return $active_theme;
'od_current_url_metrics_etag_data',
static function ( $data ) {
$data['active_theme']['template']['version'] = '2.0.0';
$data['active_theme']['stylesheet']['version'] = '2.0.0';
return $data;
}
);
$etag6 = od_get_current_url_metrics_etag( $registry, $wp_the_query, $current_template );
Expand Down

0 comments on commit 1c0bdac

Please sign in to comment.