RTMediaMedia::insert_attachment PHP Method

insert_attachment() public method

public insert_attachment ( type $attachments, type $file_object ) : array
$attachments type
$file_object type
return array $updated_attachment_ids
    function insert_attachment($attachments, $file_object)
    {
        $updated_attachment_ids = array();
        foreach ($attachments as $key => $attachment) {
            $attachment_id = wp_insert_attachment($attachment, $file_object[$key]['file'], $attachment['post_parent']);
            if (!is_wp_error($attachment_id)) {
                add_filter('intermediate_image_sizes', array($this, 'image_sizes'), 99);
                /**
                 * FIX WORDPRESS 3.6 METADATA
                 */
                require_once ABSPATH . 'wp-admin/includes/media.php';
                /**
                 *
                 */
                wp_update_attachment_metadata($attachment_id, wp_generate_attachment_metadata($attachment_id, $file_object[$key]['file']));
            } else {
                $file = $file_object[$key]['file'];
                if (function_exists('wp_delete_file')) {
                    // wp_delete_file is introduced in WordPress 4.2
                    wp_delete_file($file);
                } else {
                    unlink($file);
                    // @codingStandardsIgnoreLine
                }
                throw new Exception(esc_html__('Error creating attachment for the media file, please try again', 'buddypress-media'));
            }
            $updated_attachment_ids[] = $attachment_id;
        }
        return $updated_attachment_ids;
    }