Codeception\TestCase\WPTestCase::_make_attachment PHP Метод

_make_attachment() публичный Метод

public _make_attachment ( $upload, $parent_post_id )
    function _make_attachment($upload, $parent_post_id = 0)
    {
        $type = '';
        if (!empty($upload['type'])) {
            $type = $upload['type'];
        } else {
            $mime = wp_check_filetype($upload['file']);
            if ($mime) {
                $type = $mime['type'];
            }
        }
        $attachment = array('post_title' => basename($upload['file']), 'post_content' => '', 'post_type' => 'attachment', 'post_parent' => $parent_post_id, 'post_mime_type' => $type, 'guid' => $upload['url']);
        // Save the data
        $id = wp_insert_attachment($attachment, $upload['file'], $parent_post_id);
        wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $upload['file']));
        return $id;
    }