From c699724443ea916379c280fbc6208ecb9a3f5599 Mon Sep 17 00:00:00 2001 From: Kai Hao Date: Thu, 3 Oct 2024 22:32:43 +0800 Subject: [PATCH 1/5] fix: articles block fail to get all inner blocks (#1878) Co-authored-by: Derrick Koo --- src/blocks/homepage-articles/store.js | 12 ++---------- src/blocks/homepage-articles/utils.ts | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/blocks/homepage-articles/store.js b/src/blocks/homepage-articles/store.js index 116a6f671..11b993d16 100644 --- a/src/blocks/homepage-articles/store.js +++ b/src/blocks/homepage-articles/store.js @@ -17,7 +17,7 @@ import { addQueryArgs } from '@wordpress/url'; * Internal dependencies */ import metadata from './block.json'; -import { getBlockQueries, sanitizePostList } from './utils'; +import { getBlockQueries, sanitizePostList, recursivelyGetBlocks } from './utils'; const { name } = metadata; export const STORE_NAMESPACE = `newspack-blocks/${ name }`; @@ -138,15 +138,7 @@ const createFetchPostsSaga = blockNames => { yield put( { type: 'DISABLE_UI' } ); - // Ensure innerBlocks are populated for widget area blocks. - // See https://github.com/WordPress/gutenberg/issues/32607#issuecomment-890728216. - const blocks = getBlocks().map( block => { - const innerBlocks = select( 'core/block-editor' ).getBlocks( block.clientId ); - return { - ...block, - innerBlocks, - }; - } ); + const blocks = recursivelyGetBlocks( getBlocks ); const blockQueries = getBlockQueries( blocks, blockNames ); diff --git a/src/blocks/homepage-articles/utils.ts b/src/blocks/homepage-articles/utils.ts index d73a0637c..0bc5ffcd3 100644 --- a/src/blocks/homepage-articles/utils.ts +++ b/src/blocks/homepage-articles/utils.ts @@ -272,3 +272,23 @@ export const postsBlockDispatch = ( triggerReflow: isEditorBlock ? dispatch( STORE_NAMESPACE ).reflow : () => undefined, }; }; + +// Ensure innerBlocks are populated for some blocks (e.g. `widget-area` and `post-content`). +// See https://github.com/WordPress/gutenberg/issues/32607#issuecomment-890728216. +// See https://github.com/Automattic/wp-calypso/issues/91839. +export const recursivelyGetBlocks = ( + getBlocks: ( clientId?: string ) => Block[], + blocks: Block[] = getBlocks() +) => { + return blocks.map( ( block ) => { + let innerBlocks = + block.innerBlocks.length === 0 + ? getBlocks( block.clientId ) + : block.innerBlocks; + innerBlocks = recursivelyGetBlocks( getBlocks, innerBlocks ); + return { + ...block, + innerBlocks, + }; + }); +}; From 6eafd2af0d5d3233e56e5d08d9023db11f0a75e8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 20:49:55 +0000 Subject: [PATCH 2/5] build(deps-dev): bump @wordpress/browserslist-config from 6.7.0 to 6.9.0 Bumps [@wordpress/browserslist-config](https://github.com/WordPress/gutenberg/tree/HEAD/packages/browserslist-config) from 6.7.0 to 6.9.0. - [Release notes](https://github.com/WordPress/gutenberg/releases) - [Changelog](https://github.com/WordPress/gutenberg/blob/trunk/packages/browserslist-config/CHANGELOG.md) - [Commits](https://github.com/WordPress/gutenberg/commits/@wordpress/browserslist-config@6.9.0/packages/browserslist-config) --- updated-dependencies: - dependency-name: "@wordpress/browserslist-config" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 28296595b..f6c97cacc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,7 @@ "@testing-library/dom": "^10.4.0", "@testing-library/user-event": "^14.5.2", "@types/lodash": "^4.17.7", - "@wordpress/browserslist-config": "^6.7.0", + "@wordpress/browserslist-config": "^6.9.0", "eslint": "^8.57.0", "fetch-mock-jest": "^1.5.1", "html-entities": "^2.5.2", @@ -6895,9 +6895,9 @@ } }, "node_modules/@wordpress/browserslist-config": { - "version": "6.7.0", - "resolved": "https://registry.npmjs.org/@wordpress/browserslist-config/-/browserslist-config-6.7.0.tgz", - "integrity": "sha512-4iMAK3HJEMRm16E2GLXKbQLO085FvFvVwTU2lhzXHLhewjBfjWL3TnqQ9KdOcPmPZ0AK//hULte6PG2VhTWl6w==", + "version": "6.9.0", + "resolved": "https://registry.npmjs.org/@wordpress/browserslist-config/-/browserslist-config-6.9.0.tgz", + "integrity": "sha512-yv8KJrMZTvhY+PNWQ6CQVTUs/6sAVgim7AxGpgTkVzDYKvTeJKuZqeHzAWtHKTOG+ORIj/29XtpIOU85R9dkng==", "dev": true, "engines": { "node": ">=18.12.0", diff --git a/package.json b/package.json index 16d73cb35..6353a4c24 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "@testing-library/dom": "^10.4.0", "@testing-library/user-event": "^14.5.2", "@types/lodash": "^4.17.7", - "@wordpress/browserslist-config": "^6.7.0", + "@wordpress/browserslist-config": "^6.9.0", "eslint": "^8.57.0", "fetch-mock-jest": "^1.5.1", "html-entities": "^2.5.2", From 9815ff7229f6adc49c06a57a6494e4597405aa48 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 9 Oct 2024 07:08:59 +0000 Subject: [PATCH 3/5] build(deps-dev): bump @types/lodash from 4.17.7 to 4.17.10 Bumps [@types/lodash](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/lodash) from 4.17.7 to 4.17.10. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/lodash) --- updated-dependencies: - dependency-name: "@types/lodash" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index f6c97cacc..41149af9e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "@rushstack/eslint-patch": "^1.10.4", "@testing-library/dom": "^10.4.0", "@testing-library/user-event": "^14.5.2", - "@types/lodash": "^4.17.7", + "@types/lodash": "^4.17.10", "@wordpress/browserslist-config": "^6.9.0", "eslint": "^8.57.0", "fetch-mock-jest": "^1.5.1", @@ -5853,9 +5853,9 @@ "dev": true }, "node_modules/@types/lodash": { - "version": "4.17.7", - "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.7.tgz", - "integrity": "sha512-8wTvZawATi/lsmNu10/j2hk1KEP0IvjubqPE3cu1Xz7xfXXt5oCq3SNUz4fMIP4XGF9Ky+Ue2tBA3hcS7LSBlA==", + "version": "4.17.10", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.10.tgz", + "integrity": "sha512-YpS0zzoduEhuOWjAotS6A5AVCva7X4lVlYLF0FYHAY9sdraBfnatttHItlWeZdGhuEkf+OzMNg2ZYAx8t+52uQ==", "dev": true }, "node_modules/@types/mime": { diff --git a/package.json b/package.json index 6353a4c24..535cc0425 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "@rushstack/eslint-patch": "^1.10.4", "@testing-library/dom": "^10.4.0", "@testing-library/user-event": "^14.5.2", - "@types/lodash": "^4.17.7", + "@types/lodash": "^4.17.10", "@wordpress/browserslist-config": "^6.9.0", "eslint": "^8.57.0", "fetch-mock-jest": "^1.5.1", From adf2e9d82f90c8b9839f107bd2b4c249ff3045e8 Mon Sep 17 00:00:00 2001 From: Derrick Koo Date: Wed, 9 Oct 2024 14:12:22 -0600 Subject: [PATCH 4/5] fix: potential fatal with invalid attribute combo (#1900) --- includes/class-modal-checkout.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-modal-checkout.php b/includes/class-modal-checkout.php index d1a0970d3..3f05858a5 100644 --- a/includes/class-modal-checkout.php +++ b/includes/class-modal-checkout.php @@ -322,7 +322,7 @@ public static function render_variation_selection() { $products = array_keys( self::$products ); foreach ( $products as $product_id ) { $product = wc_get_product( $product_id ); - if ( ! $product->is_type( 'variable' ) ) { + if ( ! $product || ! $product->is_type( 'variable' ) ) { continue; } ?> From 4876de65f2ad2d689ba93507a7a8d041fcc030ba Mon Sep 17 00:00:00 2001 From: Derrick Koo Date: Mon, 14 Oct 2024 11:34:56 -0600 Subject: [PATCH 5/5] fix: deprecate video playlist block (#1903) --- includes/class-newspack-blocks.php | 25 +++++++++ src/blocks/video-playlist/edit.js | 80 +++++++++++---------------- src/blocks/video-playlist/editor.js | 4 +- src/blocks/video-playlist/editor.scss | 11 +++- src/blocks/video-playlist/index.js | 2 +- src/blocks/video-playlist/view.php | 4 ++ 6 files changed, 76 insertions(+), 50 deletions(-) diff --git a/includes/class-newspack-blocks.php b/includes/class-newspack-blocks.php index 252351e8d..f826ebfe1 100644 --- a/includes/class-newspack-blocks.php +++ b/includes/class-newspack-blocks.php @@ -241,6 +241,7 @@ public static function enqueue_block_editor_assets() { 'custom_taxonomies' => self::get_custom_taxonomies(), 'can_use_name_your_price' => self::can_use_name_your_price(), 'tier_amounts_template' => self::get_formatted_amount(), + 'can_use_video_playlist' => self::can_use_video_playlist_block(), ]; if ( class_exists( 'WP_REST_Newspack_Author_List_Controller' ) ) { @@ -1643,5 +1644,29 @@ public static function get_image_caption( $attachment_id = null, $include_captio return $combined_caption; } + + /** + * Check if the current site can use the Video Playlist block. + * If the block doesn't already exist in site content, it won't be registered. + */ + public static function can_use_video_playlist_block() { + // Check if the block exists in any content on the site. + $existing_blocks = new WP_Query( + [ + 'fields' => 'ids', + 'post_type' => 'any', + 'post_status' => 'publish', + 's' => 'newspack-blocks/youtube-video-playlist', + 'posts_per_page' => 1, + ] + ); + + // Don't register the block if it's not already on the site. + if ( 0 < $existing_blocks->found_posts ) { + return true; + } + + return false; + } } Newspack_Blocks::init(); diff --git a/src/blocks/video-playlist/edit.js b/src/blocks/video-playlist/edit.js index 50cc88fd0..372e10d8f 100644 --- a/src/blocks/video-playlist/edit.js +++ b/src/blocks/video-playlist/edit.js @@ -1,19 +1,14 @@ /** * WordPress dependencies */ -import { __ } from '@wordpress/i18n'; +import { __, sprintf } from '@wordpress/i18n'; import apiFetch from '@wordpress/api-fetch'; import { Component, Fragment } from '@wordpress/element'; -import { Placeholder, Spinner, PanelBody, RangeControl } from '@wordpress/components'; +import { Notice, Placeholder, Spinner, PanelBody } from '@wordpress/components'; import { InspectorControls } from '@wordpress/block-editor'; import { addQueryArgs } from '@wordpress/url'; import { decodeEntities } from '@wordpress/html-entities'; -/** - * Internal dependencies. - */ -import AutocompleteTokenField from '../../components/autocomplete-tokenfield'; - class Edit extends Component { constructor( props ) { super( props ); @@ -175,55 +170,46 @@ class Edit extends Component { } ); }; - /** - * Hide the overlay so users can play the videos. - */ - hideOverlay() { - this.setState( { interactive: true } ); - } - /** * Render. */ render() { - const { attributes, setAttributes } = this.props; - const { categories, videosToShow } = attributes; - const { embed, isLoading, interactive } = this.state; + const { embed, isLoading } = this.state; + + const Warning = () => ( + <> +

{ __( 'The YouTube Video Playlist block is deprecated', 'newspack-plugin' ) }

+

YouTube Playlists instead, which can be embedded into post or page content.', 'newspack-blocks' ), + 'https://support.google.com/youtube/answer/57792', + 'https://support.google.com/youtube/answer/171780' + ), + } } /> + + ) return ( - { ( isLoading || '' === embed ) && this.renderPlaceholder() } - { ! ( isLoading || '' === embed ) && ( -

-
- { ! interactive && ( - // eslint-disable-next-line jsx-a11y/no-static-element-interactions -
this.hideOverlay() } /> - ) } -
- ) } +
+ { ( isLoading || '' === embed ) && this.renderPlaceholder() } + { ! ( isLoading || '' === embed ) && ( +
+
+
+ ) } + { ! isLoading && ( +
+ +
+ ) } +
- - setAttributes( { videosToShow: _videosToShow } ) } - min={ 1 } - max={ 30 } - required - /> - setAttributes( { categories: _categories } ) } - fetchSuggestions={ this.fetchCategorySuggestions } - fetchSavedInfo={ this.fetchSavedCategories } - label={ __( 'Categories', 'newspack-blocks' ) } - /> - + + + diff --git a/src/blocks/video-playlist/editor.js b/src/blocks/video-playlist/editor.js index ed4f28163..18cd89a3a 100644 --- a/src/blocks/video-playlist/editor.js +++ b/src/blocks/video-playlist/editor.js @@ -4,4 +4,6 @@ import { registerBlockType } from '@wordpress/blocks'; import { name, settings } from '.'; -registerBlockType( `newspack-blocks/${ name }`, settings ); +if ( window.newspack_blocks_data?.can_use_video_playlist ) { + registerBlockType( `newspack-blocks/${ name }`, settings ); +} diff --git a/src/blocks/video-playlist/editor.scss b/src/blocks/video-playlist/editor.scss index 15611d6f9..d19ae86f4 100644 --- a/src/blocks/video-playlist/editor.scss +++ b/src/blocks/video-playlist/editor.scss @@ -5,8 +5,17 @@ * Prevents interaction with the player until the block is focused. */ .wpbnbvp__overlay { + align-content: center; + background-color: rgba(255, 255, 255, 0.9); + display: flex; + flex-direction: column; + justify-content: center; + left: 0; + height: 100%; position: absolute; - inset: 0; + text-align: center; + top: 0; + width: 100%; } .wpbnbvp-preview { diff --git a/src/blocks/video-playlist/index.js b/src/blocks/video-playlist/index.js index 038c4b886..2c2c3892e 100644 --- a/src/blocks/video-playlist/index.js +++ b/src/blocks/video-playlist/index.js @@ -15,7 +15,7 @@ import edit from './edit'; import './editor.scss'; export const name = 'youtube-video-playlist'; -export const title = __( 'YouTube Video Playlist', 'newspack-blocks' ); +export const title = __( 'YouTube Video Playlist (DEPRECATED)', 'newspack-blocks' ); export const icon = ( diff --git a/src/blocks/video-playlist/view.php b/src/blocks/video-playlist/view.php index cf6d8b8d4..2ffdc7553 100644 --- a/src/blocks/video-playlist/view.php +++ b/src/blocks/video-playlist/view.php @@ -23,6 +23,10 @@ function newspack_blocks_render_block_video_playlist( $attributes ) { * Registers the `newspack-blocks/donate` block on server. */ function newspack_blocks_register_video_playlist() { + if ( ! Newspack_Blocks::can_use_video_playlist_block() ) { + return; + } + register_block_type( 'newspack-blocks/youtube-video-playlist', array(