From 79dd01df1eba2dcddc97a44256f077469ab98172 Mon Sep 17 00:00:00 2001 From: Steven Dufresne Date: Thu, 25 Jul 2024 02:44:50 +0900 Subject: [PATCH] Blocks: Remove ratings blocks, use shared mu-plugins blocks (#146) See https://github.com/WordPress/wporg-mu-plugins/pull/633 Co-authored-by: Kelly Dwan --- .../themes/wporg-themes-2024/functions.php | 2 - .../wporg-themes-2024/inc/block-config.php | 25 ++++++- .../src/ratings-bars/block.json | 18 ----- .../src/ratings-bars/index.js | 16 ----- .../src/ratings-bars/index.php | 20 ------ .../src/ratings-bars/render.php | 48 -------------- .../src/ratings-bars/style.scss | 65 ------------------- .../src/ratings-stars/block.json | 18 ----- .../src/ratings-stars/index.js | 16 ----- .../src/ratings-stars/index.php | 20 ------ .../src/ratings-stars/render.php | 45 ------------- .../src/ratings-stars/style.scss | 29 --------- 12 files changed, 24 insertions(+), 298 deletions(-) delete mode 100644 source/wp-content/themes/wporg-themes-2024/src/ratings-bars/block.json delete mode 100644 source/wp-content/themes/wporg-themes-2024/src/ratings-bars/index.js delete mode 100644 source/wp-content/themes/wporg-themes-2024/src/ratings-bars/index.php delete mode 100644 source/wp-content/themes/wporg-themes-2024/src/ratings-bars/render.php delete mode 100644 source/wp-content/themes/wporg-themes-2024/src/ratings-bars/style.scss delete mode 100644 source/wp-content/themes/wporg-themes-2024/src/ratings-stars/block.json delete mode 100644 source/wp-content/themes/wporg-themes-2024/src/ratings-stars/index.js delete mode 100644 source/wp-content/themes/wporg-themes-2024/src/ratings-stars/index.php delete mode 100644 source/wp-content/themes/wporg-themes-2024/src/ratings-stars/render.php delete mode 100644 source/wp-content/themes/wporg-themes-2024/src/ratings-stars/style.scss diff --git a/source/wp-content/themes/wporg-themes-2024/functions.php b/source/wp-content/themes/wporg-themes-2024/functions.php index 1974861..138dde5 100644 --- a/source/wp-content/themes/wporg-themes-2024/functions.php +++ b/source/wp-content/themes/wporg-themes-2024/functions.php @@ -14,8 +14,6 @@ require_once( __DIR__ . '/src/business-model-notice/index.php' ); require_once( __DIR__ . '/src/child-theme-notice/index.php' ); require_once( __DIR__ . '/src/meta-list/index.php' ); -require_once( __DIR__ . '/src/ratings-bars/index.php' ); -require_once( __DIR__ . '/src/ratings-stars/index.php' ); require_once( __DIR__ . '/src/theme-available-translations/index.php' ); require_once( __DIR__ . '/src/theme-downloads/index.php' ); require_once( __DIR__ . '/src/theme-patterns/index.php' ); diff --git a/source/wp-content/themes/wporg-themes-2024/inc/block-config.php b/source/wp-content/themes/wporg-themes-2024/inc/block-config.php index c33a7e6..4b32ed4 100644 --- a/source/wp-content/themes/wporg-themes-2024/inc/block-config.php +++ b/source/wp-content/themes/wporg-themes-2024/inc/block-config.php @@ -7,7 +7,7 @@ use WP_HTML_Tag_Processor, WP_Block_Supports; use const WordPressdotorg\Theme\Theme_Directory_2024\THEME_POST_TYPE; -use function WordPressdotorg\Theme\Theme_Directory_2024\{ get_query_tags, get_theme_information, wporg_themes_get_feature_list }; +use function WordPressdotorg\Theme\Theme_Directory_2024\{ get_query_tags, get_support_url, get_theme_information, wporg_themes_get_feature_list }; use function WordPressdotorg\Theme\Theme_Directory_2024\SEO_Social_Meta\{get_archive_title}; add_filter( 'wporg_query_total_label', __NAMESPACE__ . '\update_query_total_label', 10, 2 ); @@ -17,6 +17,7 @@ add_action( 'wporg_query_filter_in_form', __NAMESPACE__ . '\inject_other_filters', 10, 2 ); add_filter( 'wporg_block_navigation_menus', __NAMESPACE__ . '\add_site_navigation_menus' ); add_filter( 'wporg_favorite_button_settings', __NAMESPACE__ . '\get_favorite_settings', 10, 2 ); +add_filter( 'wporg_ratings_data', __NAMESPACE__ . '\set_rating_data', 10, 2 ); add_filter( 'render_block_wporg/link-wrapper', __NAMESPACE__ . '\inject_permalink_link_wrapper' ); add_filter( 'render_block_wporg/language-suggest', __NAMESPACE__ . '\inject_language_suggest_endpoint' ); add_filter( 'render_block_core/search', __NAMESPACE__ . '\inject_browse_search_block' ); @@ -409,3 +410,25 @@ function update_site_title( $block_content ) { $block_content ); } + +/** + * Update ratings blocks with real rating data. + * + * @param array $data Rating data. + * @param int $post_id Current post. + * + * @return array + */ +function set_rating_data( $data, $post_id ) { + $theme = get_theme_information( $post_id ); + if ( ! $theme ) { + return $data; + } + + return array( + 'rating' => $theme->rating, + 'ratingsCount' => $theme->num_ratings, + 'ratings' => $theme->ratings, + 'supportUrl' => get_support_url( $theme->slug . '/reviews/' ), + ); +} diff --git a/source/wp-content/themes/wporg-themes-2024/src/ratings-bars/block.json b/source/wp-content/themes/wporg-themes-2024/src/ratings-bars/block.json deleted file mode 100644 index f85a695..0000000 --- a/source/wp-content/themes/wporg-themes-2024/src/ratings-bars/block.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "$schema": "https://schemas.wp.org/trunk/block.json", - "apiVersion": 2, - "name": "wporg/ratings-bars", - "version": "0.1.0", - "title": "Ratings (bars)", - "category": "design", - "icon": "", - "description": "The breakdown of ratings displayed as bars for each rating value.", - "textdomain": "wporg", - "supports": { - "html": false - }, - "usesContext": [ "postId", "postType" ], - "editorScript": "file:./index.js", - "style": "file:./style-index.css", - "render": "file:./render.php" -} diff --git a/source/wp-content/themes/wporg-themes-2024/src/ratings-bars/index.js b/source/wp-content/themes/wporg-themes-2024/src/ratings-bars/index.js deleted file mode 100644 index 1b439ce..0000000 --- a/source/wp-content/themes/wporg-themes-2024/src/ratings-bars/index.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * WordPress dependencies - */ -import { registerBlockType } from '@wordpress/blocks'; - -/** - * Internal dependencies - */ -import Edit from '../utils/dynamic-edit'; -import metadata from './block.json'; -import './style.scss'; - -registerBlockType( metadata.name, { - edit: Edit, - save: () => null, -} ); diff --git a/source/wp-content/themes/wporg-themes-2024/src/ratings-bars/index.php b/source/wp-content/themes/wporg-themes-2024/src/ratings-bars/index.php deleted file mode 100644 index 6c57594..0000000 --- a/source/wp-content/themes/wporg-themes-2024/src/ratings-bars/index.php +++ /dev/null @@ -1,20 +0,0 @@ -context['postId']; -if ( ! $current_post_id ) { - return; -} - -$theme_post = get_post( $block->context['postId'] ); -$theme = wporg_themes_theme_information( $theme_post->post_name ); - -if ( ! $theme->num_ratings ) { - return; -} - -?> - diff --git a/source/wp-content/themes/wporg-themes-2024/src/ratings-bars/style.scss b/source/wp-content/themes/wporg-themes-2024/src/ratings-bars/style.scss deleted file mode 100644 index a52b6aa..0000000 --- a/source/wp-content/themes/wporg-themes-2024/src/ratings-bars/style.scss +++ /dev/null @@ -1,65 +0,0 @@ -.wp-block-wporg-ratings-bars { - list-style: none; - padding-inline-start: unset; -} - -.wporg-ratings-bars__bar { - a { - margin-bottom: 4px; - display: flex; - align-items: center; - gap: var(--wp--preset--spacing--10); - text-decoration: none; - - &:hover { - text-decoration: underline; - } - } - - &:last-child a { - margin-bottom: 0; - } -} - -.wporg-ratings-bars__bar-label { - flex-basis: 4em; - flex-shrink: 0; -} - -.wporg-ratings-bars__bar-count { - flex-basis: 2em; - flex-shrink: 0; - text-align: right; -} - -.wporg-ratings-bars__bar-background { - display: inline-block; - background-color: var(--wp--preset--color--light-grey-2); - position: relative; - width: 100%; - height: var(--wp--preset--spacing--20); -} - -.wporg-ratings-bars__bar-foreground { - position: absolute; - inset: 0; - right: auto; - background-color: var(--wp--custom--wporg-ratings-stars--color--fill); -} - -@supports (grid-template-columns: subgrid) { - .wp-block-wporg-ratings-bars { - display: grid; - gap: 4px var(--wp--preset--spacing--10); - grid-template-columns: auto 1fr auto; - - .wporg-ratings-bars__bar, - .wporg-ratings-bars__bar a { - display: grid; - grid-column: span 3; - grid-template-columns: subgrid; - margin-bottom: unset; - gap: unset; - } - } -} diff --git a/source/wp-content/themes/wporg-themes-2024/src/ratings-stars/block.json b/source/wp-content/themes/wporg-themes-2024/src/ratings-stars/block.json deleted file mode 100644 index 00bf283..0000000 --- a/source/wp-content/themes/wporg-themes-2024/src/ratings-stars/block.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "$schema": "https://schemas.wp.org/trunk/block.json", - "apiVersion": 2, - "name": "wporg/ratings-stars", - "version": "0.1.0", - "title": "Ratings (stars)", - "category": "design", - "icon": "", - "description": "The average rating of this theme displayed as stars.", - "textdomain": "wporg", - "supports": { - "html": false - }, - "usesContext": [ "postId", "postType" ], - "editorScript": "file:./index.js", - "style": "file:./style-index.css", - "render": "file:./render.php" -} diff --git a/source/wp-content/themes/wporg-themes-2024/src/ratings-stars/index.js b/source/wp-content/themes/wporg-themes-2024/src/ratings-stars/index.js deleted file mode 100644 index 1b439ce..0000000 --- a/source/wp-content/themes/wporg-themes-2024/src/ratings-stars/index.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * WordPress dependencies - */ -import { registerBlockType } from '@wordpress/blocks'; - -/** - * Internal dependencies - */ -import Edit from '../utils/dynamic-edit'; -import metadata from './block.json'; -import './style.scss'; - -registerBlockType( metadata.name, { - edit: Edit, - save: () => null, -} ); diff --git a/source/wp-content/themes/wporg-themes-2024/src/ratings-stars/index.php b/source/wp-content/themes/wporg-themes-2024/src/ratings-stars/index.php deleted file mode 100644 index d3a3980..0000000 --- a/source/wp-content/themes/wporg-themes-2024/src/ratings-stars/index.php +++ /dev/null @@ -1,20 +0,0 @@ -context['postId']; -if ( ! $current_post_id ) { - return; -} - -$theme_post = get_post( $block->context['postId'] ); -$theme = wporg_themes_theme_information( $theme_post->post_name ); -$display_rating = round( $theme->rating / 10 ) * 0.5; - -?> -
> - rating ) : ?> - - -
- -
- -
- '; - } else if ( $i + 0.5 === $display_rating ) { - echo ''; - } else { - echo ''; - } - } - ?> -
- -
- ' . $display_rating . '' // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - ); - ?> -
- -
diff --git a/source/wp-content/themes/wporg-themes-2024/src/ratings-stars/style.scss b/source/wp-content/themes/wporg-themes-2024/src/ratings-stars/style.scss deleted file mode 100644 index bffd76a..0000000 --- a/source/wp-content/themes/wporg-themes-2024/src/ratings-stars/style.scss +++ /dev/null @@ -1,29 +0,0 @@ -.wp-block-wporg-ratings-stars { - display: flex; - align-items: center; -} - -.wporg-ratings-stars__icons { - display: inline-flex; - - svg { - height: 32px; - width: 32px; - margin-inline-start: -6px; - fill: var(--wp--custom--wporg-ratings-stars--color--fill); - } - - // Flip the half-star for RTL views. - .rtl & .is-star-half { - transform: rotateY(-180deg); - } -} - -.wporg-ratings-stars__label { - font-size: var(--wp--preset--font-size--small); - color: var(--wp--preset--color--charcoal-4); - - .wporg-ratings-stars__icons + & { - margin-inline-start: 0.5em; - } -}