Make WordPress Core


Ignore:
Timestamp:
08/17/2018 01:50:26 AM (8 years ago)
Author:
pento
Message:

Coding Standards: Upgrade WPCS to 1.0.0

WPCS 1.0.0 includes a bunch of new auto-fixers, which drops the number of coding standards issues across WordPress significantly. Prior to running the auto-fixers, there were 15,312 issues detected. With this commit, we now drop to 4,769 issues.

This change includes three notable additions:

  • Multiline function calls must now put each parameter on a new line.
  • Auto-formatting files is now part of the grunt precommit script.
  • Auto-fixable coding standards issues will now cause Travis failures.

Fixes #44600.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/custom-header.php

    r42719 r43571  
    381381})(jQuery);
    382382</script>
    383 <?php
     383                <?php
    384384        }
    385385
    … …  
    391391        public function js_2() {
    392392
    393         ?>
     393                ?>
    394394<script type="text/javascript">
    395395        function onEndCrop( coords ) {
    … …  
    427427                        <?php
    428428                        if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) ) {
    429                         ?>
     429                                ?>
    430430                        aspectRatio: xinit + ':' + yinit,
    431                         <?php
     431                                <?php
    432432                        }
    433433                        if ( ! current_theme_supports( 'custom-header', 'flex-height' ) ) {
    434                         ?>
     434                                ?>
    435435                        maxHeight: <?php echo get_theme_support( 'custom-header', 'height' ); ?>,
    436                         <?php
     436                                <?php
    437437                        }
    438438                        if ( ! current_theme_supports( 'custom-header', 'flex-width' ) ) {
    439                         ?>
     439                                ?>
    440440                        maxWidth: <?php echo get_theme_support( 'custom-header', 'width' ); ?>,
    441                         <?php
     441                                <?php
    442442                        }
    443443                        ?>
    … …  
    455455        });
    456456</script>
    457 <?php
     457                <?php
    458458        }
    459459
    … …  
    465465        public function step_1() {
    466466                $this->process_default_headers();
    467 ?>
     467                ?>
    468468
    469469<div class="wrap">
    470470<h1><?php _e( 'Custom Header' ); ?></h1>
    471471
    472 <?php if ( current_user_can( 'customize' ) ) { ?>
     472                <?php if ( current_user_can( 'customize' ) ) { ?>
    473473<div class="notice notice-info hide-if-no-customize">
    474474        <p>
    475                 <?php
    476                 printf(
    477                         __( 'You can now manage and live-preview Custom Header in the <a href="%1$s">Customizer</a>.' ),
    478                         admin_url( 'customize.php?autofocus[control]=header_image' )
    479                 );
    480                 ?>
     475                        <?php
     476                                printf(
     477                                        __( 'You can now manage and live-preview Custom Header in the <a href="%1$s">Customizer</a>.' ),
     478                                        admin_url( 'customize.php?autofocus[control]=header_image' )
     479                                );
     480                        ?>
    481481        </p>
    482482</div>
    483 <?php } ?>
    484 
    485 <?php if ( ! empty( $this->updated ) ) { ?>
     483                <?php } ?>
     484
     485                <?php if ( ! empty( $this->updated ) ) { ?>
    486486<div id="message" class="updated">
    487487<p><?php printf( __( 'Header updated. <a href="%s">Visit your site</a> to see how it looks.' ), home_url( '/' ) ); ?></p>
    488488</div>
    489 <?php } ?>
     489                <?php } ?>
    490490
    491491<h3><?php _e( 'Header Image' ); ?></h3>
    … …  
    494494<tbody>
    495495
    496 <?php if ( get_custom_header() || display_header_text() ) : ?>
     496                <?php if ( get_custom_header() || display_header_text() ) : ?>
    497497<tr>
    498498<th scope="row"><?php _e( 'Preview' ); ?></th>
    499499<td>
    500         <?php
    501         if ( $this->admin_image_div_callback ) {
    502                 call_user_func( $this->admin_image_div_callback );
    503         } else {
    504                 $custom_header = get_custom_header();
    505                 $header_image  = get_header_image();
    506 
    507                 if ( $header_image ) {
    508                         $header_image_style = 'background-image:url(' . esc_url( $header_image ) . ');';
    509                 } else {
    510                         $header_image_style = '';
    511                 }
    512 
    513                 if ( $custom_header->width ) {
    514                         $header_image_style .= 'max-width:' . $custom_header->width . 'px;';
    515                 }
    516                 if ( $custom_header->height ) {
    517                         $header_image_style .= 'height:' . $custom_header->height . 'px;';
    518                 }
    519         ?>
     500                        <?php
     501                        if ( $this->admin_image_div_callback ) {
     502                                call_user_func( $this->admin_image_div_callback );
     503                        } else {
     504                                $custom_header = get_custom_header();
     505                                $header_image  = get_header_image();
     506
     507                                if ( $header_image ) {
     508                                        $header_image_style = 'background-image:url(' . esc_url( $header_image ) . ');';
     509                                } else {
     510                                        $header_image_style = '';
     511                                }
     512
     513                                if ( $custom_header->width ) {
     514                                        $header_image_style .= 'max-width:' . $custom_header->width . 'px;';
     515                                }
     516                                if ( $custom_header->height ) {
     517                                        $header_image_style .= 'height:' . $custom_header->height . 'px;';
     518                                }
     519                                ?>
    520520        <div id="headimg" style="<?php echo $header_image_style; ?>">
    521                 <?php
    522                 if ( display_header_text() ) {
    523                         $style = ' style="color:#' . get_header_textcolor() . ';"';
    524                 } else {
    525                         $style = ' style="display:none;"';
    526                 }
    527                 ?>
     521                                <?php
     522                                if ( display_header_text() ) {
     523                                        $style = ' style="color:#' . get_header_textcolor() . ';"';
     524                                } else {
     525                                        $style = ' style="display:none;"';
     526                                }
     527                                ?>
    528528                <h1><a id="name" class="displaying-header-text" <?php echo $style; ?> onclick="return false;" href="<?php bloginfo( 'url' ); ?>" tabindex="-1"><?php bloginfo( 'name' ); ?></a></h1>
    529529                <div id="desc" class="displaying-header-text" <?php echo $style; ?>><?php bloginfo( 'description' ); ?></div>
    530530        </div>
    531         <?php } ?>
     531                        <?php } ?>
    532532</td>
    533533</tr>
    534 <?php endif; ?>
    535 
    536 <?php if ( current_user_can( 'upload_files' ) && current_theme_supports( 'custom-header', 'uploads' ) ) : ?>
     534                <?php endif; ?>
     535
     536                <?php if ( current_user_can( 'upload_files' ) && current_theme_supports( 'custom-header', 'uploads' ) ) : ?>
    537537<tr>
    538538<th scope="row"><?php _e( 'Select Image' ); ?></th>
    539539<td>
    540540        <p><?php _e( 'You can select an image to be shown at the top of your site by uploading from your computer or choosing from your media library. After selecting an image you will be able to crop it.' ); ?><br />
    541         <?php
    542         if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) ) {
    543                 printf( __( 'Images of exactly <strong>%1$d &times; %2$d pixels</strong> will be used as-is.' ) . '<br />', get_theme_support( 'custom-header', 'width' ), get_theme_support( 'custom-header', 'height' ) );
    544         } elseif ( current_theme_supports( 'custom-header', 'flex-height' ) ) {
    545                 if ( ! current_theme_supports( 'custom-header', 'flex-width' ) ) {
    546                         printf(
    547                                 /* translators: %s: size in pixels */
    548                                 __( 'Images should be at least %s wide.' ) . ' ',
    549                                 sprintf(
    550                                         /* translators: %d: custom header width */
    551                                         '<strong>' . __( '%d pixels' ) . '</strong>',
    552                                         get_theme_support( 'custom-header', 'width' )
    553                                 )
    554                         );
    555                 }
    556         } elseif ( current_theme_supports( 'custom-header', 'flex-width' ) ) {
    557                 if ( ! current_theme_supports( 'custom-header', 'flex-height' ) ) {
    558                         printf(
    559                                 /* translators: %s: size in pixels */
    560                                 __( 'Images should be at least %s tall.' ) . ' ',
    561                                 sprintf(
    562                                         /* translators: %d: custom header height */
    563                                         '<strong>' . __( '%d pixels' ) . '</strong>',
    564                                         get_theme_support( 'custom-header', 'height' )
    565                                 )
    566                         );
    567                 }
    568         }
    569         if ( current_theme_supports( 'custom-header', 'flex-height' ) || current_theme_supports( 'custom-header', 'flex-width' ) ) {
    570                 if ( current_theme_supports( 'custom-header', 'width' ) ) {
    571                         printf(
    572                                 /* translators: %s: size in pixels */
    573                                 __( 'Suggested width is %s.' ) . ' ',
    574                                 sprintf(
    575                                         /* translators: %d: custom header width */
    576                                         '<strong>' . __( '%d pixels' ) . '</strong>',
    577                                         get_theme_support( 'custom-header', 'width' )
    578                                 )
    579                         );
    580                 }
    581                 if ( current_theme_supports( 'custom-header', 'height' ) ) {
    582                         printf(
    583                                 /* translators: %s: size in pixels */
    584                                 __( 'Suggested height is %s.' ) . ' ',
    585                                 sprintf(
    586                                         /* translators: %d: custom header height */
    587                                         '<strong>' . __( '%d pixels' ) . '</strong>',
    588                                         get_theme_support( 'custom-header', 'height' )
    589                                 )
    590                         );
    591                 }
    592         }
    593         ?>
     541                        <?php
     542                        if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) ) {
     543                                printf( __( 'Images of exactly <strong>%1$d &times; %2$d pixels</strong> will be used as-is.' ) . '<br />', get_theme_support( 'custom-header', 'width' ), get_theme_support( 'custom-header', 'height' ) );
     544                        } elseif ( current_theme_supports( 'custom-header', 'flex-height' ) ) {
     545                                if ( ! current_theme_supports( 'custom-header', 'flex-width' ) ) {
     546                                        printf(
     547                                                /* translators: %s: size in pixels */
     548                                                __( 'Images should be at least %s wide.' ) . ' ',
     549                                                sprintf(
     550                                                        /* translators: %d: custom header width */
     551                                                        '<strong>' . __( '%d pixels' ) . '</strong>',
     552                                                        get_theme_support( 'custom-header', 'width' )
     553                                                )
     554                                        );
     555                                }
     556                        } elseif ( current_theme_supports( 'custom-header', 'flex-width' ) ) {
     557                                if ( ! current_theme_supports( 'custom-header', 'flex-height' ) ) {
     558                                        printf(
     559                                                /* translators: %s: size in pixels */
     560                                                __( 'Images should be at least %s tall.' ) . ' ',
     561                                                sprintf(
     562                                                        /* translators: %d: custom header height */
     563                                                        '<strong>' . __( '%d pixels' ) . '</strong>',
     564                                                        get_theme_support( 'custom-header', 'height' )
     565                                                )
     566                                        );
     567                                }
     568                        }
     569                        if ( current_theme_supports( 'custom-header', 'flex-height' ) || current_theme_supports( 'custom-header', 'flex-width' ) ) {
     570                                if ( current_theme_supports( 'custom-header', 'width' ) ) {
     571                                        printf(
     572                                                /* translators: %s: size in pixels */
     573                                                __( 'Suggested width is %s.' ) . ' ',
     574                                                sprintf(
     575                                                        /* translators: %d: custom header width */
     576                                                        '<strong>' . __( '%d pixels' ) . '</strong>',
     577                                                        get_theme_support( 'custom-header', 'width' )
     578                                                )
     579                                        );
     580                                }
     581                                if ( current_theme_supports( 'custom-header', 'height' ) ) {
     582                                        printf(
     583                                                /* translators: %s: size in pixels */
     584                                                __( 'Suggested height is %s.' ) . ' ',
     585                                                sprintf(
     586                                                        /* translators: %d: custom header height */
     587                                                        '<strong>' . __( '%d pixels' ) . '</strong>',
     588                                                        get_theme_support( 'custom-header', 'height' )
     589                                                )
     590                                        );
     591                                }
     592                        }
     593                        ?>
    594594        </p>
    595595        <form enctype="multipart/form-data" id="upload-form" class="wp-upload-form" method="post" action="<?php echo esc_url( add_query_arg( 'step', 2 ) ); ?>">
    … …  
    598598                <input type="file" id="upload" name="import" />
    599599                <input type="hidden" name="action" value="save" />
    600                 <?php wp_nonce_field( 'custom-header-upload', '_wpnonce-custom-header-upload' ); ?>
    601                 <?php submit_button( __( 'Upload' ), '', 'submit', false ); ?>
     600                        <?php wp_nonce_field( 'custom-header-upload', '_wpnonce-custom-header-upload' ); ?>
     601                        <?php submit_button( __( 'Upload' ), '', 'submit', false ); ?>
    602602        </p>
    603         <?php
    604                 $modal_update_href = esc_url(
    605                         add_query_arg(
    606                                 array(
    607                                         'page'                          => 'custom-header',
    608                                         'step'                          => 2,
    609                                         '_wpnonce-custom-header-upload' => wp_create_nonce( 'custom-header-upload' ),
    610                                 ), admin_url( 'themes.php' )
    611                         )
    612                 );
    613         ?>
     603                        <?php
     604                                $modal_update_href = esc_url(
     605                                        add_query_arg(
     606                                                array(
     607                                                        'page' => 'custom-header',
     608                                                        'step' => 2,
     609                                                        '_wpnonce-custom-header-upload' => wp_create_nonce( 'custom-header-upload' ),
     610                                                ),
     611                                                admin_url( 'themes.php' )
     612                                        )
     613                                );
     614                        ?>
    614615        <p>
    615616                <label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br />
    … …  
    622623</td>
    623624</tr>
    624 <?php endif; ?>
     625                <?php endif; ?>
    625626</tbody>
    626627</table>
    627628
    628629<form method="post" action="<?php echo esc_url( add_query_arg( 'step', 1 ) ); ?>">
    629 <?php submit_button( null, 'screen-reader-text', 'save-header-options', false ); ?>
     630                <?php submit_button( null, 'screen-reader-text', 'save-header-options', false ); ?>
    630631<table class="form-table">
    631632<tbody>
    632         <?php if ( get_uploaded_header_images() ) : ?>
     633                <?php if ( get_uploaded_header_images() ) : ?>
    633634<tr>
    634635<th scope="row"><?php _e( 'Uploaded Images' ); ?></th>
    635636<td>
    636637        <p><?php _e( 'You can choose one of your previously uploaded headers, or show a random one.' ); ?></p>
    637         <?php
    638                 $this->show_header_selector( 'uploaded' );
    639         ?>
     638                        <?php
     639                        $this->show_header_selector( 'uploaded' );
     640                        ?>
    640641</td>
    641642</tr>
    642         <?php
     643                        <?php
    643644        endif;
    644645if ( ! empty( $this->default_headers ) ) :
    … …  
    647648<th scope="row"><?php _e( 'Default Images' ); ?></th>
    648649<td>
    649 <?php if ( current_theme_supports( 'custom-header', 'uploads' ) ) : ?>
     650        <?php if ( current_theme_supports( 'custom-header', 'uploads' ) ) : ?>
    650651        <p><?php _e( 'If you don&lsquo;t want to upload your own image, you can use one of these cool headers, or show a random one.' ); ?></p>
    651 <?php else : ?>
     652        <?php else : ?>
    652653        <p><?php _e( 'You can use one of these cool headers or show a random one on each page.' ); ?></p>
    653 <?php endif; ?>
     654        <?php endif; ?>
    654655        <?php
    655656        $this->show_header_selector( 'default' );
    … …  
    685686</table>
    686687
    687 <?php if ( current_theme_supports( 'custom-header', 'header-text' ) ) : ?>
     688                <?php if ( current_theme_supports( 'custom-header', 'header-text' ) ) : ?>
    688689
    689690<h3><?php _e( 'Header Text' ); ?></h3>
    … …  
    704705<td>
    705706        <p>
    706         <?php
    707         $default_color = '';
    708         if ( current_theme_supports( 'custom-header', 'default-text-color' ) ) {
    709                 $default_color = get_theme_support( 'custom-header', 'default-text-color' );
    710                 if ( $default_color && false === strpos( $default_color, '#' ) ) {
    711                         $default_color = '#' . $default_color;
    712                 }
    713         }
    714 
    715         $default_color_attr = $default_color ? ' data-default-color="' . esc_attr( $default_color ) . '"' : '';
    716 
    717         $header_textcolor = display_header_text() ? get_header_textcolor() : get_theme_support( 'custom-header', 'default-text-color' );
    718         if ( $header_textcolor && false === strpos( $header_textcolor, '#' ) ) {
    719                 $header_textcolor = '#' . $header_textcolor;
    720         }
    721 
    722         echo '<input type="text" name="text-color" id="text-color" value="' . esc_attr( $header_textcolor ) . '"' . $default_color_attr . ' />';
    723         if ( $default_color ) {
    724                 echo ' <span class="description hide-if-js">' . sprintf( _x( 'Default: %s', 'color' ), esc_html( $default_color ) ) . '</span>';
    725         }
    726         ?>
     707                        <?php
     708                        $default_color = '';
     709                        if ( current_theme_supports( 'custom-header', 'default-text-color' ) ) {
     710                                $default_color = get_theme_support( 'custom-header', 'default-text-color' );
     711                                if ( $default_color && false === strpos( $default_color, '#' ) ) {
     712                                        $default_color = '#' . $default_color;
     713                                }
     714                        }
     715
     716                        $default_color_attr = $default_color ? ' data-default-color="' . esc_attr( $default_color ) . '"' : '';
     717
     718                        $header_textcolor = display_header_text() ? get_header_textcolor() : get_theme_support( 'custom-header', 'default-text-color' );
     719                        if ( $header_textcolor && false === strpos( $header_textcolor, '#' ) ) {
     720                                $header_textcolor = '#' . $header_textcolor;
     721                        }
     722
     723                        echo '<input type="text" name="text-color" id="text-color" value="' . esc_attr( $header_textcolor ) . '"' . $default_color_attr . ' />';
     724                        if ( $default_color ) {
     725                                echo ' <span class="description hide-if-js">' . sprintf( _x( 'Default: %s', 'color' ), esc_html( $default_color ) ) . '</span>';
     726                        }
     727                        ?>
    727728        </p>
    728729</td>
    … …  
    730731</tbody>
    731732</table>
    732 <?php
     733                        <?php
    733734endif;
    734735
    735 /**
    736  * Fires just before the submit button in the custom header options form.
    737  *
    738  * @since 3.1.0
    739  */
    740 do_action( 'custom_header_options' );
    741 
    742 wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' );
     736                /**
     737                * Fires just before the submit button in the custom header options form.
     738                *
     739                * @since 3.1.0
     740                */
     741                do_action( 'custom_header_options' );
     742
     743                wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' );
    743744?>
    744745
    745 <?php submit_button( null, 'primary', 'save-header-options' ); ?>
     746                <?php submit_button( null, 'primary', 'save-header-options' ); ?>
    746747</form>
    747748</div>
    748749
    749 <?php
     750                <?php
    750751        }
    751752
    … …  
    853854        <input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr( $attachment_id ); ?>" />
    854855        <input type="hidden" name="oitar" id="oitar" value="<?php echo esc_attr( $oitar ); ?>" />
    855         <?php if ( empty( $_POST ) && isset( $_GET['file'] ) ) { ?>
     856                <?php if ( empty( $_POST ) && isset( $_GET['file'] ) ) { ?>
    856857        <input type="hidden" name="create-new-attachment" value="true" />
    857858        <?php } ?>
    858         <?php wp_nonce_field( 'custom-header-crop-image' ); ?>
     859                <?php wp_nonce_field( 'custom-header-crop-image' ); ?>
    859860
    860861        <p class="submit">
    861         <?php submit_button( __( 'Crop and Publish' ), 'primary', 'submit', false ); ?>
    862         <?php
    863         if ( isset( $oitar ) && 1 == $oitar && ( current_theme_supports( 'custom-header', 'flex-height' ) || current_theme_supports( 'custom-header', 'flex-width' ) ) ) {
    864                 submit_button( __( 'Skip Cropping, Publish Image as Is' ), '', 'skip-cropping', false );
    865         }
    866         ?>
     862                <?php submit_button( __( 'Crop and Publish' ), 'primary', 'submit', false ); ?>
     863                <?php
     864                if ( isset( $oitar ) && 1 == $oitar && ( current_theme_supports( 'custom-header', 'flex-height' ) || current_theme_supports( 'custom-header', 'flex-width' ) ) ) {
     865                        submit_button( __( 'Skip Cropping, Publish Image as Is' ), '', 'skip-cropping', false );
     866                }
     867                ?>
    867868        </p>
    868869</form>
Note: See TracChangeset for help on using the changeset viewer.