Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kellymears/block-sandbox
Better WordPress block testing for theme & plugin developers.
https://github.com/kellymears/block-sandbox
gutenberg wordpress wordpress-plugin
Last synced: 3 months ago
JSON representation
Better WordPress block testing for theme & plugin developers.
- Host: GitHub
- URL: https://github.com/kellymears/block-sandbox
- Owner: kellymears
- License: mit
- Created: 2019-04-30T10:05:53.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-14T10:22:53.000Z (over 4 years ago)
- Last Synced: 2024-10-08T18:19:49.857Z (4 months ago)
- Topics: gutenberg, wordpress, wordpress-plugin
- Language: PHP
- Size: 281 KB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Block Editor Sandbox
[![Latest Stable Version](https://poser.pugx.org/tiny-pixel/block-sandbox/v/stable)](https://packagist.org/packages/tiny-pixel/block-sandbox) [![Total Downloads](https://poser.pugx.org/tiny-pixel/block-sandbox/downloads)](https://packagist.org/packages/tiny-pixel/block-sandbox) [![License](https://poser.pugx.org/tiny-pixel/block-sandbox/license)](https://packagist.org/packages/tiny-pixel/block-sandbox)
This plugin registers a `Sandbox` posttype preset with a template including many common/core blocks in diverse arrangements. It requires zero configuration to start utilizing.
It was inspired by `coblocks/block-unit-test` (now `godaddy/block-unit-test` π¬).
**In comparison, `block-sandbox` aims to be:**
β Hackable, with an easy-to-read and fun-to-modify API
β Easy to keep updated as the block spec continues to change
β Not the intellectual property of Godaddy. Nothing against Rich Tabor (get it!) but _no, thanks_.
## Simple usage
```console
$ composer require tiny-pixel/block-sandbox
$ wp plugin activate block-sandbox
```## Programmatic usage & configuration
At a minimum you need to create the CPT, apply the template and register it with WordPress:
```php
add_action('init', function () {
(new Sandbox())
->create()
->applyTemplate()
->register();
});
```Additionally, there are several methods available for you to utilize in modifying the behavior of the plugin.
### Append extra blocks
If you would like to add additional blocks to the template you can do so with the `appendBlocks` method.
```php
$extra = [['core/cover', [
'align' => 'wide',
'url' => 'example.png',
'title' => 'Additional block'
]]];add_action('init', function () use ($extra) {
(new Sandbox())
->createSandbox()
->appendBlocks($extra)
->applyTemplate()
->register();
});
```### Overwrite template
If you would like to wholesale replace the included template with your own you can do so using `setTemplate`. Just pass in an array of the blocks.
```php
$template = [
['core/cover', [
'align' => 'wide',
'url' => 'example.png',
'title' => 'Additional block']],['core-embed/vimeo', [
'caption' => 'Γ©coute: El Guincho',
'align' => 'wide',
'url' => 'https://vimeo.com/70237487']],
];add_action('init', function () use ($template) {
(new Sandbox())
->createSandbox()
->setTemplate($template)
->applyTemplate()
->register();
});
```### Modify labels
If you would like to change `sandbox` to something else you can do that using `setLabel`. It takes an array with a new `id`, `singular`, and `plural` form of your desired label.
```php
$label = [
'id' => 'test',
'singular' => 'Test',
'plural' => 'Tests',
];add_action('init', function () use ($label) {
(new Sandbox())
->create()
->setLabel($label)
->applyTemplate()
->register();
});
```### All of the above
```php
add_action('init', function () use ($template, $extra, $posttype) {
(new Sandbox())
->create()
->setLabel($posttype)
->setTemplate($template)
->appendBlocks($extra)
->applyTemplate()
->register();
});
```## License
[MIT License](https://github.com/kellymears/block-testing/blob/master/LICENSE.md). Happy hacking!