bp_folder_add( array|string $args = '' )

Add folder item.

Description

Parameters

$args

(Optional) An array of arguments

Default value: ''

Return

(WP_Error|bool|int) The ID of the folder on success. False on error.

Source

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

1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
function bp_folder_add( $args = '' ) {
 
    $r = bp_parse_args(
        $args,
        array(
            'id'            => false, // Pass an existing folder ID to update an existing entry.
            'user_id'       => bp_loggedin_user_id(),   // User ID.
            'blog_id'       => get_current_blog_id(),   // Blog ID.
            'group_id'      => false,
            'title'         => ''// title of folder being added.
            'privacy'       => 'public',    // Optional: privacy of the document e.g. public.
            'date_created'  => bp_core_current_time(),  // The GMT time that this document was recorded.
            'date_modified' => bp_core_current_time(),  // The GMT time that this document was updated.
            'error_type'    => 'bool',
            'parent'        => 0,
        ),
        'folder_add'
    );
 
    // Setup document to be added.
    $folder                = new BP_Document_Folder( $r['id'] );
    $folder->user_id       = (int) $r['user_id'];
    $folder->group_id      = (int) $r['group_id'];
    $folder->blog_id       = (int) $r['blog_id'];
    $folder->title         = $r['title'];
    $folder->privacy       = $r['privacy'];
    $folder->date_created  = $r['date_created'];
    $folder->date_modified = $r['date_modified'];
    $folder->error_type    = $r['error_type'];
    $folder->parent        = $r['parent'];
 
    if ( ! empty( $folder->group_id ) ) {
        $folder->privacy = 'grouponly';
    }
 
    $save = $folder->save();
 
    if ( 'wp_error' === $r['error_type'] && is_wp_error( $save ) ) {
        return $save;
    } elseif ( 'bool' === $r['error_type'] && false === $save ) {
        return false;
    }
 
    /**
     * Fires at the end of the execution of adding a new folder item, before returning the new folder item ID.
     *
     * @param object $folder folder object.
     *
     * @since BuddyBoss 1.4.0
     */
    do_action( 'bp_folder_add', $folder );
 
    return $folder->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.