Changeset 42343 for trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php
r38331 r42343 18 18 // Backward compatibility for legacy argument format. 19 19 if ( is_string( $args ) ) { 20 $file = $args;21 $args = $legacy_args;20 $file = $args; 21 $args = $legacy_args; 22 22 $args['post_parent'] = $legacy_parent; 23 $args['file'] = $file;23 $args['file'] = $file; 24 24 } 25 25 26 $r = array_merge( array( 27 'file' => '', 28 'post_parent' => 0, 29 ), $args ); 26 $r = array_merge( 27 array( 28 'file' => '', 29 'post_parent' => 0, 30 ), $args 31 ); 30 32 31 33 return wp_insert_attachment( $r, $r['file'], $r['post_parent'] ); … … 33 35 34 36 function create_upload_object( $file, $parent = 0 ) { 35 $contents = file_get_contents( $file);36 $upload = wp_upload_bits(basename($file), null, $contents);37 $contents = file_get_contents( $file ); 38 $upload = wp_upload_bits( basename( $file ), null, $contents ); 37 39 38 40 $type = ''; 39 if ( ! empty( $upload['type']) ) {41 if ( ! empty( $upload['type'] ) ) { 40 42 $type = $upload['type']; 41 43 } else { 42 44 $mime = wp_check_filetype( $upload['file'] ); 43 if ( $mime)45 if ( $mime ) { 44 46 $type = $mime['type']; 47 } 45 48 } 46 49 47 50 $attachment = array( 48 'post_title' => basename( $upload['file'] ),49 'post_content' => '',50 'post_type' => 'attachment',51 'post_parent' => $parent,51 'post_title' => basename( $upload['file'] ), 52 'post_content' => '', 53 'post_type' => 'attachment', 54 'post_parent' => $parent, 52 55 'post_mime_type' => $type, 53 'guid' => $upload[ 'url'],56 'guid' => $upload['url'], 54 57 ); 55 58 56 59 // Save the data 57 $id = wp_insert_attachment( $attachment, $upload[ 'file'], $parent );60 $id = wp_insert_attachment( $attachment, $upload['file'], $parent ); 58 61 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) ); 59 62
Note: See TracChangeset
for help on using the changeset viewer.