Changeset 3692053 for blockish/trunk/includes/Extensions/AiPreview.php
- Timestamp:
- 09/11/2026 08:14:03 PM (5 weeks ago)
- File:
-
- 1 edited
-
blockish/trunk/includes/Extensions/AiPreview.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
blockish/trunk/includes/Extensions/AiPreview.php
r3672479 r3692053 2 2 3 3 namespace Blockish\Extensions; 4 5 use Blockish\Config\ExtensionList; 4 6 5 7 defined( 'ABSPATH' ) || exit; … … 7 9 /** 8 10 * Locates staged blockish/ai-preview blocks via a single posts-table LIKE query. 11 * Registers the dynamic block so resolved inner markup renders on the frontend. 9 12 */ 10 13 class AiPreview { 11 14 12 15 private const BLOCK_COMMENT = '<!-- wp:blockish/ai-preview'; 16 17 /** 18 * Hook block registration when MCP AI is active. 19 */ 20 public static function boot(): void { 21 add_action( 'init', array( __CLASS__, 'register_block' ), 20 ); 22 } 23 24 /** 25 * Dynamic block: editor JS owns the schema attrs; PHP echoes saved children. 26 */ 27 public static function register_block(): void { 28 $active = ExtensionList::get_instance()->get_list( 'active' ); 29 if ( empty( $active['mcp-ai'] ) ) { 30 return; 31 } 32 33 if ( \WP_Block_Type_Registry::get_instance()->is_registered( 'blockish/ai-preview' ) ) { 34 return; 35 } 36 37 register_block_type( 38 'blockish/ai-preview', 39 array( 40 'api_version' => 3, 41 'title' => __( 'AI Preview Wrapper', 'blockish' ), 42 'category' => 'design', 43 'attributes' => array( 44 'previousSchema' => array( 45 'type' => 'string', 46 'default' => '', 47 ), 48 'pendingSchema' => array( 49 'type' => 'string', 50 'default' => '', 51 ), 52 ), 53 'supports' => array( 54 'inserter' => false, 55 'html' => false, 56 'reusable' => false, 57 ), 58 'render_callback' => array( __CLASS__, 'render' ), 59 ) 60 ); 61 } 62 63 /** 64 * Frontend: output resolved inner blocks (empty until editor-open resolve saves children). 65 * 66 * @param array $attributes Block attributes. 67 * @param string $content Serialized inner blocks HTML. 68 */ 69 public static function render( array $attributes, string $content ): string { 70 return $content; 71 } 13 72 14 73 /** … … 57 116 } 58 117 118 $preview = \Blockish\Mcp\SchemaUtils::find_ai_preview_block( (string) ( $row['post_content'] ?? '' ) ); 59 119 $items[] = array( 60 120 'id' => $id, … … 67 127 'rest_id' => self::rest_id( $id, $type, (string) ( $row['post_name'] ?? '' ) ), 68 128 'rest_route' => self::rest_route( $id, $type, (string) ( $row['post_name'] ?? '' ) ), 129 'resolved' => self::preview_has_children( $preview ), 69 130 ); 70 131 } 71 132 72 133 return $items; 134 } 135 136 /** 137 * Whether the ai-preview block already has saved inner markup (FE-ready). 138 * 139 * @param array|null $preview Parsed block from find_ai_preview_block. 140 */ 141 public static function preview_has_children( ?array $preview ): bool { 142 if ( ! $preview ) { 143 return false; 144 } 145 return ! empty( $preview['innerBlocks'] ); 73 146 } 74 147 … … 83 156 return null; 84 157 } 85 $pending = $preview 86 ? \Blockish\Mcp\SchemaUtils::decode_schema_attr( $preview['attrs']['pendingSchema'] ?? '' ) 87 : array(); 158 $pending = \Blockish\Mcp\SchemaUtils::decode_schema_attr( $preview['attrs']['pendingSchema'] ?? '' ); 88 159 89 160 $post_type = $post->post_type; … … 93 164 'id' => $post_id, 94 165 'pendingSchema' => $pending, 95 'previousSchema' => $preview 96 ? \Blockish\Mcp\SchemaUtils::decode_schema_attr( $preview['attrs']['previousSchema'] ?? '' ) 97 : array(), 166 'previousSchema' => \Blockish\Mcp\SchemaUtils::decode_schema_attr( $preview['attrs']['previousSchema'] ?? '' ), 167 'resolved' => self::preview_has_children( $preview ), 98 168 'rest_id' => self::rest_id( $post_id, $post_type, $post_name ), 99 169 'rest_route' => self::rest_route( $post_id, $post_type, $post_name ), … … 273 343 case 'blockish_form': 274 344 return __( 'Form', 'blockish' ); 345 case 'blockish_megamenu': 346 return __( 'Mega Menu', 'blockish' ); 275 347 case 'page': 276 348 case 'blockish-page':
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)