PHP code example of themeplate / blocks
1. Go to this page and download the library: Download themeplate/blocks library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
themeplate / blocks example snippets
use ThemePlate\Blocks\BlockType;
/** https://developer.wordpress.org/reference/classes/wp_block_type/__construct/#parameters */
$config = array(
'namespace' => 'my-blocks',
'template' => '/path/to/render.php',
);
( new BlockType( 'Custom Block', $config ) )->fields( $list )->init();
/** >= 1.6.0 */
( new BlockType( __DIR__ . '/tests/example' ) )->init()
$config = array(
'allowed_blocks' => array(
'core/image',
'core/heading',
'core/paragraph',
),
'template_blocks' => array(
array( 'core/image', array() ),
array( 'core/heading', array( 'placeholder' => 'Insert title here' ) ),
array( 'core/paragraph', array( 'placeholder' => 'Insert content copy' ) ),
),
);
( new BlockType( 'My custom block', $config ) )->fields( $list )->init();
/** >= 1.6.0 */
// return in the config.php file beside block.json
return $config;
use ThemePlate\Blocks\CustomBlocks;
( new CustomBlocks( 'My Blocks', '/path/to/blocks' ) )->init();
/** >= 1.6.0 */
( new CustomBlocks( '/path/to/blocks' ) )->init()
use ThemePlate\Blocks\BlockType;
return ( new BlockType( 'My custom block' ) )->fields( $list );
/** >= 1.6.0 */
return array(
...
/** https://developer.wordpress.org/reference/classes/wp_block_type/__construct/#parameters */
...
);
/**
* @var array $attributes Block attributes.
* @var string $content Block inner content.
* @var WP_Block $block Block instance.
*/
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
/path/to/blocks/
├── first-block/
│ ├── block.json // >= 1.6.0
│ ├── config.php
│ └── markup.php
├── second-block/
├── block.json // >= 1.6.0
├── config.php
└── markup.php