diff --git a/blocks/subscribe-form/block.json b/blocks/subscribe-form/block.json
new file mode 100644
index 0000000..a976c88
--- /dev/null
+++ b/blocks/subscribe-form/block.json
@@ -0,0 +1,15 @@
+{
+ "$schema": "https://schemas.wp.org/trunk/block.json",
+ "apiVersion": 3,
+ "name": "chrnx/subscribe-form",
+ "version": "0.2.0",
+ "title": "Subscribe Form",
+ "category": "theme",
+ "description": "The email subscription form, rendered only when a provider endpoint is configured.",
+ "textdomain": "chrnx",
+ "attributes": {
+ "headingLevel": { "type": "integer", "default": 2, "enum": [2, 3, 4, 5, 6] }
+ },
+ "supports": { "html": false },
+ "render": "file:./render.php"
+}
diff --git a/blocks/subscribe-form/render.php b/blocks/subscribe-form/render.php
new file mode 100644
index 0000000..c89aaca
--- /dev/null
+++ b/blocks/subscribe-form/render.php
@@ -0,0 +1,35 @@
+
+
' . esc_html__( 'HTTPS form endpoint from your email provider. Leave empty to hide the form.', 'chrnx' ) . '
'; +} + +/** Render the subscription email field-name input. */ +function chrnx_render_subscribe_field_field() { + printf( + '', + esc_attr( chrnx_get_subscribe_field_name() ) + ); + echo '' . esc_html__( 'Name of the email input your provider expects, for example email or EMAIL.', 'chrnx' ) . '
'; +} + +/** Register the subscription form settings and Reading fields. */ +function chrnx_register_subscribe_form_settings() { + register_setting( + 'reading', + 'chrnx_subscribe_endpoint', + array( + 'type' => 'string', + 'default' => '', + 'sanitize_callback' => 'chrnx_sanitize_subscribe_endpoint', + ) + ); + register_setting( + 'reading', + 'chrnx_subscribe_field', + array( + 'type' => 'string', + 'default' => 'email', + 'sanitize_callback' => 'chrnx_sanitize_subscribe_field', + ) + ); + add_settings_field( + 'chrnx_subscribe_endpoint', + esc_html__( 'Subscribe form endpoint', 'chrnx' ), + 'chrnx_render_subscribe_endpoint_field', + 'reading' + ); + add_settings_field( + 'chrnx_subscribe_field', + esc_html__( 'Subscribe email field name', 'chrnx' ), + 'chrnx_render_subscribe_field_field', + 'reading' + ); +} +add_action( 'admin_init', 'chrnx_register_subscribe_form_settings' ); + +/** + * Return the configured subscription form endpoint. + * + * @return string Valid HTTPS endpoint or an empty string. + */ +function chrnx_get_subscribe_endpoint(): string { + return chrnx_sanitize_https_url( get_option( 'chrnx_subscribe_endpoint', '' ) ); +} + +/** + * Return the configured email field name. + * + * @return string Safe field name. + */ +function chrnx_get_subscribe_field_name(): string { + return chrnx_sanitize_subscribe_field( get_option( 'chrnx_subscribe_field', 'email' ) ); +}