[ 'name' => __('FormLayer Forms', 'formlayer-pro'), 'singular_name' => __('FormLayer Form', 'formlayer-pro'), ], 'public' => false, 'show_ui' => false, 'show_in_rest' => true, 'supports' => ['title', 'editor'], ]); register_block_type('formlayer/form-selector', [ 'attributes' => [ 'formId' => [ 'type' => 'string', 'default' => '', ], 'width' => [ 'type' => 'string', 'default' => 'none', ], 'alignment' => [ 'type' => 'string', 'default' => 'left', ], ], 'render_callback' => '\FormLayerPro\Block::render_callback', ]); } // Dynamic rendering callback for the block on frontend static function render_callback($attributes) { if(empty($attributes['formId'])){ return ''; } $form_id = intval($attributes['formId']); // Explicitly enqueue form frontend assets for flawless frontend interactive behaviors wp_enqueue_style('formlayer-frontend'); wp_enqueue_script('formlayer-frontend'); // Get form HTML $form_html = \FormLayer\Frontend::render_shortcode(['id' => $form_id]); // Extract display settings $width = isset($attributes['width']) ? sanitize_text_field($attributes['width']) : 'none'; $align = isset($attributes['alignment']) ? sanitize_text_field($attributes['alignment']) : 'left'; // Apply inline styles based on width & alignment options $style = ''; if($width !== 'none' && !empty($width)){ $style .= 'width: ' . esc_attr($width) . '; max-width: 100%; '; } if($align === 'center'){ $style .= 'margin-left: auto; margin-right: auto; '; } elseif ($align === 'right'){ $style .= 'margin-left: auto; margin-right: 0; '; } else { $style .= 'margin-left: 0; margin-right: auto; '; } // Return fully styled wrapper containing the sanitized/escaped form HTML return '