| 1 |
<?php |
| 2 |
/** |
| 3 |
* Server-side rendering of the `core/form-submission-notification` block. |
| 4 |
* |
| 5 |
* @package WordPress |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Renders the `core/form-submission-notification` block on server. |
| 10 |
* |
| 11 |
* @param array $attributes The block attributes. |
| 12 |
* @param string $content The saved content. |
| 13 |
* |
| 14 |
* @return string The content of the block being rendered. |
| 15 |
*/ |
| 16 |
function gutenberg_render_block_core_form_submission_notification( $attributes, $content ) { |
| 17 |
$show = isset( $_GET['wp-form-result'] ) && sanitize_text_field( wp_unslash( $_GET['wp-form-result'] ) ) === $attributes['type']; |
| 18 |
/** |
| 19 |
* Filters whether to show the form submission notification block. |
| 20 |
* |
| 21 |
* @param bool $show Whether to show the form submission notification block. |
| 22 |
* @param array $attributes The block attributes. |
| 23 |
* @param string $content The saved content. |
| 24 |
* |
| 25 |
* @return bool Whether to show the form submission notification block. |
| 26 |
*/ |
| 27 |
$show = apply_filters( 'show_form_submission_notification_block', $show, $attributes, $content ); |
| 28 |
if ( ! $show ) { |
| 29 |
return ''; |
| 30 |
} |
| 31 |
return $content; |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Registers the `core/form-submission-notification` block on server. |
| 36 |
*/ |
| 37 |
function gutenberg_register_block_core_form_submission_notification() { |
| 38 |
if ( ! gutenberg_is_experiment_enabled( 'gutenberg-form-blocks' ) ) { |
| 39 |
return; |
| 40 |
} |
| 41 |
register_block_type_from_metadata( |
| 42 |
__DIR__ . '/form-submission-notification', |
| 43 |
array( |
| 44 |
'render_callback' => 'gutenberg_render_block_core_form_submission_notification', |
| 45 |
) |
| 46 |
); |
| 47 |
} |
| 48 |
add_action( 'init', 'gutenberg_register_block_core_form_submission_notification', 20 ); |
| 49 |
|