3, 'title' => __( 'Nodebook form', 'nodebook' ), 'category' => 'widgets', 'editor_script' => 'nodebook-blocks', 'style' => 'nodebook-form', 'attributes' => array( 'phone' => array( 'type' => 'boolean', 'default' => false, ), 'company' => array( 'type' => 'boolean', 'default' => false, ), 'message' => array( 'type' => 'boolean', 'default' => true, ), 'button' => array( 'type' => 'string', 'default' => '', ), 'success' => array( 'type' => 'string', 'default' => '', ), 'newsletter' => array( 'type' => 'boolean', 'default' => true, ), 'newsletterText' => array( 'type' => 'string', 'default' => '', ), 'source' => array( 'type' => 'string', 'default' => '', ), ), 'render_callback' => array( __CLASS__, 'render_form' ), ) ); register_block_type( 'nodebook/signup', array( 'api_version' => 3, 'title' => __( 'Newsletter sign-up', 'nodebook' ), 'category' => 'widgets', 'editor_script' => 'nodebook-blocks', 'style' => 'nodebook-form', 'attributes' => array( 'name' => array( 'type' => 'boolean', 'default' => true, ), 'button' => array( 'type' => 'string', 'default' => '', ), 'promise' => array( 'type' => 'string', 'default' => '', ), 'success' => array( 'type' => 'string', 'default' => '', ), ), 'render_callback' => array( __CLASS__, 'render_signup' ), ) ); } /** Shortcode attributes from block attributes; empty strings fall back to the shortcode's defaults. */ private static function atts( array $map ) { return array_filter( $map, static function ( $v ) { return '' !== $v && null !== $v; } ); } /** * The contact form block. * * @param array $a Block attributes. */ public static function render_form( $a ) { $fields = array( 'name', 'email' ); foreach ( array( 'phone', 'company', 'message' ) as $f ) { if ( ! empty( $a[ $f ] ) ) { $fields[] = $f; } } return '