| 1 |
<?php |
| 2 |
$file = SPICEB_PLUGIN_URL .'inc/spicepress/images/portfolio/gallery2.jpg'; |
| 3 |
$ImagePath = SPICEB_PLUGIN_URL .'inc/spicepress/images/portfolio'; |
| 4 |
|
| 5 |
$images = array( |
| 6 |
$ImagePath.'/gallery1.jpg', |
| 7 |
$ImagePath.'/gallery2.jpg', |
| 8 |
$ImagePath.'/gallery3.jpg', |
| 9 |
$ImagePath.'/gallery4.jpg', |
| 10 |
$ImagePath.'/gallery5.jpg', |
| 11 |
$ImagePath.'/gallery6.jpg', |
| 12 |
$ImagePath.'/gallery7.jpg', |
| 13 |
$ImagePath.'/gallery8.jpg', |
| 14 |
$ImagePath.'/gallery9.jpg', |
| 15 |
$ImagePath.'/gallery10.jpg', |
| 16 |
$ImagePath.'/gallery11.jpg', |
| 17 |
$ImagePath.'/gallery12.jpg', |
| 18 |
$ImagePath. '/logo.png', |
| 19 |
); |
| 20 |
|
| 21 |
foreach($images as $name) { |
| 22 |
$filename = basename($name); |
| 23 |
$upload_file = wp_upload_bits($filename, null, file_get_contents($name)); |
| 24 |
if (!$upload_file['error']) { |
| 25 |
$wp_filetype = wp_check_filetype($filename, null ); |
| 26 |
$attachment = array( |
| 27 |
'post_mime_type' => $wp_filetype['type'], |
| 28 |
'post_parent' => $parent_post_id, |
| 29 |
'post_title' => preg_replace('/\.[^.]+$/', '', $filename), |
| 30 |
'post_excerpt' => 'Portfolio caption', |
| 31 |
'post_status' => 'inherit' |
| 32 |
); |
| 33 |
$ImageId[] = $attachment_id = wp_insert_attachment( $attachment, $upload_file['file'], $parent_post_id ); |
| 34 |
|
| 35 |
if (!is_wp_error($attachment_id)) { |
| 36 |
require_once(ABSPATH . "wp-admin" . '/includes/image.php'); |
| 37 |
$attachment_data = wp_generate_attachment_metadata( $attachment_id, $upload_file['file'] ); |
| 38 |
wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
} |
| 43 |
|
| 44 |
update_option( 'portfolio_media_id', $ImageId ); |
| 45 |
|
| 46 |
?> |
| 47 |
|