bp_document_move_document_to_folder( int $document_id, int $folder_id, int $group_id )

This function will document into the folder.

Description

Parameters

$document_id

(Required)

$folder_id

(Required)

$group_id

(Required)

Return

(bool|int)

Source

File: bp-document/bp-document-functions.php

2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
function bp_document_move_document_to_folder( $document_id = 0, $folder_id = 0, $group_id = 0 ) {
 
    global $wpdb, $bp;
 
    if ( 0 === $document_id ) {
        return false;
    }
 
    if ( (int) $document_id > 0 ) {
        $has_access = bp_document_user_can_edit( $document_id );
        if ( ! $has_access ) {
            return false;
        }
    }
 
    if ( (int) $folder_id > 0 ) {
        $has_access = bp_folder_user_can_edit( $folder_id );
        if ( ! $has_access ) {
            return false;
        }
    }
 
    if ( ! $group_id ) {
        $get_document = new BP_Document( $document_id );
        if ( $get_document->group_id > 0 ) {
            $group_id = $get_document->group_id;
        }
    }
 
    $destination_privacy = 'loggedin';
    if ( $group_id > 0 ) {
        $destination_privacy = 'grouponly';
    } elseif ( $folder_id > 0 ) {
        $destination_folder  = BP_Document_Folder::get_folder_data( array( $folder_id ) );
        $destination_privacy = $destination_folder[0]->privacy;
 
        // Update modify date for destination folder.
        $destination_folder_update                = new BP_Document_Folder( $folder_id );
        $destination_folder_update->date_modified = bp_core_current_time();
        $destination_folder_update->save();
    }
 
    $document                = new BP_Document( $document_id );
    $document->folder_id     = $folder_id;
    $document->group_id      = $group_id;
    $document->date_modified = bp_core_current_time();
    $document->save();
 
    // Update document activity privacy.
    if ( ! $group_id ) {
        if ( ! empty( $document ) && ! empty( $document->attachment_id ) ) {
            $post_attachment = $document->attachment_id;
            $activity_id     = get_post_meta( $post_attachment, 'bp_document_parent_activity_id', true );
            if ( ! empty( $activity_id ) && bp_is_active( 'activity' ) ) {
                $activity = new BP_Activity_Activity( (int) $activity_id );
                if ( bp_activity_user_can_delete( $activity ) ) {
                    $activity->privacy = $destination_privacy;
                    $activity->save();
                }
            }
        }
    }
    return $document_id;
}

Changelog

Changelog
Version Description
BuddyBoss 1.4.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.