Skip to main content

GF_Block

Base Gravity Forms Block class.

Since: 2.4.10 (Class GF_Block)

Source: includes/blocks/class-gf-block.php:15

Details

  • Kind: class
  • Namespace: (global)

Properties

PropertyTypeDescription
$typestringBlock type.
$script_handlestringHandle of primary block editor script.
$style_handlestringHandle of primary block editor style.
$fe_script_handlestringHandle of primary block FE script.
$fe_style_handlestringHandle of primary block FE style.
$attributesarrayBlock attributes.

Methods

MethodDescription
init()Register block type.
get_type()Get block type.
register_block_type()Register block with WordPress.
register_block_assets()Enqueue/register the block's assets upon init
check_allowed_blocks()Checks allowed blocks for Gravity forms blocks to only enqueue block editor assets when necessary.
register_scripts()Enqueue block scripts.
enqueue_scripts()Enqueue scripts
scripts()Override this function to provide a list of scripts to be enqueued.
register_styles()Enqueue block styles.
enqueue_styles()Enqueue styles
styles()Override this function to provide a list of styles to be enqueued.
render_block()Display block contents on frontend.
post_enqueue_scripts()Override to perform additional actions when scripts/styles are enqueued on the wp_enqueue_scripts hook.

Method Reference

init()

public function init()

Register block type.

Enqueue editor assets.

Since: 2.4.10

Source: includes/blocks/class-gf-block.php:81

get_type()

public function get_type()

Get block type.

Returns

  • string

Since: 2.4.10

Source: includes/blocks/class-gf-block.php:104

register_block_type()

public function register_block_type()

Register block with WordPress.

Since: 2.4.10

Source: includes/blocks/class-gf-block.php:115

register_block_assets()

public function register_block_assets()

Enqueue/register the block's assets upon init

Returns

  • void

Since: 2.5.6

Source: includes/blocks/class-gf-block.php:145

check_allowed_blocks()

public function check_allowed_blocks( $allowed_block_types )

Checks allowed blocks for Gravity forms blocks to only enqueue block editor assets when necessary.

Parameters

NameTypeDefaultDescription
$allowed_block_typesbool | arrayArray of block type slugs, or boolean to enable/disable all.

Returns

  • bool | array

Since: 2.4.18

Deprecated: since 2.5.6. See GF_Block::register_block_assets()

Source: includes/blocks/class-gf-block.php:161

register_scripts()

public function register_scripts()

Enqueue block scripts.

Since: 2.4.10

Source: includes/blocks/class-gf-block.php:184

enqueue_scripts()

public function enqueue_scripts()

Enqueue scripts

Returns

  • void

Source: includes/blocks/class-gf-block.php:235

scripts()

public function scripts()

Override this function to provide a list of scripts to be enqueued.

Following is an example of the array that is expected to be returned by this function: <pre>



array(
array(
'handle' =&gt; 'super_signature_script',
'src' =&gt; $this-&gt;get_base_url() . '/super_signature/ss.js',
'version' =&gt; $this-&gt;_version,
'deps' =&gt; array( 'jquery'),
'callback' =&gt; array( $this, 'localize_scripts' ),
'strings' =&gt; array(
// Accessible in JavaScript using the global variable "[script handle]_strings"
'stringKey1' =&gt; __( 'The string', 'gravityforms' ),
'stringKey2' =&gt; __( 'Another string.', 'gravityforms' )
)
)
);


</pre>

Returns

  • array

Since: 2.4.10

Source: includes/blocks/class-gf-block.php:267

register_styles()

public function register_styles()

Enqueue block styles.

Since: 2.4.10

Source: includes/blocks/class-gf-block.php:284

enqueue_styles()

public function enqueue_styles()

Enqueue styles

Returns

  • void

Source: includes/blocks/class-gf-block.php:324

styles()

public function styles()

Override this function to provide a list of styles to be enqueued.

See scripts() for an example of the format expected to be returned.

Returns

  • array

Since: 2.4.10

Source: includes/blocks/class-gf-block.php:336

render_block()

public function render_block( $attributes=[] )

Display block contents on frontend.

Parameters

NameTypeDefaultDescription
$attributesarray[]Block attributes.

Returns

  • string

Since: 2.4.10

Source: includes/blocks/class-gf-block.php:357

post_enqueue_scripts()

public function post_enqueue_scripts( $found_forms, $found_blocks, $post )

Override to perform additional actions when scripts/styles are enqueued on the wp_enqueue_scripts hook.

Parameters

NameTypeDefaultDescription
$found_formsarrayAn array of found forms using the form ID as the key to the ajax status.
$found_blocksarrayAn array of found GF blocks.
$postWP_PostThe post which was processed.

Since: 2.4.18

Source: includes/blocks/class-gf-block.php:372