Files
chrnxandClaude Opus 5 d1ad17f4be feat: add a provider-agnostic subscribe form
Reading settings take an HTTPS endpoint and the email field name, so
the form posts straight to Buttondown, Mailchimp, MailerLite or
anything else without the theme picking one. Without an endpoint the
block renders nothing rather than a form that goes nowhere.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-13 19:41:36 -05:00

36 lines
1.6 KiB
PHP

<?php
/**
* Subscribe Form block render.
*
* @package CHRNX
*/
$chrnx_endpoint = chrnx_get_subscribe_endpoint();
// Nothing invented: without a configured provider there is no form to show.
if ( '' === $chrnx_endpoint ) {
return;
}
$chrnx_field = chrnx_get_subscribe_field_name();
$chrnx_heading = chrnx_get_heading_level( $attributes['headingLevel'] ?? 2, 2 );
$chrnx_input_id = wp_unique_id( 'chrnx-subscribe-email-' );
?>
<section <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-subscribe-form' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<h<?php echo esc_attr( $chrnx_heading ); ?> class="chrnx-subscribe-form__title"><?php echo esc_html__( 'Get new work by email', 'chrnx' ); ?></h<?php echo esc_attr( $chrnx_heading ); ?>>
<p class="chrnx-subscribe-form__note"><?php echo esc_html__( 'New stories, releases, and episodes. No tracking, and you can leave whenever you want.', 'chrnx' ); ?></p>
<form class="chrnx-subscribe-form__form" method="post" action="<?php echo esc_url( $chrnx_endpoint ); ?>" target="_blank" rel="noopener noreferrer">
<label class="chrnx-subscribe-form__label" for="<?php echo esc_attr( $chrnx_input_id ); ?>"><?php echo esc_html__( 'Email address', 'chrnx' ); ?></label>
<input
class="chrnx-subscribe-form__input"
id="<?php echo esc_attr( $chrnx_input_id ); ?>"
type="email"
name="<?php echo esc_attr( $chrnx_field ); ?>"
autocomplete="email"
inputmode="email"
spellcheck="false"
required
>
<button class="chrnx-subscribe-form__button" type="submit"><?php echo esc_html__( 'Subscribe', 'chrnx' ); ?></button>
</form>
</section>