Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 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/class-file-upload-upgrader.php

    r41289 r42343  
    5353        public function __construct( $form, $urlholder ) {
    5454
    55                 if ( empty($_FILES[$form]['name']) && empty($_GET[$urlholder]) )
    56                         wp_die(__('Please select a file'));
     55                if ( empty( $_FILES[ $form ]['name'] ) && empty( $_GET[ $urlholder ] ) ) {
     56                        wp_die( __( 'Please select a file' ) );
     57                }
    5758
    5859                //Handle a newly uploaded file, Else assume it's already been uploaded
    59                 if ( ! empty($_FILES) ) {
    60                         $overrides = array( 'test_form' => false, 'test_type' => false );
    61                         $file = wp_handle_upload( $_FILES[$form], $overrides );
     60                if ( ! empty( $_FILES ) ) {
     61                        $overrides = array(
     62                                'test_form' => false,
     63                                'test_type' => false,
     64                        );
     65                        $file      = wp_handle_upload( $_FILES[ $form ], $overrides );
    6266
    63                         if ( isset( $file['error'] ) )
     67                        if ( isset( $file['error'] ) ) {
    6468                                wp_die( $file['error'] );
     69                        }
    6570
    66                         $this->filename = $_FILES[$form]['name'];
    67                         $this->package = $file['file'];
     71                        $this->filename = $_FILES[ $form ]['name'];
     72                        $this->package  = $file['file'];
    6873
    6974                        // Construct the object array
    7075                        $object = array(
    71                                 'post_title' => $this->filename,
    72                                 'post_content' => $file['url'],
     76                                'post_title'     => $this->filename,
     77                                'post_content'   => $file['url'],
    7378                                'post_mime_type' => $file['type'],
    74                                 'guid' => $file['url'],
    75                                 'context' => 'upgrader',
    76                                 'post_status' => 'private'
     79                                'guid'           => $file['url'],
     80                                'context'        => 'upgrader',
     81                                'post_status'    => 'private',
    7782                        );
    7883
    … …  
    8388                        wp_schedule_single_event( time() + 2 * HOUR_IN_SECONDS, 'upgrader_scheduled_cleanup', array( $this->id ) );
    8489
    85                 } elseif ( is_numeric( $_GET[$urlholder] ) ) {
     90                } elseif ( is_numeric( $_GET[ $urlholder ] ) ) {
    8691                        // Numeric Package = previously uploaded file, see above.
    87                         $this->id = (int) $_GET[$urlholder];
     92                        $this->id   = (int) $_GET[ $urlholder ];
    8893                        $attachment = get_post( $this->id );
    89                         if ( empty($attachment) )
    90                                 wp_die(__('Please select a file'));
     94                        if ( empty( $attachment ) ) {
     95                                wp_die( __( 'Please select a file' ) );
     96                        }
    9197
    9298                        $this->filename = $attachment->post_title;
    93                         $this->package = get_attached_file( $attachment->ID );
     99                        $this->package  = get_attached_file( $attachment->ID );
    94100                } else {
    95101                        // Else, It's set to something, Back compat for plugins using the old (pre-3.3) File_Uploader handler.
    96                         if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) )
     102                        if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) ) {
    97103                                wp_die( $uploads['error'] );
     104                        }
    98105
    99106                        $this->filename = sanitize_file_name( $_GET[ $urlholder ] );
    100                         $this->package = $uploads['basedir'] . '/' . $this->filename;
     107                        $this->package  = $uploads['basedir'] . '/' . $this->filename;
    101108
    102109                        if ( 0 !== strpos( realpath( $this->package ), realpath( $uploads['basedir'] ) ) ) {
    … …  
    114121         */
    115122        public function cleanup() {
    116                 if ( $this->id )
     123                if ( $this->id ) {
    117124                        wp_delete_attachment( $this->id );
    118125
    119                 elseif ( file_exists( $this->package ) )
     126                } elseif ( file_exists( $this->package ) ) {
    120127                        return @unlink( $this->package );
     128                }
    121129
    122130                return true;
Note: See TracChangeset for help on using the changeset viewer.