Git Product home page Git Product logo

acf-auto-blocks's Introduction

ACF Auto Blocks

Auto-register ACF field groups as blocks in the block editor.

Creating Blocks

ACF Auto Blocks includes a wp-cli command for creating new blocks:

wp autoblocks make_block foo-bar --name="Foo Bar" --icon="editor-code"

This will create a new directory in your theme named /acf-blocks/foo containing a block.json, group_block_foo.json, and template.php file. You can generate additional files using the CLI Hooks.

Once the block has been created, head to your admin and import the new field group to start adding fields to your block. You can edit the block.json based on the WordPress block metadata and ACF Block API v2. Once your fields are setup, start editing the template.php to output the field data.

<?php
// $foo = $data['foo']

extract( $data );
?>
<div class="block_foo">
  <?php echo $foo; ?>
</div>

Theme Hooks

acf/auto_blocks/directory

Filters block directory. Must return path relative to site install. Defaults to {path-to-theme}/acf-blocks.

function my_autoblocks_directory( $dir ) {
    // ...
    return $dir;
}
add_filter( 'acf/auto_blocks/directory', 'my_autoblocks_directory', 10, 2 );

acf/auto_blocks/v2/parse_block_options

Filters block options used for register_block_type.

function my_autoblocks_parse_block_options_v2( $options ) {
    // ...
    return $options;
}
add_filter( 'acf/auto_blocks/v2/parse_block_options', 'my_autoblocks_parse_block_options_v2', 10, 1 );

acf/auto_blocks/v1/parse_block_options

Filters block options used for acf_register_block. (Deprecated)

function my_autoblocks_parse_block_options_v1( $options ) {
    // ...
    return $options;
}
add_filter( 'acf/auto_blocks/v2/parse_block_options', 'my_autoblocks_parse_block_options_v1', 10, 1 );

acf/auto_blocks/block_data

Filters block field data.

function my_autoblocks_block_data( $data, $block ) {
    // ...
    return $data;
}
add_filter( 'acf/auto_blocks/block_data', 'my_autoblocks_block_data', 10, 2 );

acf/auto_blocks/block_settings

Filters block settings.

function my_autoblocks_block_settings( $settings ) {
    // ...
    return $settings;
}
add_filter( 'acf/auto_blocks/block_settings', 'my_autoblocks_block_settings', 10, 2 );

acf/auto_blocks/block_preview

Filters admin block preview.

function my_autoblocks_block_preview( $html, $block ) {
    // ...
    return $html;
}
add_filter( 'acf/auto_blocks/block_preview', 'my_autoblocks_block_preview', 10, 2 );

acf/auto_blocks/render_block

Filters front-end block ouput.

function my_autoblocks_render_block( $html, $block ) {
    // ...
    return $html;
}
add_filter( 'acf/auto_blocks/render_block', 'my_autoblocks_render_block', 10, 2 );

CLI Hooks

acf/auto_blocks/cli/build_json

Filters block json file.

function my_autoblocks_cli_build_json( $json, $values = [] ) {
    // ...
    return $json;
}
add_filter( 'acf/auto_blocks/cli/build_json', 'my_autoblocks_cli_build_json', 10, 2 );

acf/auto_blocks/cli/build_field_group

Filters ACF field group json file.

function my_autoblocks_cli_build_field_group( $json, $values = [] ) {
    // ...
    return $json;
}
add_filter( 'acf/auto_blocks/cli/build_field_group', 'my_autoblocks_cli_build_field_group', 10, 2 );

acf/auto_blocks/cli/build_template

Filters template php file.

function my_autoblocks_cli_build_template( $php, $values = [] ) {
    // ...
    return $php;
}
add_filter( 'acf/auto_blocks/cli/build_template', 'my_autoblocks_cli_build_template', 10, 2 );

acf/auto_blocks/cli/make_block

Run after base block files have been created.

function my_autoblocks_cli_make_block( $args = [], $assoc_args = [], $values = [] ) {
    // ...
}
add_action( 'acf/auto_blocks/cli/build_template', 'my_autoblocks_cli_make_block', 10, 3 );

Note: $values will contain an associative array that can be used to find replace block specific values.

$values = [
  '{key}' => $key_kebab,
  '{key_kebab}' => $key_kebab,
  '{key_snake}' => $key_snake,
  '{dir}' => $dir,
  '{name}' => $name,
  '{icon}' => $icon,
];

acf-auto-blocks's People

Contributors

benplum avatar wightspace avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

acf-auto-blocks's Issues

Save To Meta on Repeaters

Save to meta is not working for repeaters, only the last item's fields are saved (previous items are overwritten).

Can only register 5 blocks?!

Ben.

I am investigating, but at the moment it only lets me register five blocks. Any more than 5 and the oldest ones (after the youngest 5) are ignored!

Everything looks fine on in the Custom Fields admin pages, but they just don't register.

Can you have a quick look? This is critical for a project I'm working on!

Cheers

A

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.