|
/ Documentation /Developer Hooks & Events/ suredonation_allowed_form_blocks Filter Hook

suredonation_allowed_form_blocks Filter Hook

The suredonation_allowed_form_blocks filter allows developers to modify the list of block types that can be used in the SureDonation donation-form block editor.

Use this filter when developing a custom SureDonation field or block that should be available in the block inserter while creating or editing a donation form.

Parameters

ParameterTypeDescription
$blocksarrayThe list of block names allowed in the SureDonation form editor.

The default SureDonation block list includes:

suredonation/input
suredonation/email
suredonation/number
suredonation/dropdown
suredonation/address
suredonation/phone
suredonation/url
suredonation/heading
suredonation/html
suredonation/donation-amount
suredonation/anonymous-donation
suredonation/payment
suredonation/donate-button
suredonation/cover-fees

Return Value

Return an array containing the block names that should be available in the SureDonation form editor.

You can use the filter to:

  • Add custom blocks.
  • Remove existing blocks.
  • Modify the list of blocks available to form builders.

Filter Source

apply_filters( 'suredonation_allowed_form_blocks', $blocks );

Filter Usage

add_filter( 'suredonation_allowed_form_blocks', 'your_custom_function', 10, 1 );

function your_custom_function( $blocks ) {

    // Add or remove allowed blocks here.

    return $blocks;

}

Filter Example

The following example adds a custom field block to the SureDonation block inserter:

add_filter( 'suredonation_allowed_form_blocks', 'mysite_allow_custom_block', 10, 1 );

function mysite_allow_custom_block( $blocks ) {

    $blocks[] = 'mysite/custom-field';

    return $blocks;

}

After applying this filter, mysite/custom-field can be included in SureDonation donation forms.

  • The filter is applied in Donation_Form::restrict_blocks() through the allowed_block_types_all handler.
  • It only affects SureDonation form post types.
  • For other WordPress post types, the block allowlist is returned without modification.
  • Registering a block with this filter does not register the block itself. The custom block must already be registered with WordPress.
  • If the custom block requires server-side validation, also consider registering it with suredonation_validatable_blocks.
  • If the block is part of a custom extension and needs to be registered during SureDonation’s block-registration process, use suredonation_register_additional_blocks.

Related Hooks

  • suredonation_register_additional_blocks
  • suredonation_validatable_blocks
Was this doc helpful?
What went wrong?

We don't respond to the article feedback, we use it to improve our support content.

Need help? Contact Support
Table of Contents
Scroll to Top