Making WordPress.org


Ignore:
Timestamp:
05/16/2024 05:27:41 AM (2 years ago)
Author:
dd32
Message:

Plugin Directory: Blocks: Import blocks registered with new WP_Block_Type().

See #6170.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php

    r13712 r13713  
    10141014                                foreach ( $matches as $match ) {
    10151015                                        $blocks[] = (object) [
    1016                                                 'name' => $match[1],
     1016                                                'name'  => $match[1],
    10171017                                                'title' => $match[2],
    10181018                                        ];
     
    10201020                        }
    10211021                }
     1022
    10221023                if ( 'php' === $ext ) {
    10231024                        // Parse a php-style register_block_type() call.
    10241025                        // Again this assumes literal strings, and only parses the name and title.
    10251026                        $contents = file_get_contents( $filename );
     1027
     1028                        // Search out register_block_type() calls.
    10261029                        if ( $contents && preg_match_all( "#register_block_type\s*[(]\s*['\"]([-\w]+/[-\w]+)['\"](?!\s*[.])#ms", $contents, $matches, PREG_SET_ORDER ) ) {
    10271030                                foreach ( $matches as $match ) {
    10281031                                        $blocks[] = (object) [
    1029                                                 'name' => $match[1],
     1032                                                'name'  => $match[1],
    10301033                                                'title' => null,
    10311034                                        ];
    10321035                                }
    10331036                        }
    1034                 }
     1037
     1038                        // Search out WP_Block_Type() instances.
     1039                        if ( $contents && preg_match_all( "#new\s+WP_Block_Type\s*[(]\s*['\"]([-\w]+\/[-\w]+)['\"](?!\s*[.])(\s*,[^;]{0,500}['\"]title['\"]\s*=>\s*['\"]([^'\"]+)['\"](?!\s*[.]))?#ms", $contents, $matches, PREG_SET_ORDER ) ) {
     1040                                var_dump( $filename, $matches );
     1041                                foreach ( $matches as $match ) {
     1042                                        $blocks[] = (object) [
     1043                                                'name'  => $match[1],
     1044                                                'title' => $match[3] ?? null,
     1045                                        ];
     1046                                }
     1047                        }
     1048
     1049                }
     1050
    10351051                if ( 'block.json' === basename( $filename ) ) {
    10361052                        // A block.json file should have everything we want.
Note: See TracChangeset for help on using the changeset viewer.