Skip to content

Commit

Permalink
Update placeholder status for the contact form block as well
Browse files Browse the repository at this point in the history
  • Loading branch information
jeherve committed Nov 25, 2024
1 parent b908bc1 commit d9172a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit d9172a1

Please sign in to comment.