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