| @@ -9,10 +9,15 @@ | ||
| 9 | 9 | |
| 10 | 10 | namespace Automattic\Jetpack\Extensions\VideoPress; |
| 11 | 11 | |
| 12 | 12 | use Automattic\Jetpack\Blocks; |
| 13 | +use Automattic\Jetpack\Modules; | |
| 13 | 14 | use Jetpack_Gutenberg; |
| 14 | 15 | |
| 16 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 17 | + exit( 0 ); | |
| 18 | +} | |
| 19 | + | |
| 15 | 20 | const FEATURE_NAME = 'videopress-block'; |
| 16 | 21 | const FEATURE_FOLDER = 'videopress'; |
| 17 | 22 | const BLOCK_NAME = 'jetpack/' . FEATURE_NAME; |
| 18 | 23 | |
| @@ -21,8 +26,17 @@ | ||
| 21 | 26 | * This is done via an action so that we can disable |
| 22 | 27 | * registration if we need to. |
| 23 | 28 | */ |
| 24 | 29 | function register_block() { |
| 30 | + /* | |
| 31 | + * The block is available even when the module is not active, | |
| 32 | + * so we can display a nudge to activate the module instead of the block. | |
| 33 | + * However, since non-admins cannot activate modules, we do not display the empty block for them. | |
| 34 | + */ | |
| 35 | + if ( ! ( new Modules() )->is_active( 'videopress' ) && ! current_user_can( 'jetpack_activate_modules' ) ) { | |
| 36 | + return; | |
| 37 | + } | |
| 38 | + | |
| 25 | 39 | Blocks::jetpack_register_block( |
| 26 | 40 | BLOCK_NAME, |
| 27 | 41 | array( 'render_callback' => __NAMESPACE__ . '\load_assets' ) |
| 28 | 42 | ); |
| @@ -37,7 +51,12 @@ | ||
| 37 | 51 | * |
| 38 | 52 | * @return string |
| 39 | 53 | */ |
| 40 | 54 | function load_assets( $attrs, $content ) { |
| 55 | + // Do not render the block if the module is not active. | |
| 56 | + if ( ! ( new Modules() )->is_active( 'videopress' ) ) { | |
| 57 | + return ''; | |
| 58 | + } | |
| 59 | + | |
| 41 | 60 | Jetpack_Gutenberg::load_assets_as_required( FEATURE_FOLDER ); |
| 42 | 61 | return $content; |
| 43 | 62 | } |