Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (6 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-admin/includes/revision.php

    r41559 r42343  
    2121 */
    2222function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) {
    23     if ( ! $post = get_post( $post ) )
     23    if ( ! $post = get_post( $post ) ) {
    2424        return false;
     25    }
    2526
    2627    if ( $compare_from ) {
    27         if ( ! $compare_from = get_post( $compare_from ) )
     28        if ( ! $compare_from = get_post( $compare_from ) ) {
    2829            return false;
     30        }
    2931    } else {
    3032        // If we're dealing with the first revision...
     
    3234    }
    3335
    34     if ( ! $compare_to = get_post( $compare_to ) )
     36    if ( ! $compare_to = get_post( $compare_to ) ) {
    3537        return false;
     38    }
    3639
    3740    // If comparing revisions, make sure we're dealing with the right post parent.
    3841    // The parent post may be a 'revision' when revisions are disabled and we're looking at autosaves.
    39     if ( $compare_from && $compare_from->post_parent !== $post->ID && $compare_from->ID !== $post->ID )
     42    if ( $compare_from && $compare_from->post_parent !== $post->ID && $compare_from->ID !== $post->ID ) {
    4043        return false;
    41     if ( $compare_to->post_parent !== $post->ID && $compare_to->ID !== $post->ID )
     44    }
     45    if ( $compare_to->post_parent !== $post->ID && $compare_to->ID !== $post->ID ) {
    4246        return false;
     47    }
    4348
    4449    if ( $compare_from && strtotime( $compare_from->post_date_gmt ) > strtotime( $compare_to->post_date_gmt ) ) {
    45         $temp = $compare_from;
     50        $temp         = $compare_from;
    4651        $compare_from = $compare_to;
    47         $compare_to = $temp;
     52        $compare_to   = $temp;
    4853    }
    4954
    5055    // Add default title if title field is empty
    51     if ( $compare_from && empty( $compare_from->post_title ) )
     56    if ( $compare_from && empty( $compare_from->post_title ) ) {
    5257        $compare_from->post_title = __( '(no title)' );
    53     if ( empty( $compare_to->post_title ) )
     58    }
     59    if ( empty( $compare_to->post_title ) ) {
    5460        $compare_to->post_title = __( '(no title)' );
     61    }
    5562
    5663    $return = array();
     
    7784
    7885        $args = array(
    79             'show_split_view' => true
     86            'show_split_view' => true,
    8087        );
    8188
     
    104111            // It's a better user experience to still show the Title, even if it didn't change.
    105112            // No, you didn't see this.
    106             $diff = '<table class="diff"><colgroup><col class="content diffsplit left"><col class="content diffsplit middle"><col class="content diffsplit right"></colgroup><tbody><tr>';
     113            $diff  = '<table class="diff"><colgroup><col class="content diffsplit left"><col class="content diffsplit middle"><col class="content diffsplit right"></colgroup><tbody><tr>';
    107114            $diff .= '<td>' . esc_html( $compare_from->post_title ) . '</td><td></td><td>' . esc_html( $compare_to->post_title ) . '</td>';
    108115            $diff .= '</tr></tbody>';
     
    112119        if ( $diff ) {
    113120            $return[] = array(
    114                 'id' => $field,
     121                'id'   => $field,
    115122                'name' => $name,
    116123                'diff' => $diff,
     
    144151 */
    145152function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null ) {
    146     $post = get_post( $post );
     153    $post    = get_post( $post );
    147154    $authors = array();
    148155    $now_gmt = time();
    149156
    150     $revisions = wp_get_post_revisions( $post->ID, array( 'order' => 'ASC', 'check_enabled' => false ) );
     157    $revisions = wp_get_post_revisions(
     158        $post->ID, array(
     159            'order'         => 'ASC',
     160            'check_enabled' => false,
     161        )
     162    );
    151163    // If revisions are disabled, we only want autosaves and the current post.
    152164    if ( ! wp_revisions_enabled( $post ) ) {
    153165        foreach ( $revisions as $revision_id => $revision ) {
    154             if ( ! wp_is_post_autosave( $revision ) )
     166            if ( ! wp_is_post_autosave( $revision ) ) {
    155167                unset( $revisions[ $revision_id ] );
     168            }
    156169        }
    157170        $revisions = array( $post->ID => $post ) + $revisions;
     
    163176
    164177    $can_restore = current_user_can( 'edit_post', $post->ID );
    165     $current_id = false;
     178    $current_id  = false;
    166179
    167180    foreach ( $revisions as $revision ) {
    168         $modified = strtotime( $revision->post_modified );
     181        $modified     = strtotime( $revision->post_modified );
    169182        $modified_gmt = strtotime( $revision->post_modified_gmt . ' +0000' );
    170183        if ( $can_restore ) {
    171             $restore_link = str_replace( '&amp;', '&', wp_nonce_url(
    172                 add_query_arg(
    173                     array( 'revision' => $revision->ID,
    174                         'action' => 'restore' ),
     184            $restore_link = str_replace(
     185                '&amp;', '&', wp_nonce_url(
     186                    add_query_arg(
     187                        array(
     188                            'revision' => $revision->ID,
     189                            'action'   => 'restore',
     190                        ),
    175191                        admin_url( 'revision.php' )
    176                 ),
    177                 "restore-post_{$revision->ID}"
    178             ) );
     192                    ),
     193                    "restore-post_{$revision->ID}"
     194                )
     195            );
    179196        }
    180197
    181198        if ( ! isset( $authors[ $revision->post_author ] ) ) {
    182199            $authors[ $revision->post_author ] = array(
    183                 'id' => (int) $revision->post_author,
     200                'id'     => (int) $revision->post_author,
    184201                'avatar' => $show_avatars ? get_avatar( $revision->post_author, 32 ) : '',
    185                 'name' => get_the_author_meta( 'display_name', $revision->post_author ),
     202                'name'   => get_the_author_meta( 'display_name', $revision->post_author ),
    186203            );
    187204        }
    188205
    189206        $autosave = (bool) wp_is_post_autosave( $revision );
    190         $current = ! $autosave && $revision->post_modified_gmt === $post->post_modified_gmt;
     207        $current  = ! $autosave && $revision->post_modified_gmt === $post->post_modified_gmt;
    191208        if ( $current && ! empty( $current_id ) ) {
    192209            // If multiple revisions have the same post_modified_gmt, highest ID is current.
    193210            if ( $current_id < $revision->ID ) {
    194211                $revisions[ $current_id ]['current'] = false;
    195                 $current_id = $revision->ID;
     212                $current_id                          = $revision->ID;
    196213            } else {
    197214                $current = false;
     
    254271            'restoreUrl' => false,
    255272        );
    256         $current_id = $post->ID;
     273        $current_id             = $post->ID;
    257274    }
    258275
     
    289306    $from = absint( $from );
    290307
    291     $diffs = array( array(
    292         'id' => $from . ':' . $selected_revision_id,
    293         'fields' => wp_get_revision_ui_diff( $post->ID, $from, $selected_revision_id ),
    294     ));
     308    $diffs = array(
     309        array(
     310            'id'     => $from . ':' . $selected_revision_id,
     311            'fields' => wp_get_revision_ui_diff( $post->ID, $from, $selected_revision_id ),
     312        ),
     313    );
    295314
    296315    return array(
    297         'postId'           => $post->ID,
    298         'nonce'            => wp_create_nonce( 'revisions-ajax-nonce' ),
    299         'revisionData'     => array_values( $revisions ),
    300         'to'               => $selected_revision_id,
    301         'from'             => $from,
    302         'diffData'         => $diffs,
    303         'baseUrl'          => parse_url( admin_url( 'revision.php' ), PHP_URL_PATH ),
    304         'compareTwoMode'   => absint( $compare_two_mode ), // Apparently booleans are not allowed
    305         'revisionIds'      => array_keys( $revisions ),
     316        'postId'         => $post->ID,
     317        'nonce'          => wp_create_nonce( 'revisions-ajax-nonce' ),
     318        'revisionData'   => array_values( $revisions ),
     319        'to'             => $selected_revision_id,
     320        'from'           => $from,
     321        'diffData'       => $diffs,
     322        'baseUrl'        => parse_url( admin_url( 'revision.php' ), PHP_URL_PATH ),
     323        'compareTwoMode' => absint( $compare_two_mode ), // Apparently booleans are not allowed
     324        'revisionIds'    => array_keys( $revisions ),
    306325    );
    307326}
     
    358377                    <div class="author-info">
    359378                    <# if ( data.attributes.autosave ) { #>
    360                         <span class="byline"><?php printf( __( 'Autosave by %s' ),
    361                             '<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
     379                        <span class="byline">
     380                        <?php
     381                        printf(
     382                            __( 'Autosave by %s' ),
     383                            '<span class="author-name">{{ data.attributes.author.name }}</span>'
     384                        );
     385                            ?>
     386                            </span>
    362387                    <# } else if ( data.attributes.current ) { #>
    363                         <span class="byline"><?php printf( __( 'Current Revision by %s' ),
    364                             '<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
     388                        <span class="byline">
     389                        <?php
     390                        printf(
     391                            __( 'Current Revision by %s' ),
     392                            '<span class="author-name">{{ data.attributes.author.name }}</span>'
     393                        );
     394                            ?>
     395                            </span>
    365396                    <# } else { #>
    366                         <span class="byline"><?php printf( __( 'Revision by %s' ),
    367                             '<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
     397                        <span class="byline">
     398                        <?php
     399                        printf(
     400                            __( 'Revision by %s' ),
     401                            '<span class="author-name">{{ data.attributes.author.name }}</span>'
     402                        );
     403                            ?>
     404                            </span>
    368405                    <# } #>
    369406                        <span class="time-ago">{{ data.attributes.timeAgo }}</span>
     
    400437        <# }); #>
    401438        </div>
    402     </script><?php
     439    </script>
     440    <?php
    403441}
Note: See TracChangeset for help on using the changeset viewer.