WordPress.org

Making WordPress.org

Changeset 10256


Ignore:
Timestamp:
09/14/2020 10:39:58 PM (7 months ago)
Author:
ryelle
Message:

Plugin Directory: Filter blocks list to ensure main block is first

The Block Directory API endpoint (on individual WordPress sites) displays the title of the first block in the list. In most cases, there is only one block and this is fine. Other times, there may be child blocks, and in this case we want to make sure the parent block is used as the source of the title.

File:
1 edited

Legend:

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

    r10218 r10256  
    612612                $blocks[ $block_name ]->title = $trunk_readme->name;
    613613            }
     614        }
     615
     616        // Filter the blocks list so that the parent block is first.
     617        if ( count( $blocks ) > 1 ) {
     618            $children = array_filter(
     619                $blocks,
     620                function( $block ) {
     621                    return isset( $block->parent ) && count( $block->parent );
     622                }
     623            );
     624
     625            $parent = array_filter(
     626                $blocks,
     627                function( $block ) {
     628                    return ! isset( $block->parent ) || ! count( $block->parent );
     629                }
     630            );
     631
     632            $blocks = array_merge( $parent, $children );
    614633        }
    615634
Note: See TracChangeset for help on using the changeset viewer.