Add Gutenberg block helper functions for Oribi Sync

This commit is contained in:
Matt Batchelder
2026-02-19 16:11:55 -05:00
parent f17b9ccb98
commit f528f21573

View File

@@ -9,11 +9,35 @@
if ( ! defined( 'ABSPATH' ) ) exit;
// ─── Gutenberg block helpers ──────────────────────────────────────────────────
/** Generate a self-closing block comment (standalone or child blocks). */
if ( ! function_exists( 'oribi_b' ) ) {
function oribi_b( $name, $attrs = [] ) {
return '<!-- wp:oribi/' . $name . ' ' . wp_json_encode( $attrs, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ) . ' /-->';
}
}
/** Generate an opening tag for a parent block comment. */
if ( ! function_exists( 'oribi_b_open' ) ) {
function oribi_b_open( $name, $attrs = [] ) {
$json = ! empty( $attrs ) ? ' ' . wp_json_encode( $attrs, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ) : '';
return '<!-- wp:oribi/' . $name . $json . ' -->';
}
}
/** Generate a closing tag for a parent block comment. */
if ( ! function_exists( 'oribi_b_close' ) ) {
function oribi_b_close( $name ) {
return '<!-- /wp:oribi/' . $name . ' -->';
}
}
/**
* Execute a PHP page-data file fetched from the repo and return its block markup.
*
* The file is expected to use oribi_b() / oribi_b_open() / oribi_b_close()
* helpers (from oribi-tech-setup) and return a string of Gutenberg block markup.
* helpers and return a string of Gutenberg block markup.
*
* @param string $php_source Raw PHP source code from the repo.
* @param string $slug Page slug (used for error context).
@@ -21,14 +45,6 @@ if ( ! defined( 'ABSPATH' ) ) exit;
* @return string|WP_Error The rendered block markup, or WP_Error on failure.
*/
function oribi_sync_execute_php( string $php_source, string $slug ) {
// Ensure the block helpers are available
if ( ! function_exists( 'oribi_b' ) ) {
return new WP_Error(
'oribi_sync_missing_helpers',
'Block helper functions (oribi_b, oribi_b_open, oribi_b_close) are not available. '
. 'Make sure the Oribi Tech Setup plugin is active.'
);
}
// Write to a temp file so we can include it
$tmp = wp_tempnam( 'oribi-sync-' . $slug . '.php' );