Changeset 34855 for trunk/tests/phpunit/includes/factory.php
- Timestamp:
- 10/06/2015 04:58:21 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/factory.php
r34828 r34855 94 94 function create_object( $file, $parent = 0, $args = array() ) { 95 95 return wp_insert_attachment( $args, $file, $parent ); 96 } 97 98 function create_upload_object( $file, $parent = 0 ) { 99 $contents = file_get_contents($file); 100 $upload = wp_upload_bits(basename($file), null, $contents); 101 102 $type = ''; 103 if ( ! empty($upload['type']) ) { 104 $type = $upload['type']; 105 } else { 106 $mime = wp_check_filetype( $upload['file'] ); 107 if ($mime) 108 $type = $mime['type']; 109 } 110 111 $attachment = array( 112 'post_title' => basename( $upload['file'] ), 113 'post_content' => '', 114 'post_type' => 'attachment', 115 'post_parent' => $parent, 116 'post_mime_type' => $type, 117 'guid' => $upload[ 'url' ], 118 ); 119 120 // Save the data 121 $id = wp_insert_attachment( $attachment, $upload[ 'file' ], $parent ); 122 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) ); 123 124 return $id; 96 125 } 97 126 }
Note: See TracChangeset
for help on using the changeset viewer.