Skip to content

badasswp/manage-block-template

Repository files navigation

manage-block-template

A simple plugin to manage block templates easily.


screenshot-1

Download

Download from WordPress plugin repository.

You can also get the latest version from any of our release tags.

Why Manage Block Template?

Creating and managing block templates for different post types within your WP website doesn't have to be rocket science! With this plugin, you can easily create multiple block templates of your choice and assign them to specific post types within your website. It's fast and super easy to use.

This plugin is perfect for website owners who run blogs, news or websites with tons of post types! Now, you have one less to worry about...

manage-block-template-demo.mp4

Hooks

manage_block_template_admin_fields

This custom hook (filter) provides a way to filter the admin fields presented on the options page of the plugin.

add_filter( 'manage_block_template_admin_fields', [ $this, 'custom_admin_fields' ] );

public function custom_admin_fields( $fields ): array {
    $fields[] = [
        'name'    => 'name_of_your_control',
        'label'   => __( 'Control Label', 'your-text-domain' ),
        'cb'      => [ $this, 'name_of_your_control_callback' ],
        'page'    => 'manage-block-template',
        'section' => 'manage-block-template-section',
    ];

    return $fields;
}

Parameters

  • fields {array} By default this will be an array containing key, value options for the control.

manage_block_template_blocks

This custom hook (filter) provides a way to filter the blocks passed to a specific post type's template.

add_filter( 'manage_block_template_blocks', [ $this, 'custom_blocks' ], 10, 2 );

public function custom_blocks( $blocks, $post_type ): array {
    if ( 'your_custom_post_type' === $post_type ) {
        $blocks[] = [
            'your-custom-block-name',
            [
                'placeholder' => 'your-placeholder',
            ],
        ];
    }

    return $blocks;
}

Parameters

  • blocks {array} By default this will be an index array containing arrays with block names and attributes.
  • post_type {string} By default this will be the current post type.

manage_block_template_post_types

This custom hook (filter) provides a way to filter the post types available for block templates.

add_filter( 'manage_block_template_post_types', [ $this, 'custom_post_types' ] );

public function custom_post_types( $post_types ): array {
    $post_types[] = esc_html(
        'your_custom_post_type'
    );

    return $post_types;
}

Parameters

  • post_types {array} By default this will be an index array containing post type names.

Contribute

Contributions are welcome and will be fully credited. To contribute, please fork this repo and raise a PR (Pull Request) against the master branch.

Pre-requisites

You should have the following tools before proceeding to the next steps:

  • Composer
  • Yarn
  • Docker

To enable you start development, please run:

yarn start

This should spin up a local WP env instance for you to work with at:

http://manage-block-template.localhost:8496

You should now have a functioning local WP env to work with. To login to the wp-admin backend, please use admin for username & password for password.

Awesome! - Thanks for being interested in contributing your time and code to this project!

About

Manage your WP Block Editor template.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors