Hi David – It’s going to be a bit tricky. I guess it partially depends on how your import data is structured. A couple suggestions:
– I’d do this all in PHP. Don’t try to fake the front-end using POST requests. This’ll be a nightmare.
– Go ahead and use the BP_Docs_Query::save()
method, but it’s poorly written, so you’ll have to do some ugly stuff. In particular, you’ll need to look for the places where it’s looking in $_POST
and fake that on your end. So,
foreach ( $docs_to_insert as $doc ) {
$_POST = array();
$_POST['doc_content'] = $doc['content'];
$_POST['associated_group_id'] = $doc['group_id'];
}
etc.
– You can either filter the logged in user id, or you can just switch it after creation, using the $doc_id that you get back from the save method. I’d suggest the latter.
– Attachments are going to be a bit of a bear. I guess I’d suggest putting the source files in a directory accessible from your PHP script (which I guess would be structured as a WP plugin), and then using WP’s sideload functionality (in particular, wp_handle_sideload()) to move stuff around. You’ll probably need to manually add some of the filters in buddypress-docs/includes/attachments.php to ensure that wp_upload_dir() gets filtered correctly, and your files go to the correct place.
Hopefully that’s a good starting point. Good luck!