Making WordPress.org


Ignore:
Timestamp:
05/16/2024 07:08:56 AM (2 years ago)
Author:
dd32
Message:

Plugin Directory: Blocks: When we can't extract a block name, instead of using the plugin name, use the block name in "human readable form".

For example 'plugin-slug/my-block' becomes 'My Block', and 'example/example-block-name' becomes 'Block Name'.

Fixes #5971.

File:
1 edited

Legend:

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

    r13717 r13718  
    406406                                delete_post_meta( $plugin->ID, 'block_name' );
    407407                                delete_post_meta( $plugin->ID, 'block_title' );
     408
    408409                                foreach ( $blocks as $block ) {
    409410                                        add_post_meta( $plugin->ID, 'block_name', $block->name, false );
    410                                         add_post_meta( $plugin->ID, 'block_title', ( $block->title ?: $plugin->post_title ), false );
     411                                        add_post_meta( $plugin->ID, 'block_title', $block->title, false );
    411412                                }
    412413                        }
     
    843844                }
    844845
    845                 foreach ( $blocks as $block_name => $block ) {
     846                // Set the fallback name for the blocks.
     847                foreach ( $blocks as $block_name => &$block ) {
    846848                        if ( empty( $block->title ) ) {
    847                                 $blocks[ $block_name ]->title = $readme->name;
     849                                $block->title = $block_name;
     850                                // If the block duplicates the namespace, remove it. 'plugin-slug/plugin-slug-block-name'
     851                                $block->title = preg_replace( '#^([^/]+)/\\1-?#i', '$1/', $block->title );
     852                                // Treat any non-wordy characters as spaces.
     853                                $block->title = preg_replace( '/[^a-z]+/', ' ', $block_name );
     854                                // Capitalise all words.
     855                                $block->title = ucwords( $block->title );
    848856                        }
    849857                }
Note: See TracChangeset for help on using the changeset viewer.