Make WordPress Core

Changeset 56400


Ignore:
Timestamp:
08/16/2023 02:03:44 PM (9 months ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Use strict comparison in wp-admin/includes/image-edit.php.

Follow-up to [11911], [11965], [11984], [12155], [12163], [22094].

Props aristath, poena, afercia, SergeyBiryukov.
See #58831.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/image-edit.php

    r56277 r56400  
    637637            unset( $obj->c );
    638638        }
     639
    639640        $changes[ $key ] = $obj;
    640641    }
     
    643644    if ( count( $changes ) > 1 ) {
    644645        $filtered = array( $changes[0] );
     646
    645647        for ( $i = 0, $j = 1, $c = count( $changes ); $j < $c; $j++ ) {
    646648            $combined = false;
    647             if ( $filtered[ $i ]->type == $changes[ $j ]->type ) {
     649
     650            if ( $filtered[ $i ]->type === $changes[ $j ]->type ) {
    648651                switch ( $filtered[ $i ]->type ) {
    649652                    case 'rotate':
     
    657660                }
    658661            }
     662
    659663            if ( ! $combined ) {
    660664                $filtered[ ++$i ] = $changes[ $j ];
    661665            }
    662666        }
     667
    663668        $changes = $filtered;
    664669        unset( $filtered );
     
    694699        switch ( $operation->type ) {
    695700            case 'rotate':
    696                 if ( 0 != $operation->angle ) {
     701                if ( 0 !== $operation->angle ) {
    697702                    if ( $image instanceof WP_Image_Editor ) {
    698703                        $image->rotate( $operation->angle );
     
    703708                break;
    704709            case 'flip':
    705                 if ( 0 != $operation->axis ) {
     710                if ( 0 !== $operation->axis ) {
    706711                    if ( $image instanceof WP_Image_Editor ) {
    707                         $image->flip( ( $operation->axis & 1 ) != 0, ( $operation->axis & 2 ) != 0 );
     712                        $image->flip( ( $operation->axis & 1 ) !== 0, ( $operation->axis & 2 ) !== 0 );
    708713                    } else {
    709                         $image = _flip_image_resource( $image, ( $operation->axis & 1 ) != 0, ( $operation->axis & 2 ) != 0 );
     714                        $image = _flip_image_resource( $image, ( $operation->axis & 1 ) !== 0, ( $operation->axis & 2 ) !== 0 );
    710715                    }
    711716                }
     
    802807        $data = $backup_sizes['full-orig'];
    803808
    804         if ( $parts['basename'] != $data['file'] ) {
     809        if ( $parts['basename'] !== $data['file'] ) {
    805810            if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE ) {
    806 
    807811                // Delete only if it's an edited image.
    808812                if ( preg_match( '/-e[0-9]{13}\./', $parts['basename'] ) ) {
     
    829833        if ( isset( $backup_sizes[ "$default_size-orig" ] ) ) {
    830834            $data = $backup_sizes[ "$default_size-orig" ];
    831             if ( isset( $meta['sizes'][ $default_size ] ) && $meta['sizes'][ $default_size ]['file'] != $data['file'] ) {
     835
     836            if ( isset( $meta['sizes'][ $default_size ] ) && $meta['sizes'][ $default_size ]['file'] !== $data['file'] ) {
    832837                if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE ) {
    833 
    834838                    // Delete only if it's an edited image.
    835839                    if ( preg_match( '/-e[0-9]{13}-/', $meta['sizes'][ $default_size ]['file'] ) ) {
     
    848852    }
    849853
    850     if ( ! wp_update_attachment_metadata( $post_id, $meta ) ||
    851         ( $old_backup_sizes !== $backup_sizes && ! update_post_meta( $post_id, '_wp_attachment_backup_sizes', $backup_sizes ) ) ) {
    852 
     854    if ( ! wp_update_attachment_metadata( $post_id, $meta )
     855        || ( $old_backup_sizes !== $backup_sizes && ! update_post_meta( $post_id, '_wp_attachment_backup_sizes', $backup_sizes ) )
     856    ) {
    853857        $msg->error = __( 'Cannot save image metadata.' );
    854858        return $msg;
     
    859863    } else {
    860864        $msg->msg = __( 'Image restored successfully.' );
     865
    861866        if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE ) {
    862867            delete_post_meta( $post_id, '_wp_attachment_backup_sizes' );
     
    887892
    888893    $img = wp_get_image_editor( _load_image_to_edit_path( $post_id, 'full' ) );
     894
    889895    if ( is_wp_error( $img ) ) {
    890896        $return->error = esc_js( __( 'Unable to create new image.' ) );
     
    956962    $suffix   = time() . rand( 100, 999 );
    957963
    958     if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE &&
    959         isset( $backup_sizes['full-orig'] ) && $backup_sizes['full-orig']['file'] != $basename ) {
     964    if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE
     965        && isset( $backup_sizes['full-orig'] ) && $backup_sizes['full-orig']['file'] !== $basename
     966    ) {
    960967
    961968        if ( $edit_thumbnails_separately && 'thumbnail' === $target ) {
     
    970977            $new_filename = "{$filename}.{$ext}";
    971978            $new_path     = "{$dirname}/$new_filename";
     979
    972980            if ( file_exists( $new_path ) ) {
    973981                $suffix++;
     
    986994    if ( 'nothumb' === $target || 'all' === $target || 'full' === $target || $scaled ) {
    987995        $tag = false;
     996
    988997        if ( isset( $backup_sizes['full-orig'] ) ) {
    989             if ( ( ! defined( 'IMAGE_EDIT_OVERWRITE' ) || ! IMAGE_EDIT_OVERWRITE ) && $backup_sizes['full-orig']['file'] !== $basename ) {
     998            if ( ( ! defined( 'IMAGE_EDIT_OVERWRITE' ) || ! IMAGE_EDIT_OVERWRITE )
     999                && $backup_sizes['full-orig']['file'] !== $basename
     1000            ) {
    9901001                $tag = "full-$suffix";
    9911002            }
     
    10011012            );
    10021013        }
     1014
    10031015        $success = ( $path === $new_path ) || update_attached_file( $post_id, $new_path );
    10041016
     
    10461058        foreach ( $sizes as $size ) {
    10471059            $tag = false;
     1060
    10481061            if ( isset( $meta['sizes'][ $size ] ) ) {
    10491062                if ( isset( $backup_sizes[ "$size-orig" ] ) ) {
    1050                     if ( ( ! defined( 'IMAGE_EDIT_OVERWRITE' ) || ! IMAGE_EDIT_OVERWRITE ) && $backup_sizes[ "$size-orig" ]['file'] != $meta['sizes'][ $size ]['file'] ) {
     1063                    if ( ( ! defined( 'IMAGE_EDIT_OVERWRITE' ) || ! IMAGE_EDIT_OVERWRITE )
     1064                        && $backup_sizes[ "$size-orig" ]['file'] !== $meta['sizes'][ $size ]['file']
     1065                    ) {
    10511066                        $tag = "$size-$suffix";
    10521067                    }
     
    10891104            // Check if it's an image edit from attachment edit screen.
    10901105            if ( ! empty( $_REQUEST['context'] ) && 'edit-attachment' === $_REQUEST['context'] ) {
    1091                 $thumb_url         = wp_get_attachment_image_src( $post_id, array( 900, 600 ), true );
     1106                $thumb_url = wp_get_attachment_image_src( $post_id, array( 900, 600 ), true );
     1107
    10921108                $return->thumbnail = $thumb_url[0];
    10931109            } else {
    10941110                $file_url = wp_get_attachment_url( $post_id );
     1111
    10951112                if ( ! empty( $meta['sizes']['thumbnail'] ) ) {
    10961113                    $thumb             = $meta['sizes']['thumbnail'];
     
    11101127
    11111128    $return->msg = esc_js( __( 'Image saved' ) );
     1129
    11121130    return $return;
    11131131}
Note: See TracChangeset for help on using the changeset viewer.