Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentyten/loop-attachment.php

    r32116 r42343  
    1616?>
    1717
    18 <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
     18<?php
     19if ( have_posts() ) {
     20    while ( have_posts() ) :
     21        the_post();
     22    ?>
    1923
    2024                <?php if ( ! empty( $post->post_parent ) ) : ?>
    21                     <p class="page-title"><a href="<?php echo esc_url( get_permalink( $post->post_parent ) ); ?>" title="<?php echo esc_attr( sprintf( __( 'Return to %s', 'twentyten' ), strip_tags( get_the_title( $post->post_parent ) ) ) ); ?>" rel="gallery"><?php
    22                         /* translators: %s - title of parent post */
    23                         printf( __( '<span class="meta-nav">&larr;</span> %s', 'twentyten' ), get_the_title( $post->post_parent ) );
    24                     ?></a></p>
     25                    <p class="page-title"><a href="<?php echo esc_url( get_permalink( $post->post_parent ) ); ?>" title="<?php echo esc_attr( sprintf( __( 'Return to %s', 'twentyten' ), strip_tags( get_the_title( $post->post_parent ) ) ) ); ?>" rel="gallery">
     26                                                                <?php
     27                                                                /* translators: %s - title of parent post */
     28                                                                printf( __( '<span class="meta-nav">&larr;</span> %s', 'twentyten' ), get_the_title( $post->post_parent ) );
     29                    ?>
     30                    </a></p>
    2531                <?php endif; ?>
    2632
    27                 <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
     33                    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    2834                    <h2 class="entry-title"><?php the_title(); ?></h2>
    2935
    3036                    <div class="entry-meta">
    3137                        <?php
    32                             printf( __( '<span class="%1$s">By</span> %2$s', 'twentyten' ),
     38                            printf(
     39                                __( '<span class="%1$s">By</span> %2$s', 'twentyten' ),
    3340                                'meta-prep meta-prep-author',
    34                                 sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
     41                                sprintf(
     42                                    '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
    3543                                    get_author_posts_url( get_the_author_meta( 'ID' ) ),
    3644                                    esc_attr( sprintf( __( 'View all posts by %s', 'twentyten' ), get_the_author() ) ),
     
    3846                                )
    3947                            );
    40                         ?>
    41                         <span class="meta-sep">|</span>
    42                         <?php
    43                             printf( __( '<span class="%1$s">Published</span> %2$s', 'twentyten' ),
     48                            ?>
     49                            <span class="meta-sep">|</span>
     50                            <?php
     51                            printf(
     52                                __( '<span class="%1$s">Published</span> %2$s', 'twentyten' ),
    4453                                'meta-prep meta-prep-entry-date',
    45                                 sprintf( '<span class="entry-date"><abbr class="published" title="%1$s">%2$s</abbr></span>',
     54                                sprintf(
     55                                    '<span class="entry-date"><abbr class="published" title="%1$s">%2$s</abbr></span>',
    4656                                    esc_attr( get_the_time() ),
    4757                                    get_the_date()
     
    5161                                echo ' <span class="meta-sep">|</span> ';
    5262                                $metadata = wp_get_attachment_metadata();
    53                                 printf( __( 'Full size is %s pixels', 'twentyten' ),
    54                                     sprintf( '<a href="%1$s" title="%2$s">%3$s &times; %4$s</a>',
     63                                printf(
     64                                    __( 'Full size is %s pixels', 'twentyten' ),
     65                                    sprintf(
     66                                        '<a href="%1$s" title="%2$s">%3$s &times; %4$s</a>',
    5567                                        esc_url( wp_get_attachment_url() ),
    5668                                        esc_attr( __( 'Link to full-size image', 'twentyten' ) ),
     
    6072                                );
    6173                            }
    62                         ?>
    63                         <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
    64                     </div><!-- .entry-meta -->
     74                            ?>
     75                            <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
     76                        </div><!-- .entry-meta -->
    6577
    66                     <div class="entry-content">
     78                        <div class="entry-content">
    6779                        <div class="entry-attachment">
    68 <?php if ( wp_attachment_is_image() ) :
    69     $attachments = array_values( get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) ) );
    70     foreach ( $attachments as $k => $attachment ) {
    71         if ( $attachment->ID == $post->ID )
    72             break;
    73     }
     80    <?php
     81    if ( wp_attachment_is_image() ) :
     82        $attachments = array_values(
     83            get_children(
     84                array(
     85                    'post_parent'    => $post->post_parent,
     86                    'post_status'    => 'inherit',
     87                    'post_type'      => 'attachment',
     88                    'post_mime_type' => 'image',
     89                    'order'          => 'ASC',
     90                    'orderby'        => 'menu_order ID',
     91                )
     92            )
     93        );
     94        foreach ( $attachments as $k => $attachment ) {
     95            if ( $attachment->ID == $post->ID ) {
     96                break;
     97            }
     98        }
    7499
    75     // If there is more than 1 image attachment in a gallery
    76     if ( count( $attachments ) > 1 ) {
    77         $k++;
    78         if ( isset( $attachments[ $k ] ) )
    79             // get the URL of the next image attachment
    80             $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
    81         else
    82             // or get the URL of the first image attachment
    83             $next_attachment_url = get_attachment_link( $attachments[0]->ID );
    84     } else {
    85         // or, if there's only 1 image attachment, get the URL of the image
    86         $next_attachment_url = wp_get_attachment_url();
    87     }
    88 ?>
    89                         <p class="attachment"><a href="<?php echo esc_url( $next_attachment_url ); ?>" title="<?php the_title_attribute(); ?>" rel="attachment"><?php
    90                             /**
    91                              * Filter the Twenty Ten default attachment width.
    92                              *
    93                              * @since Twenty Ten 1.0
    94                              *
    95                              * @param int The default attachment width in pixels. Default 900.
    96                              */
    97                             $attachment_width  = apply_filters( 'twentyten_attachment_size', 900 );
    98                             /**
    99                              * Filter the Twenty Ten default attachment height.
    100                              *
    101                              * @since Twenty Ten 1.0
    102                              *
    103                              * @param int The default attachment height in pixels. Default 900.
    104                              */
    105                             $attachment_height = apply_filters( 'twentyten_attachment_height', 900 );
    106                             echo wp_get_attachment_image( $post->ID, array( $attachment_width, $attachment_height ) ); // filterable image width with, essentially, no limit for image height.
    107                         ?></a></p>
     100        // If there is more than 1 image attachment in a gallery
     101        if ( count( $attachments ) > 1 ) {
     102            $k++;
     103            if ( isset( $attachments[ $k ] ) ) {
     104                // get the URL of the next image attachment
     105                $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
     106            } else {          // or get the URL of the first image attachment
     107                $next_attachment_url = get_attachment_link( $attachments[0]->ID );
     108            }
     109        } else {
     110            // or, if there's only 1 image attachment, get the URL of the image
     111            $next_attachment_url = wp_get_attachment_url();
     112        }
     113    ?>
     114                        <p class="attachment"><a href="<?php echo esc_url( $next_attachment_url ); ?>" title="<?php the_title_attribute(); ?>" rel="attachment">
     115                                                                    <?php
     116                                                                    /**
     117                                                                     * Filter the Twenty Ten default attachment width.
     118                                                                     *
     119                                                                     * @since Twenty Ten 1.0
     120                                                                     *
     121                                                                     * @param int The default attachment width in pixels. Default 900.
     122                                                                     */
     123                                                                    $attachment_width = apply_filters( 'twentyten_attachment_size', 900 );
     124                                                                    /**
     125                                                                     * Filter the Twenty Ten default attachment height.
     126                                                                     *
     127                                                                     * @since Twenty Ten 1.0
     128                                                                     *
     129                                                                     * @param int The default attachment height in pixels. Default 900.
     130                                                                     */
     131                                                                    $attachment_height = apply_filters( 'twentyten_attachment_height', 900 );
     132                                                                    echo wp_get_attachment_image( $post->ID, array( $attachment_width, $attachment_height ) ); // filterable image width with, essentially, no limit for image height.
     133                            ?>
     134                            </a></p>
    108135
    109                         <div id="nav-below" class="navigation">
     136                            <div id="nav-below" class="navigation">
    110137                            <div class="nav-previous"><?php previous_image_link( false ); ?></div>
    111138                            <div class="nav-next"><?php next_image_link( false ); ?></div>
    112139                        </div><!-- #nav-below -->
    113 <?php else : ?>
     140    <?php else : ?>
    114141                        <a href="<?php echo esc_url( wp_get_attachment_url() ); ?>" title="<?php the_title_attribute(); ?>" rel="attachment"><?php echo esc_html( basename( get_permalink() ) ); ?></a>
    115 <?php endif; ?>
     142    <?php endif; ?>
    116143                        </div><!-- .entry-attachment -->
    117                         <div class="entry-caption"><?php if ( ! empty( $post->post_excerpt ) ) the_excerpt(); ?></div>
     144                        <div class="entry-caption">
     145                        <?php
     146                        if ( ! empty( $post->post_excerpt ) ) {
     147                            the_excerpt();}
     148?>
     149</div>
    118150
    119 <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?>
    120 <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
     151    <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?>
     152    <?php
     153    wp_link_pages(
     154        array(
     155            'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ),
     156            'after'  => '</div>',
     157        )
     158    );
     159    ?>
    121160
    122161                    </div><!-- .entry-content -->
     
    130169<?php comments_template(); ?>
    131170
    132 <?php endwhile; // end of the loop. ?>
     171<?php endwhile;
     172}; // end of the loop. ?>
Note: See TracChangeset for help on using the changeset viewer.