Making WordPress.org


Ignore:
Timestamp:
11/11/2020 04:23:45 PM (4 years ago)
Author:
ryelle
Message:

Plugin Directory: Show available block names, icons, and descriptions.

Props michael-arestad for design.
Fixes #5411.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/template-parts/section-blocks.php

    r8544 r10440  
    1414$classes = [ 'plugin-' . $section_slug, 'section' ];
    1515$classes = implode( ' ', $classes );
     16
     17$allowed_svg = array(
     18    'svg'   => array(
     19        'class' => true,
     20        'aria-hidden' => true,
     21        'aria-labelledby' => true,
     22        'role' => true,
     23        'xmlns' => true,
     24        'width' => true,
     25        'height' => true,
     26        'viewbox' => true,
     27    ),
     28    'g'     => array( 'fill' => true ),
     29    'title' => array( 'title' => true ),
     30    'path'  => array(
     31        'd' => true,
     32        'fill' => true,
     33        'transform' => true,
     34    ),
     35);
    1636?>
    1737
     
    2040
    2141    <p><?php printf( esc_html( _n( 'This plugin provides %d block.', 'This plugin provides %d blocks.', count( $section_content ), 'wporg-plugins'  ) ), count( $section_content ) ); ?></p>
    22     <dl>
    23         <?php foreach ( $section_content as $block ) : ?>
    24             <dt><?php if ( isset( $block->name ) ) echo esc_html( $block->name ); ?></dt>
    25                 <dd><?php if ( isset( $block->title ) ) echo esc_html( $block->title ); ?></dd>
     42    <ul class="plugin-blocks-list">
     43        <?php
     44        foreach ( $section_content as $block ) :
     45            $block_name = isset( $block->title ) ? $block->title : false;
     46            if ( ! $block_name ) {
     47                $block_name = isset( $block->name ) ? $block->name : false;
     48            }
     49            if ( ! $block_name ) {
     50                // If we still have no name, we don't have a valid block.
     51                continue;
     52            }
     53            $block_icon = isset( $block->icon ) ? $block->icon : '';
     54            $block_classes = 'plugin-blocks-list-item';
     55            $block_classes .= isset( $block->description ) ? ' has-description' : '';
     56            ?>
     57            <li class="<?php echo esc_attr( $block_classes ); ?>">
     58                <?php if ( false !== strpos( $block_icon, '<svg' ) ) : ?>
     59                    <span class="block-icon">
     60                        <?php echo wp_kses( str_replace( '<svg ', '<svg role="img" aria-hidden="true" focusable="false" ', $block_icon ), $allowed_svg ); ?>
     61                    </span>
     62                <?php elseif ( $block_icon ) : ?>
     63                    <span class="block-icon dashicons dashicons-<?php echo esc_attr( $block->icon ); ?>"></span>
     64                <?php else : ?>
     65                    <span class="block-icon dashicons dashicons-block-default"></span>
     66                <?php endif; ?>
     67                <span class="block-title"><?php echo esc_html( $block_name ); ?></span>
     68                <?php if ( isset( $block->description ) ) : ?>
     69                    <span class="block-description"><?php echo esc_html( $block->description ); ?></dd>
     70                <?php endif; ?>
     71            </li>
    2672        <?php endforeach; ?>
    27     </dl>
     73    </ul>
    2874</div>
Note: See TracChangeset for help on using the changeset viewer.