| 1 |
<?php |
| 2 |
$ImagePath = SPICEB_PLUGIN_URL .'inc/innofit/images'; |
| 3 |
|
| 4 |
$images = array( |
| 5 |
$ImagePath. '/logo.png', |
| 6 |
); |
| 7 |
|
| 8 |
foreach($images as $name) { |
| 9 |
$filename = basename($name); |
| 10 |
$upload_file = wp_upload_bits($filename, null, file_get_contents($name)); |
| 11 |
if (!$upload_file['error']) { |
| 12 |
$wp_filetype = wp_check_filetype($filename, null ); |
| 13 |
$attachment = array( |
| 14 |
'post_mime_type' => $wp_filetype['type'], |
| 15 |
'post_parent' => $parent_post_id, |
| 16 |
'post_title' => preg_replace('/\.[^.]+$/', '', $filename), |
| 17 |
'post_status' => 'inherit' |
| 18 |
); |
| 19 |
$ImageId[] = $attachment_id = wp_insert_attachment( $attachment, $upload_file['file'], $parent_post_id ); |
| 20 |
|
| 21 |
if (!is_wp_error($attachment_id)) { |
| 22 |
require_once(ABSPATH . "wp-admin" . '/includes/image.php'); |
| 23 |
$attachment_data = wp_generate_attachment_metadata( $attachment_id, $upload_file['file'] ); |
| 24 |
wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
} |
| 29 |
|
| 30 |
update_option( 'innofit_media_id', $ImageId ); |
| 31 |
?> |