| 1 |
<?php |
| 2 |
/** |
| 3 |
* PHP render form Sureforms_Form Block. |
| 4 |
* |
| 5 |
* @package SureForms. |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace SRFM\Inc\Blocks\Sform; |
| 9 |
|
| 10 |
use WP_REST_Response; |
| 11 |
use SRFM\Inc\Blocks\Base; |
| 12 |
use SRFM\Inc\Generate_Form_Markup; |
| 13 |
use SRFM\Inc\Helper; |
| 14 |
|
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Sureforms_Form Block. |
| 21 |
*/ |
| 22 |
class Block extends Base { |
| 23 |
/** |
| 24 |
* Render the block. |
| 25 |
* |
| 26 |
* @param array<mixed> $attributes Block attributes. |
| 27 |
* @param string $content Post content. |
| 28 |
* |
| 29 |
* @return string|false |
| 30 |
*/ |
| 31 |
public function render( $attributes, $content = '' ) { |
| 32 |
$id = isset( $attributes['id'] ) ? Helper::get_integer_value( $attributes['id'] ) : ''; |
| 33 |
|
| 34 |
if ( empty( $id ) ) { |
| 35 |
return ''; |
| 36 |
} |
| 37 |
|
| 38 |
$sf_classname = isset( $attributes['className'] ) ? $attributes['className'] : ''; |
| 39 |
$show_title_current_page = isset( $attributes['showTitle'] ) ? $attributes['showTitle'] : true; |
| 40 |
|
| 41 |
$form = get_post( $id ); |
| 42 |
|
| 43 |
if ( ! $form || SRFM_FORMS_POST_TYPE !== $form->post_type || 'publish' !== $form->post_status || ! empty( $form->post_password ) ) { |
| 44 |
return ''; |
| 45 |
} |
| 46 |
|
| 47 |
return Generate_Form_Markup::get_form_markup( $id, $show_title_current_page, $sf_classname ); |
| 48 |
} |
| 49 |
|
| 50 |
} |
| 51 |
|