Skip to content

Commit df0c176

Browse files
Update the filter.
1 parent 07ba397 commit df0c176

File tree

1 file changed

+15
-28
lines changed

1 file changed

+15
-28
lines changed

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

Lines changed: 15 additions & 28 deletions
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, 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 );
@@ -16,8 +16,7 @@
1616
add_filter( 'wporg_query_filter_options_subjects', __NAMESPACE__ . '\get_subjects_options' );
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' );
19-
add_filter( 'wporg_block_ratings_stars', __NAMESPACE__ . '\set_rating_stars' );
20-
add_filter( 'wporg_block_ratings_bars', __NAMESPACE__ . '\set_rating_bars' );
19+
add_filter( 'wporg_ratings_data', __NAMESPACE__ . '\set_rating_data', 10, 2 );
2120
add_filter( 'render_block_wporg/link-wrapper', __NAMESPACE__ . '\inject_permalink_link_wrapper' );
2221
add_filter( 'render_block_wporg/language-suggest', __NAMESPACE__ . '\inject_language_suggest_endpoint' );
2322
add_filter( 'render_block_core/search', __NAMESPACE__ . '\inject_browse_search_block' );
@@ -363,35 +362,23 @@ function filter_language_suggest_block( $block_content ) {
363362
}
364363

365364
/**
366-
* Update block attributes with real rating data.
365+
* Update ratings blocks with real rating data.
367366
*
368-
* @param array $attributes Block attributes.
369-
* @return array
370-
*/
371-
function set_rating_stars( $attributes ) {
372-
global $post;
373-
374-
$theme = wporg_themes_theme_information( $post->post_name );
375-
376-
return array_merge( $attributes, array(
377-
'rating' => $theme->rating,
378-
) );
379-
}
380-
381-
/**
382-
* Update block attributes with real rating data.
367+
* @param array $data Rating data.
368+
* @param int $post_id Current post.
383369
*
384-
* @param array $attributes Block attributes.
385370
* @return array
386371
*/
387-
function set_rating_bars( $attributes ) {
388-
global $post;
389-
390-
$theme = wporg_themes_theme_information( $post->post_name );
372+
function set_rating_data( $data, $post_id ) {
373+
$theme = get_theme_information( $post_id );
374+
if ( ! $theme ) {
375+
return $data;
376+
}
391377

392-
return array_merge( $attributes, array(
393-
'num_ratings' => $theme->num_ratings,
378+
return array(
379+
'rating' => $theme->rating,
380+
'ratingsCount' => $theme->num_ratings,
394381
'ratings' => $theme->ratings,
395-
'slug' => $theme->slug,
396-
) );
382+
'supportUrl' => get_support_url( $theme->slug . '/reviews/' ),
383+
);
397384
}

0 commit comments

Comments
 (0)