Making WordPress.org

Changeset 9052


Ignore:
Timestamp:
07/17/2019 07:33:07 AM (7 years ago)
Author:
tellyworth
Message:

Plugin dir: import more block metadata.

This stores new postmeta items block_name and block_files for use with the block install UI.

File:
1 edited

Legend:

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

    r9050 r9052  
    7575                $tagged_versions = $data['tagged_versions'];
    7676                $blocks          = $data['blocks'];
     77                $block_files     = $data['block_files'];
    7778
    7879                $content = '';
     
    189190                // Store the block data, if known
    190191                if ( count( $blocks ) ) {
    191                         update_post_meta( $plugin->ID, 'all_blocks', $blocks );
     192                        $changed = update_post_meta( $plugin->ID, 'all_blocks', $blocks );
     193                        if ( $changed || count ( get_post_meta( $plugin->ID, 'block_name' ) ) !== count ( $blocks ) ) {
     194                                delete_post_meta( $plugin->ID, 'block_name' );
     195                                foreach ( $blocks as $block ) {
     196                                        add_post_meta( $plugin->ID, 'block_name', $block->name, false );
     197                                }
     198                        }
    192199                } else {
    193200                        delete_post_meta( $plugin->ID, 'all_blocks' );
     201                        delete_post_meta( $plugin->ID, 'block_name' );
     202                }
     203
     204                // Only store block_files for plugins in the block directory
     205                if ( count( $block_files ) && has_term( 'block', 'plugin_section', $plugin->ID ) ) {
     206                        update_post_meta( $plugin->ID, 'block_files', $block_files );
     207                } else {
     208                        delete_post_meta( $plugin->ID, 'block_files' );
    194209                }
    195210
     
    440455                }
    441456
    442                 return compact( 'readme', 'stable_tag', 'tmp_dir', 'plugin_headers', 'assets', 'tagged_versions', 'blocks' );
     457                // Find blocks dist/build JS files
     458                $block_files = array();
     459                $dist_files = SVN::ls( 'https://plugins.svn.wordpress.org' . "/{$plugin_slug}/trunk/dist" ) ?: array();
     460                $build_files = SVN::ls( 'https://plugins.svn.wordpress.org' . "/{$plugin_slug}/trunk/build" ) ?: array();
     461
     462                foreach ( $dist_files as $file ) {
     463                        #$block_files[] = 'https://plugins.svn.wordpress.org' . "/{$plugin_slug}/trunk/dist/" . $file;
     464                        $block_files[] = '/trunk/dist/' . $file;
     465                }
     466
     467                foreach ( $build_files as $file ) {
     468                        #$block_files[] = 'https://plugins.svn.wordpress.org' . "/{$plugin_slug}/trunk/build/" . $file;
     469                        $block_files[] = '/trunk/build/' . $file;
     470                }
     471
     472                return compact( 'readme', 'stable_tag', 'tmp_dir', 'plugin_headers', 'assets', 'tagged_versions', 'blocks', 'block_files' );
    443473        }
    444474
Note: See TracChangeset for help on using the changeset viewer.