Skip to content

Instantly share code, notes, and snippets.

@baldawayash15
Last active June 6, 2024 08:54
Show Gist options
  • Save baldawayash15/05950dbb6a73fae04e8f81ed2684be77 to your computer and use it in GitHub Desktop.
Save baldawayash15/05950dbb6a73fae04e8f81ed2684be77 to your computer and use it in GitHub Desktop.
<?php
// Placeholder Classes
if ( ! class_exists( 'Placeholder_Block' ) ) {
class Placeholder_Block {
public $name;
function __construct( $name ) {
$this->name = $name;
add_action( 'init', array( $this, 'onInit' ) );
}
function ourRenderCallback( $attributes, $content ) {
ob_start();
require get_theme_file_path( "/blocks/{$this->name}.php" );
return ob_get_clean();
}
function onInit() {
wp_register_script( $this->name, get_stylesheet_directory_uri() . "/blocks/{$this->name}.js", array( 'wp-blocks', 'wp-editor' ) );
register_block_type( "blocktheme/{$this->name}", array(
'editor_script' => $this->name,
'render_callback' => array( $this, 'ourRenderCallback' )
) );
}
}
}
new Placeholder_Block( 'header' );
<?php
include ( get_theme_file_path( '/includes/class-placeholder-block.php' ) );
wp.blocks.registerBlockType("gtrpsblocktheme/header", {
title: "Global Trade Review Header",
edit: function () {
return wp.element.createElement(
"div",
{ className: "gtr-placeholder-block" },
"Global Trade Review Header Placeholder"
);
},
save: function () {
return null;
},
});
<?php
// Header code goes here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment