Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
42.86% |
12 / 28 |
|
0.00% |
0 / 1 |
CRAP | n/a |
0 / 0 |
|
| Automattic\Jetpack\Extensions\VideoPress_Video\register_videopress_blocks | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
42 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Register VideoPress Video block. |
| 4 | * |
| 5 | * @package automattic/jetpack |
| 6 | **/ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Extensions\VideoPress_Video; |
| 9 | |
| 10 | use Automattic\Jetpack\VideoPress\Channel as VideoPress_Pkg_Channel; |
| 11 | use Automattic\Jetpack\VideoPress\Initializer as VideoPress_Pkg_Initializer; |
| 12 | |
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | exit( 0 ); |
| 15 | } |
| 16 | |
| 17 | // Set the videopress/video block availability, depending on the site plan. |
| 18 | add_action( |
| 19 | 'jetpack_register_gutenberg_extensions', |
| 20 | function () { |
| 21 | \Jetpack_Gutenberg::set_availability_for_plan( 'videopress/video' ); |
| 22 | } |
| 23 | ); |
| 24 | |
| 25 | /** |
| 26 | * Register the VideoPress blocks. |
| 27 | * |
| 28 | * Named so tests can invoke it directly without re-running the global init action. |
| 29 | * |
| 30 | * @param string|null $playlist_metadata_file Path to the playlist block.json; null uses the package default. |
| 31 | * @param string|null $latest_videos_playlist_metadata_file Path to the latest videos playlist block.json; null uses the package default. |
| 32 | */ |
| 33 | function register_videopress_blocks( $playlist_metadata_file = null, $latest_videos_playlist_metadata_file = null ) { |
| 34 | $extensions = \Jetpack_Gutenberg::get_extensions(); |
| 35 | $is_videopress_video_extension_enabled = in_array( 'videopress/video', $extensions, true ); |
| 36 | |
| 37 | if ( |
| 38 | $is_videopress_video_extension_enabled && |
| 39 | method_exists( 'Automattic\Jetpack\VideoPress\Initializer', 'register_videopress_video_block' ) |
| 40 | ) { |
| 41 | VideoPress_Pkg_Initializer::register_videopress_video_block(); |
| 42 | } |
| 43 | |
| 44 | // The playlist block has its own VideoPress-module-active guard inside |
| 45 | // register_videopress_playlist_block(), so register it unconditionally here. |
| 46 | if ( method_exists( 'Automattic\Jetpack\VideoPress\Initializer', 'register_videopress_playlist_block' ) ) { |
| 47 | VideoPress_Pkg_Initializer::register_videopress_playlist_block( $playlist_metadata_file ); |
| 48 | } |
| 49 | |
| 50 | // Depends on the playlist block above: it registers only once that one is. |
| 51 | if ( method_exists( 'Automattic\Jetpack\VideoPress\Initializer', 'register_videopress_latest_videos_playlist_block' ) ) { |
| 52 | VideoPress_Pkg_Initializer::register_videopress_latest_videos_playlist_block( $latest_videos_playlist_metadata_file ); |
| 53 | } |
| 54 | |
| 55 | // The All Playlists block only registers once the playlist block has. |
| 56 | if ( method_exists( 'Automattic\Jetpack\VideoPress\Initializer', 'register_videopress_all_playlists_block' ) ) { |
| 57 | VideoPress_Pkg_Initializer::register_videopress_all_playlists_block(); |
| 58 | } |
| 59 | } |
| 60 | // Ignore the empty argument supplied by do_action( 'init' ) so metadata uses the package default. |
| 61 | add_action( 'init', __NAMESPACE__ . '\register_videopress_blocks', 10, 0 ); |
| 62 | |
| 63 | // The channel feature ( video durations and views, Query Loop filters, channel block |
| 64 | // bindings ) registers itself on init when the theme opts in; WordPress.com does not |
| 65 | // run the package initializer, so it starts here as well. |
| 66 | if ( method_exists( 'Automattic\Jetpack\VideoPress\Channel', 'init' ) ) { |
| 67 | VideoPress_Pkg_Channel::init(); |
| 68 | } |
| 69 | |
| 70 | // Register the `v6-video-frame-poster` extension. |
| 71 | add_action( |
| 72 | 'jetpack_register_gutenberg_extensions', |
| 73 | function () { |
| 74 | \Jetpack_Gutenberg::set_extension_available( 'v6-video-frame-poster' ); |
| 75 | } |
| 76 | ); |