register( new self() ); } /** * Widget name. */ public function get_name(): string { return 'forensix-form'; } /** * Widget title. */ public function get_title(): string { return __( 'Forensix form', 'forensix-digital' ); } /** * Widget icon. */ public function get_icon(): string { return 'eicon-form-horizontal'; } /** * Panel category. * * @return string[] */ public function get_categories(): array { return array( 'general' ); } /** * Controls: the form to show. */ protected function register_controls(): void { $options = array( '' => __( 'Choose a form', 'forensix-digital' ) ); foreach ( ( new FormStore() )->all() as $form ) { $options[ (string) $form['id'] ] = $form['title']; } $this->start_controls_section( 'content', array( 'label' => __( 'Form', 'forensix-digital' ) ) ); $this->add_control( 'form_id', array( 'label' => __( 'Form', 'forensix-digital' ), 'type' => Controls_Manager::SELECT, 'options' => $options, 'default' => '', ) ); $this->end_controls_section(); } /** * Front-end output, the same as the shortcode. */ protected function render(): void { $settings = $this->get_settings_for_display(); $form_id = absint( $settings['form_id'] ?? 0 ); if ( $form_id > 0 ) { echo FormsApp::render_form( $form_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped with wp_kses() in FormsApp::render_form(). } } }