예제 #1
0
function bp_docs_set_associated_group_id($doc_id, $group_id = 0)
{
    if (0 == intval($group_id)) {
        $term = array();
    } else {
        $term = bp_docs_get_group_term($group_id);
    }
    wp_set_post_terms($doc_id, $term, bp_docs_get_associated_item_tax_name(), false);
}
/**
 * Process group-doc unlinking requests.
 * Allows group mods & admins to remove docs from groups they moderate.
 *
 * @since 1.9.0
 *
 * @param int $doc_id ID of the doc to remove from the group
 * @param int $group_id ID of the group the doc should be removed from
 * @return bool true if the term is removed
 */
function bp_docs_unlink_from_group($doc_id, $group_id = 0)
{
    if ($group_id) {
        $term = bp_docs_get_group_term($group_id);
    }
    if (empty($doc_id) || empty($term)) {
        return false;
    }
    do_action('bp_docs_before_doc_unlink_from_group', $doc_id, $group_id, $term);
    $removed = wp_remove_object_terms($doc_id, $term, bp_docs_get_associated_item_tax_name());
    // wp_remove_object_terms returns true on success, false or WP_Error on failure.
    $retval = $removed == true ? true : false;
    if ($removed) {
        do_action('bp_docs_doc_unlinked_from_group', $doc_id, $group_id, $term);
    }
    // If the doc is no longer associated with any group, make sure it doesn't become public.
    $assoc_group_id = bp_docs_get_associated_group_id($doc_id);
    if (empty($assoc_group_id)) {
        bp_docs_remove_group_related_doc_access_settings($doc_id);
    }
    // Recalculate the number of docs in the affected group.
    if ($retval) {
        bp_docs_update_doc_count($group_id, 'group');
    }
    return $retval;
}
예제 #3
0
function bp_docs_set_associated_group_id($doc_id, $group_id = 0)
{
    wp_set_post_terms($doc_id, bp_docs_get_group_term($group_id), bp_docs_get_associated_item_tax_name(), true);
}