Skip to content

Commit 74a3d6c

Browse files
StevenDufresneryelle
authored andcommitted
Use filter to populate stars.
Tie into filters. Fix typo. Update the filter.
1 parent 7e3165b commit 74a3d6c

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

source/wp-content/themes/wporg-themes-2024/inc/block-config.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use WP_HTML_Tag_Processor, WP_Block_Supports;
99
use const WordPressdotorg\Theme\Theme_Directory_2024\THEME_POST_TYPE;
10-
use function WordPressdotorg\Theme\Theme_Directory_2024\{ get_query_tags, get_theme_information, wporg_themes_get_feature_list };
10+
use function WordPressdotorg\Theme\Theme_Directory_2024\{ get_query_tags, get_support_url, get_theme_information, wporg_themes_get_feature_list };
1111
use function WordPressdotorg\Theme\Theme_Directory_2024\SEO_Social_Meta\{get_archive_title};
1212

1313
add_filter( 'wporg_query_total_label', __NAMESPACE__ . '\update_query_total_label', 10, 2 );
@@ -17,6 +17,7 @@
1717
add_action( 'wporg_query_filter_in_form', __NAMESPACE__ . '\inject_other_filters', 10, 2 );
1818
add_filter( 'wporg_block_navigation_menus', __NAMESPACE__ . '\add_site_navigation_menus' );
1919
add_filter( 'wporg_favorite_button_settings', __NAMESPACE__ . '\get_favorite_settings', 10, 2 );
20+
add_filter( 'wporg_ratings_data', __NAMESPACE__ . '\set_rating_data', 10, 2 );
2021
add_filter( 'render_block_wporg/link-wrapper', __NAMESPACE__ . '\inject_permalink_link_wrapper' );
2122
add_filter( 'render_block_wporg/language-suggest', __NAMESPACE__ . '\inject_language_suggest_endpoint' );
2223
add_filter( 'render_block_core/search', __NAMESPACE__ . '\inject_browse_search_block' );
@@ -409,3 +410,25 @@ function update_site_title( $block_content ) {
409410
$block_content
410411
);
411412
}
413+
414+
/**
415+
* Update ratings blocks with real rating data.
416+
*
417+
* @param array $data Rating data.
418+
* @param int $post_id Current post.
419+
*
420+
* @return array
421+
*/
422+
function set_rating_data( $data, $post_id ) {
423+
$theme = get_theme_information( $post_id );
424+
if ( ! $theme ) {
425+
return $data;
426+
}
427+
428+
return array(
429+
'rating' => $theme->rating,
430+
'ratingsCount' => $theme->num_ratings,
431+
'ratings' => $theme->ratings,
432+
'supportUrl' => get_support_url( $theme->slug . '/reviews/' ),
433+
);
434+
}

0 commit comments

Comments
 (0)