Making WordPress.org

Changeset 12319


Ignore:
Timestamp:
12/12/2022 03:55:38 AM (17 months ago)
Author:
dd32
Message:

Plugin Directory: Simplify the 'sections' titles, as we don't need anything more than the title here.

This replaces [12315-12318] with simpler code, as the cause was a previous design choice interacting with unexpected data.

Location:
sites/trunk/wordpress.org/public_html/wp-content
Files:
4 edited

Legend:

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

    r12318 r12319  
    332332
    333333    /**
    334      * Returns the available sections for a plugin.
    335      *
    336      * @static
    337      *
    338      * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
     334     * Returns the section names for plugins.
     335     *
     336     * @static
    339337     * @return array
    340338     */
    341     public static function get_plugin_sections( $post = null ) {
    342         $plugin = get_post( $post );
    343 
    344         $default_sections = array(
    345             'description',
    346             'screenshots',
    347             'faq',
    348             'blocks',
    349             'stats',
    350             'support',
    351             'reviews',
    352             'installation',
    353             'developers',
    354             'changelog',
    355         );
    356         if ( ! get_post_meta( $plugin->ID, 'assets_screenshots', true ) ) {
    357             unset( $default_sections[ array_search( 'screenshots', $default_sections ) ] );
    358         }
    359         if ( ! get_post_meta( $plugin->ID, 'all_blocks' ) ) {
    360             unset( $default_sections[ array_search( 'blocks', $default_sections ) ] );
    361         }
    362 
    363         $raw_sections = get_post_meta( $plugin->ID, 'sections', true ) ?: array();
    364         $raw_sections = array_unique( array_merge( $raw_sections, $default_sections ) );
    365 
    366         $sections  = array();
    367         $title     = '';
    368         $permalink = get_permalink();
    369 
    370         foreach ( $raw_sections as $section_slug ) {
    371             switch ( $section_slug ) {
    372 
    373                 case 'description':
    374                     $title = _x( 'Description', 'plugin tab title', 'wporg-plugins' );
    375                     break;
    376 
    377                 case 'installation':
    378                     $title = _x( 'Installation', 'plugin tab title', 'wporg-plugins' );
    379                     break;
    380 
    381                 case 'faq':
    382                     $title = _x( 'FAQ', 'plugin tab title', 'wporg-plugins' );
    383                     break;
    384 
    385                 case 'screenshots':
    386                     $title = _x( 'Screenshots', 'plugin tab title', 'wporg-plugins' );
    387                     break;
    388 
    389                 case 'changelog':
    390                     $title = _x( 'Changelog', 'plugin tab title', 'wporg-plugins' );
    391                     break;
    392 
    393                 case 'stats':
    394                     $title = _x( 'Stats', 'plugin tab title', 'wporg-plugins' );
    395                     break;
    396 
    397                 case 'support':
    398                     $title = _x( 'Support', 'plugin tab title', 'wporg-plugins' );
    399                     break;
    400 
    401                 case 'reviews':
    402                     $title = _x( 'Reviews', 'plugin tab title', 'wporg-plugins' );
    403                     break;
    404 
    405                 case 'developers':
    406                     $title = _x( 'Contributors & Developers', 'plugin tab title', 'wporg-plugins' );
    407                     break;
    408 
    409                 case 'other_notes':
    410                     $title = _x( 'Other Notes', 'plugin tab title', 'wporg-plugins' );
    411                     break;
    412 
    413                 case 'blocks':
    414                     $title = _x( 'Blocks', 'plugin tab title', 'wporg-plugins' );
    415                     break;
    416 
    417                 default:
    418                     // Skip ahead to the next section
    419                     continue 2;
    420             }
    421 
    422             $sections[] = array(
    423                 'slug'  => $section_slug,
    424                 'title' => $title,
    425             );
    426         }
    427 
    428         return $sections;
     339    public static function get_plugin_section_titles() {
     340        return [
     341            'description'  => _x( 'Description', 'plugin tab title', 'wporg-plugins' ),
     342            'installation' => _x( 'Installation', 'plugin tab title', 'wporg-plugins' ),
     343            'faq'          => _x( 'FAQ', 'plugin tab title', 'wporg-plugins' ),
     344            'screenshots'  => _x( 'Screenshots', 'plugin tab title', 'wporg-plugins' ),
     345            'changelog'    => _x( 'Changelog', 'plugin tab title', 'wporg-plugins' ),
     346            'stats'        => _x( 'Stats', 'plugin tab title', 'wporg-plugins' ),
     347            'support'      => _x( 'Support', 'plugin tab title', 'wporg-plugins' ),
     348            'reviews'      => _x( 'Reviews', 'plugin tab title', 'wporg-plugins' ),
     349            'developers'   => _x( 'Contributors & Developers', 'plugin tab title', 'wporg-plugins' ),
     350            'other_notes'  => _x( 'Other Notes', 'plugin tab title', 'wporg-plugins' ),
     351            'blocks'       => _x( 'Blocks', 'plugin tab title', 'wporg-plugins' ),
     352        ];
    429353    }
    430354
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/template-parts/plugin-single.php

    r12266 r12319  
    1313use WordPressdotorg\Plugin_Directory\Template;
    1414
    15 global $section, $section_slug, $section_content, $post;
     15global $section_slug, $section_title, $section_content, $post;
    1616
    1717$content   = Plugin_Directory::instance()->split_post_content_into_pages( get_the_content() );
     
    7979    <div class="entry-content">
    8080        <?php
    81         if ( get_query_var( 'plugin_advanced' ) ) :
     81        if ( get_query_var( 'plugin_advanced' ) ) {
    8282            get_template_part( 'template-parts/section-advanced' );
    83         else :
    84             $plugin_sections = Template::get_plugin_sections();
     83        } else {
     84            $plugin_sections_titles = Template::get_plugin_section_titles();
    8585
    86             foreach ( array( 'description', 'screenshots', 'blocks', 'installation', 'faq', 'reviews', 'developers', 'changelog' ) as $section_slug ) :
     86            foreach ( array( 'description', 'screenshots', 'blocks', 'installation', 'faq', 'reviews', 'developers', 'changelog' ) as $section_slug ) {
    8787                $section_content = '';
     88                $section_title   = $plugin_sections_titles[ $section_slug ] ?? '';
    8889
    89                 if ( 'description' === $section_slug && $is_closed ) {
     90                if ( $is_closed && in_array( $section_slug, [ 'screenshots', 'installation', 'faq', 'changelog' ], true ) ) {
     91                    // Don't show these sections when closed.
     92                    $section_content = '';
     93
     94                } elseif ( $is_closed && 'description' === $section_slug ) {
    9095                    // Don't show the description for closed plugins, show a notice instead.
    9196                    $section_content = get_closed_plugin_notice();
     
    9398                } elseif ( 'blocks' === $section_slug ) {
    9499                    $section_content = get_post_meta( get_the_ID(), 'all_blocks', true );
    95                 } elseif ( ! in_array( $section_slug, [ 'screenshots', 'installation', 'faq', 'changelog' ], true ) || ! $is_closed ) {
    96                     if ( isset( $content[ $section_slug ] ) ) {
    97                         $section_content = trim( apply_filters( 'the_content', $content[ $section_slug ], $section_slug ) );
    98                     }
     100
     101                } elseif ( isset( $content[ $section_slug ] ) ) {
     102                    $section_content = trim( apply_filters( 'the_content', $content[ $section_slug ], $section_slug ) );
    99103                }
    100104
     
    103107                }
    104108
    105                 $section = wp_list_filter( $plugin_sections, array( 'slug' => $section_slug ) );
    106                 $section = array_pop( $section );
    107 
    108                 if ( 'blocks' === $section_slug ) {
    109                     get_template_part( 'template-parts/section-blocks' );
    110                 } else {
    111                     get_template_part( 'template-parts/section' );
    112                 }
    113             endforeach;
    114         endif; // plugin_advanced.
     109                get_template_part( 'template-parts/section', $section_slug );
     110            }
     111        } // plugin_advanced.
    115112        ?>
    116113    </div><!-- .entry-content -->
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/template-parts/section-blocks.php

    r11355 r12319  
    88 */
    99
    10 global $section, $section_slug, $section_content;
     10global $section_slug, $section_title, $section_content;
    1111
    1212$prefix = in_array( $section_slug, array( 'screenshots', 'faq', 'blocks' ), true ) ? '' : 'tab-';
     
    3737
    3838<div id="<?php echo esc_attr( $prefix . $section_slug ); ?>" class="<?php echo esc_attr( $classes ); ?>">
    39     <h2 id="<?php echo esc_attr( $section_slug . '-header' ); ?>"><?php echo esc_html( $section['title'] ); ?></h2>
     39    <h2 id="<?php echo esc_attr( $section_slug . '-header' ); ?>"><?php echo esc_html( $section_title ); ?></h2>
    4040
    4141    <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>
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/template-parts/section.php

    r8882 r12319  
    88 */
    99
    10 global $section, $section_slug, $section_content;
     10global $section_slug, $section_title, $section_content;
    1111
    1212$prefix = in_array( $section_slug, array( 'screenshots', 'faq' ), true ) ? '' : 'tab-';
     
    1717
    1818<div id="<?php echo esc_attr( $prefix . $section_slug ); ?>" class="<?php echo esc_attr( $classes ); ?>">
    19     <h2 id="<?php echo esc_attr( $section_slug . '-header' ); ?>"><?php echo esc_html( $section['title'] ); ?></h2>
     19    <h2 id="<?php echo esc_attr( $section_slug . '-header' ); ?>"><?php echo esc_html( $section_title ); ?></h2>
    2020    <?php echo $section_content; ?>
    2121</div>
Note: See TracChangeset for help on using the changeset viewer.