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 = () => ( + <> +
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 (