Making WordPress.org


Ignore:
Timestamp:
12/08/2017 05:37:23 PM (9 years ago)
Author:
obenland
Message:

Plugins: Simplify template logic.

Moves most of the logic into template tags to make the single-plugin template it bit easier to understand.

Props joostdevalk.
Fixes #3310.

File:
1 edited

Legend:

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

    r6232 r6251  
    1111use WordPressdotorg\Plugin_Directory\Plugin_Directory;
    1212use WordPressdotorg\Plugin_Directory\Template;
    13 use WordPressdotorg\Plugin_Directory\Tools;
    14 global $section, $section_slug, $section_content, $section_read_more;
    1513
    16 $content = Plugin_Directory::instance()->split_post_content_into_pages( get_the_content() );
    17 $status  = get_post_status();
     14global $section, $section_slug, $section_content, $section_read_more, $post;
    1815
    19 ?><article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    20     <?php
    21     // Don't show the plugin banner for closed plugins
    22     if ( ! in_array( $status, array( 'closed', 'disabled' ) ) ) {
    23             echo Template::get_plugin_banner( get_post(), 'html' );
    24     }
    25     ?>
     16$content   = Plugin_Directory::instance()->split_post_content_into_pages( get_the_content() );
     17$is_closed = in_array( get_post_status(), ['closed', 'disabled'], true );
     18?>
     19
     20<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
     21        <?php the_plugin_banner(); ?>
    2622
    2723        <header class="plugin-header">
    28                 <?php if ( time() - get_post_modified_time() > 2 * YEAR_IN_SECONDS ) : ?>
    29                         <div class="plugin-notice notice notice-warning notice-alt">
    30                                 <p><?php _e( 'This plugin <strong>hasn&#146;t been updated in over 2 years</strong>. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.', 'wporg-plugins' ); ?></p>
    31                         </div>
    32                 <?php endif; ?>
    33                 <?php if ( 'publish' !== $status ) :
    34                                 $notice_type = 'notice-error';
    35                                 switch ( $status ) {
    36                                         case 'draft':
    37                                         case 'pending':
    38                                                 $message = __( 'This plugin is requested and not visible to the public yet. Please be patient as your plugin gets reviewed.', 'wporg-plugins' );
    39                                                 $notice_type = 'notice-info';
    40                                                 break;
    41 
    42                                         case 'approved':
    43                                                 $message = __( 'This plugin is approved and awaiting data upload but not visible to the public yet. Once you make your first commit, the plugin will become public.', 'wporg-plugins' );
    44                                                 $notice_type = 'notice-info';
    45                                                 break;
    46 
    47                                         case 'rejected':
    48                                                 $message = __( 'This plugin has been rejected and is not visible to the public.', 'wporg-plugins' );
    49                                                 break;
    50 
    51                                         case 'disabled':
    52                                                 if ( current_user_can( 'plugin_approve' ) ) {
    53                                                         $message = __( 'This plugin is disabled (closed, but actively serving updates).', 'wporg-plugins' );
    54                                                         break;
    55                                                 } else {
    56                                                         $message = __( 'This plugin has been closed for new installs.', 'wporg-plugins' );
    57                                                         break;
    58                                                 }
    59                                                 // fall through
    60                                         default:
    61                                         case 'closed':
    62                                                 $message = __( 'This plugin has been closed and is no longer available for download.', 'wporg-plugins' );
    63                                                 break;
    64                                 }
    65 
    66             if ( in_array( $status, array( 'closed', 'disabled' ) ) ) {
    67                     $closed_date    = get_post_meta( get_the_ID(), 'plugin_closed_date', true );
    68                     if ( ! empty( $closed_date ) ) {
    69                             $message .= '<br/>';
    70                                         $message .= sprintf( __( 'This plugin was closed on %s.', 'wporg-plugins' ), mysql2date( get_option( 'date_format' ), $closed_date ) );
    71                                 }
    72             }
    73 
    74                 if ( ! in_array( $status, array( 'closed', 'disabled' ) ) ) {
    75                                     // the notice for closed and disabled is shown below the Description header, because we don't output the readme there
    76                         ?>
    77             <!-- .plugin-notice -->
    78                         <div class="plugin-notice notice <?php echo esc_attr( $notice_type ); ?> notice-alt">
    79                                 <p><?php echo $message; ?></p>
    80                         </div>
    81             <!-- .plugin-notice -->
    82         <?php } ?>
    83                 <?php endif; ?>
     24                <?php the_active_plugin_notice(); ?>
    8425
    8526                <div class="entry-thumbnail">
    86                         <?php echo Template::get_plugin_icon( get_post(), 'html' ); ?>
     27                        <?php echo Template::get_plugin_icon( $post, 'html' ); ?>
    8728                </div>
    8829
    8930                <div class="plugin-actions">
    90                         <?php
    91                         if ( is_user_logged_in() ) :
    92                                 $url = Template::get_favorite_link();
    93                                 $is_favorited = Tools::favorited_plugin( $post );
    94                                 ?>
    95                                 <div class="plugin-favorite">
    96                                         <a href="<?php echo esc_url( $url ); ?>" class="plugin-favorite-heart<?php echo $is_favorited ? ' favorited' : ''; ?>">
    97                                                 <span class="screen-reader-text">
    98                                                         <?php
    99                                                                 if ( $is_favorited ) {
    100                                                                         /* translators: %s: plugin name */
    101                                                                         printf( __( 'Unfavorite %s', 'wporg-plugins' ), get_the_title() );
    102                                                                 } else {
    103                                                                         /* translators: %s: plugin name */
    104                                                                         printf( __( 'Favorite %s', 'wporg-plugins' ), get_the_title() );
    105                                                                 }
    106                                                         ?>
    107                                                 </span>
    108                                         </a>
    109                                         <script>
    110                                                 jQuery( '.plugin-favorite-heart' )
    111                                                         .on( 'click touchstart animationend', function() {
    112                                                                 jQuery( this ).toggleClass( 'is-animating' );
    113                                                         } )
    114                                                         .on( 'click', function() {
    115                                                                 jQuery( this ).toggleClass( 'favorited' );
    116                                                         } );
    117                                         </script>
    118                                 </div>
    119                         <?php endif; ?>
     31                        <?php the_plugin_favorite_button(); ?>
    12032
    121                         <?php if ( 'publish' === get_post_status() || current_user_can( 'plugin_admin_view', get_post() ) ) : ?>
     33                        <?php if ( 'publish' === get_post_status() || current_user_can( 'plugin_admin_view', $post ) ) : ?>
    12234                                <a class="plugin-download button download-button button-large" href="<?php echo esc_url( Template::download_link() ); ?>"><?php _e( 'Download', 'wporg-plugins' ); ?></a>
    12335                        <?php endif; ?>
    12436                </div>
    125        
    126                 <?php
    127                 if ( in_array( $status, array( 'closed', 'disabled' ) ) ) {
    128                         $plugin_title = $post->post_name;
    129                 } else {
    130                         $plugin_title = get_the_title();
    131                 }
    132                 ?>
     37
     38                <?php $plugin_title = $is_closed ? $post->post_name : get_the_title(); ?>
    13339                <h1 class="plugin-title"><a href="<?php echo esc_url( get_permalink() ); ?>"><?php echo $plugin_title; ?></a></h1>
    13440
    135                 <span class="byline"><?php
    136                         $url = get_post_meta( get_the_ID(), 'header_author_uri', true );
    137                         $author = strip_tags( get_post_meta( get_the_ID(), 'header_author', true ) ) ?: get_the_author();
    138 
    139                         printf(
    140                                 _x( 'By %s', 'post author', 'wporg-plugins' ),
    141                                 '<span class="author vcard">' .
    142                                 ( $url ? '<a class="url fn n" rel="nofollow" href="' . esc_url( $url ) . '">' : '' ) .
    143                                 esc_html( Template::encode( $author ) ) .
    144                                 ( $url ? '</a>' : '' ) .
    145                                 '</span>'
    146                         );
    147                 ?></span>
     41                <span class="byline"><?php the_author_byline(); ?></span>
    14842        </header><!-- .entry-header -->
    14943
    150 <?php if ( ! get_query_var( 'plugin_advanced' ) ) { ?>
    151         <span id="description"></span>
    152         <span id="reviews"></span>
    153         <span id="installation"></span>
    154         <span id="developers"></span>
    155         <ul class="tabs clear">
    156                 <li id="tablink-description"><a href='#description'><?php _e( 'Details', 'wporg-plugins' ); ?></a></li>
    157                 <li id="tablink-reviews"><a href='#reviews'><?php _e( 'Reviews', 'wporg-plugins' ); ?></a></li>
    158 <?php if ( isset( $content[ 'installation' ] ) && ! in_array( $status, array( 'closed', 'disabled' ) ) ) { ?>
    159                 <li id="tablink-installation"><a href='#installation'><?php _e( 'Installation', 'wporg-plugins' ); ?></a></li>
    160 <?php } ?>
    161                 <li id="tablink-support"><a href='<?php echo Template::get_support_url(); ?>'><?php _e( 'Support', 'wporg-plugins' ); ?></a></li>
    162                 <li id="tablink-developers"><a href='#developers'><?php _e( 'Development', 'wporg-plugins' ); ?></a></li>
    163     </ul>
    164 <?php } ?>
     44        <?php if ( ! get_query_var( 'plugin_advanced' ) ) : ?>
     45                <span id="description"></span>
     46                <span id="reviews"></span>
     47                <span id="installation"></span>
     48                <span id="developers"></span>
     49                <ul class="tabs clear">
     50                        <li id="tablink-description"><a href="#description"><?php _e( 'Details', 'wporg-plugins' ); ?></a></li>
     51                        <li id="tablink-reviews"><a href="#reviews"><?php _e( 'Reviews', 'wporg-plugins' ); ?></a></li>
     52                        <?php if ( isset( $content['installation'] ) && ! $is_closed ) : ?>
     53                                <li id="tablink-installation">
     54                                        <a href="#installation"><?php _e( 'Installation', 'wporg-plugins' ); ?></a>
     55                                </li>
     56                        <?php endif; ?>
     57                        <li id="tablink-support">
     58                                <a href="<?php echo esc_url( Template::get_support_url() ); ?>"><?php _e( 'Support', 'wporg-plugins' ); ?></a>
     59                        </li>
     60                        <li id="tablink-developers"><a href="#developers"><?php _e( 'Development', 'wporg-plugins' ); ?></a></li>
     61                </ul>
     62        <?php endif; ?>
     63
    16564        <div class="entry-content">
    16665                <?php
    16766                if ( get_query_var( 'plugin_advanced' ) ) :
    16867                        get_template_part( 'template-parts/section-advanced' );
    169                 else:
     68                else :
    17069                        $plugin_sections = Template::get_plugin_sections();
    171 
    17270                        foreach ( array( 'description', 'screenshots', 'installation', 'faq', 'reviews', 'developers', 'changelog' ) as $section_slug ) :
    17371                                if ( ! isset( $content[ $section_slug ] ) ) {
    … …  
    17573                                }
    17674
    177                                 if ( 'description' === $section_slug && in_array( $status, array( 'closed', 'disabled' ) ) ) {
    178                                 // Don't show the description for closed plugins
    179                                         $section_content = '<div class="plugin-notice notice notice-error notice-alt"><p>' . $message . '</p></div>';
    180                             if ( get_current_user_id() == get_post()->post_author ) {
    181                                     $section_content .= '<div class="plugin-notice notice notice-info notice-alt"><p>' .
    182                                                         sprintf(
    183                                                         /* translators: 1: plugins@wordpress.org */
    184                                                                 __( 'If you did not request this change, please contact <a href="mailto:%1$s">%1$s</a> for a status. All developers with commit access are contacted when a plugin is closed, with the reasons why, so check your spam email too.', 'wporg-plugins' ),
    185                                                                 'plugins@wordpress.org'
    186                                                         ) . '</p></div><!-- .plugin-notice -->';
    187                             }
    188                                 }
    189                                 else if ( in_array( $section_slug, array( 'screenshots', 'installation', 'faq', 'changelog' ) ) && in_array( $status, array( 'closed', 'disabled' ) ) ) {
    190                                 $section_content = '';
    191                                 }
    192                                 else {
     75                                $section_content = '';
     76
     77                                if ( 'description' === $section_slug && $is_closed ) {
     78                                        // Don't show the description for closed plugins.
     79                                        $section_content = get_closed_plugin_notice();
     80
     81                                } else if ( ! in_array( $section_slug, ['screenshots', 'installation', 'faq', 'changelog'], true ) || ! $is_closed ) {
    19382                                        $section_content = trim( apply_filters( 'the_content', $content[ $section_slug ], $section_slug ) );
    19483                                }
    … …  
    20291
    20392                                $section_no_read_mores = array( 'description', 'screenshots', 'installation', 'faq', 'reviews' );
    204                                 // If the FAQ section is the newer `<dl>` form, no need to do read-more for it.
     93                                // If the FAQ section is the newer `<dl>` form, no need to do readmore for it.
    20594                                if ( false !== stripos( $section_content, '<dl>' ) ) {
    20695                                        $section_no_read_mores[] = 'faq';
    … …  
    216105
    217106        <div class="entry-meta">
    218                 <?php
    219                 get_template_part( 'template-parts/plugin-sidebar', ( get_query_var( 'plugin_advanced' ) ? 'advanced' : '' ) );
    220                 ?>
     107                <?php get_template_part( 'template-parts/plugin-sidebar', get_query_var( 'plugin_advanced' ) ? 'advanced' : '' ); ?>
    221108        </div><!-- .entry-meta -->
    222109</article><!-- #post-## -->
Note: See TracChangeset for help on using the changeset viewer.