diff --git a/projects/packages/forms/changelog/update-block-skeleton-non-admins b/projects/packages/forms/changelog/update-block-skeleton-non-admins new file mode 100644 index 0000000000000..6e4ba2743674c --- /dev/null +++ b/projects/packages/forms/changelog/update-block-skeleton-non-admins @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Block registration: do not display the block in the editor for non-admins, when the feature is not active. diff --git a/projects/packages/forms/src/blocks/contact-form/class-contact-form-block.php b/projects/packages/forms/src/blocks/contact-form/class-contact-form-block.php index 6a77ca212e17d..e8d61c2e8649e 100644 --- a/projects/packages/forms/src/blocks/contact-form/class-contact-form-block.php +++ b/projects/packages/forms/src/blocks/contact-form/class-contact-form-block.php @@ -11,7 +11,7 @@ use Automattic\Jetpack\Blocks; use Automattic\Jetpack\Forms\ContactForm\Contact_Form; use Automattic\Jetpack\Forms\ContactForm\Contact_Form_Plugin; -use Jetpack; +use Automattic\Jetpack\Modules; /** * Contact Form block render callback. @@ -24,6 +24,15 @@ class Contact_Form_Block { * and enable plugin in one click */ public static function register_block() { + /* + * The block is available even when the module is not active, + * so we can display a nudge to activate the module instead of the block. + * However, since non-admins cannot activate modules, we do not display the empty block for them. + */ + if ( ! ( new Modules() )->is_active( 'contact-form' ) && ! current_user_can( 'jetpack_activate_modules' ) ) { + return; + } + Blocks::jetpack_register_block( 'jetpack/contact-form', array( @@ -134,7 +143,7 @@ public static function register_child_blocks() { */ public static function gutenblock_render_form( $atts, $content ) { // We should not render block is module is disabled - if ( ! Jetpack::is_module_active( 'contact-form' ) ) { + if ( ! ( new Modules() )->is_active( 'contact-form' ) ) { return ''; } // Render fallback in other contexts than frontend (i.e. feed, emails, API, etc.), unless the form is being submitted.