1. Go to this page and download the library: Download sixach/wp-block-api 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/ */
sixach / wp-block-api example snippets
namespace Sixa_Blocks;
final class My_Block extends Block {
public static function register(): void {
register_block_type_from_metadata( plugin_dir_path( __DIR__ ) );
}
}
namespace Sixa_Blocks;
final class My_Extension extends Extension {
public static function register(): void {
Functions::register_extension_from_metadata( plugin_dir_path( __DIR__ ) );
}
}
/**
* My Block.
*
* @wordpress-plugin
* Plugin Name: Sixa - My Block
* Description: My block for WordPress editor.
* Version: 1.0.0
* Requires at least: 5.7
* Requires PHP: 7.2
* Author: sixa AG
* License: GPL v3 or later
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* Text Domain: sixa
*
* @package sixa
*/
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
/**
* Include the namespace of this block.
*/
use Sixa_Blocks\My_Block;
/**
* Composer autoload is needed in this package even if
* it doesn't use any libraries to autoload the classes
* from this package.
*
* @see https://getcomposer.org/doc/01-basic-usage.md#autoloading
*/
Sixa_Blocks\My_Block::init();
namespace Sixa_Blocks;
final class My_Basic_Block extends Block {
public static function register(): void {
register_block_type_from_metadata( plugin_dir_path( __DIR__ ) );
}
}
namespace Sixa_Blocks;
final class My_Block extends Block {
public static function register(): void {
self::some_setup();
register_block_type_from_metadata(
plugin_dir_path( __DIR__ ),
array(
'render_callback' => array( __CLASS__, 'render' ),
)
);
}
public static function render( array $attributes = array() ): string {
// Add your render callback here.
}
private static function some_setup(): void {
// Add your setup code here (e.g. post type registration).
}
}
namespace Sixa_Blocks;
final class My_WooCommerce_Block extends WooCommerce_Block {
public static function register(): void {
register_block_type_from_metadata( plugin_dir_path( __DIR__ ) );
}
}
namespace Sixa_Blocks;
final class My_Extension extends Extension {
public static function register(): void {
Functions::register_extension_from_metadata( plugin_dir_path( __DIR__ ) );
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.