<?php
// Only copy below this line.
// -------------------------------------------------------------
/**
* Register a custom attribute or more. This is useful to limit where your custom fields appear.
*/
add_filter( 'pum_sub_form_shortcode_defaults', 'custom_pum_mc_shortcode_atts' );
function custom_pum_mc_shortcode_atts( $defaults ) {
$defaults['custom1'] = '';
return $defaults;
}
/**
* Process any extra submitted fields and add the needed data to the api subscriber request.
*/
add_filter( 'pum_mailchimp_sub_list_args', 'process_custom_pum_mc_fields' );
function process_custom_pum_mc_fields( $subscriber ) {
if ( isset( $_POST['custom1'] ) ) {
$subscriber['merge_fields']['CUSTOM1'] = sanitize_text_field( $_POST['custom1'] );
}
return $subscriber;
}
/**
* Render any custom fields when the custom1 attr exists.
*/
add_action( 'pum_newsletter_fields', 'custom_pum_mc_fields' );
function custom_pum_mc_fields( $atts ) {
if ( ! empty( $atts['custom1'] ) ) {
?>
<div class="pum-form__field pum-sub-form-field">
<label class="pum-form__label pum-sub-form-label">Custom 1
<input type="text" name="custom1" placeholder="Custom 1">
</label>
</div>
<?php
}
}