Plugin Directory


Ignore:
Timestamp:
09/11/2026 08:14:03 PM (5 weeks ago)
Author:
mizan42047
Message:

Update to version 1.3.0 from GitHub

File:
1 edited

Legend:

Unmodified
Added
Removed
  • blockish/trunk/includes/Extensions/AiPreview.php

    r3672479 r3692053  
    22
    33namespace Blockish\Extensions;
     4
     5use Blockish\Config\ExtensionList;
    46
    57defined( 'ABSPATH' ) || exit;
    … …  
    79/**
    810 * 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.
    912 */
    1013class AiPreview {
    1114
    1215        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        }
    1372
    1473        /**
    … …  
    57116                        }
    58117
     118                        $preview  = \Blockish\Mcp\SchemaUtils::find_ai_preview_block( (string) ( $row['post_content'] ?? '' ) );
    59119                        $items[] = array(
    60120                                'id'         => $id,
    … …  
    67127                                'rest_id'    => self::rest_id( $id, $type, (string) ( $row['post_name'] ?? '' ) ),
    68128                                'rest_route' => self::rest_route( $id, $type, (string) ( $row['post_name'] ?? '' ) ),
     129                                'resolved'   => self::preview_has_children( $preview ),
    69130                        );
    70131                }
    71132
    72133                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'] );
    73146        }
    74147
    … …  
    83156                        return null;
    84157                }
    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'] ?? '' );
    88159
    89160                $post_type = $post->post_type;
    … …  
    93164                        'id'             => $post_id,
    94165                        '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 ),
    98168                        'rest_id'        => self::rest_id( $post_id, $post_type, $post_name ),
    99169                        'rest_route'     => self::rest_route( $post_id, $post_type, $post_name ),
    … …  
    273343                        case 'blockish_form':
    274344                                return __( 'Form', 'blockish' );
     345                        case 'blockish_megamenu':
     346                                return __( 'Mega Menu', 'blockish' );
    275347                        case 'page':
    276348                        case 'blockish-page':
Note: See TracChangeset for help on using the changeset viewer.