Skip to:
Content
Pages
Categories
Search
Top
Bottom

Duplicate associate item


  • beboze
    Participant

    @beboze


    1. ON CREATING A DOCUMENT FROM THE BACKOFFICE

    Concerning table on creating a document
    wp_posts
    (id = 1511)
    wp_postmeta
    (post_id = 1511)

    wp_term_relationships
    (object_id = post_id = 1511)

    wp_term_taxonomy
    (term_taxonomy_id =

    wp_terms

    On opening the document from the FrontPage the category name is missing

    2. ON CREATING A DOCUMENT FROM THE FRONT OFFICE

    Concerning table on creating a document
    wp_posts
    (id = 1514)
    wp_postmeta
    (post_id = 1514)
    wp_term_relationships
    (object_id = post_id = 1514) 2 rows of the same post_id

    wp_term_taxonomy
    2 term taxonomy id
    Id = 32 and id = 204

    wp_terms = 26

    On opening the document from the FrontPage the category name is present

    But on opening the document from the back office the category name is duplicated.

    CODE MODIFICATION
    File modified:wp-content/plugins/buddypress-docs/includes/functions.php
    Line number: 126
    function bp_docs_get_item_term_id($item_id, $item_type, $item_name = ” ) {
    global $bp;

    $groups_dir = ABSPATH.’wp-content/plugins/buddypress/bp-groups/classes/class-bp-groups-group.php’; //ss add this to get the class Bp_Groups_Group
    require_once($groups_dir);

    //if ( empty( $item_id ) ) {
    //return ;
    //}

    // Sanitization
    // @todo Maybe this should be more generous
    $slug_group = BP_Groups_Group ::get_slug($item_id); // ss add this to test the group from tbl wp_term

    $item_type = ‘group’ == $item_type ? ‘group’ : ‘user’;

    //$item_term_slug = ‘bp_docs_associated_’ . $item_type . ‘_’ . $item_id;
    $item_term_slug = ‘group’ == $item_type ? $slug_group : ‘bp_docs_associated_’ . $item_type . ‘_’ . $item_id;

    $item_term = get_term_by( ‘slug’, $item_term_slug, bp_docs_get_associated_item_tax_name() );
    //var_dump($item_term);
    //die(‘xxx’);
    // If the item term doesn’t exist, then create it
    if ( empty( $item_term ) ) {
    // Set up the arguments for creating the term. Filter this to set your own
    switch ( $item_type ) {
    case ‘group’ :
    $item = groups_get_group( ‘group_id=’ . $item_id );
    $item_name = $item->name;
    break;

    case ‘user’ :
    default :
    $item_name = bp_core_get_user_displayname( $item_id );
    break;
    }

    $item_term_args = apply_filters( ‘bp_docs_item_term_values’, array(
    ‘description’ => sprintf( _x( ‘Docs associated with the %1$s %2$s’, ‘Description for the associated-item taxonomy term. Of the form “Docs associated with the [item-type] [item-name]” – item-type is group, user, etc’, ‘bp-docs’ ), $item_type, $item_name ),
    ‘slug’ => $item_term_slug,
    ) );

    // Create the item term
    $item_term = wp_insert_term( $item_name, bp_docs_get_associated_item_tax_name(), $item_term_args );
    $term_id = isset( $item_term[‘term_id’] ) ? $item_term[‘term_id’] : false;
    } else {

    $term_id = $item_term->term_id;
    }
    //echo $item_id;
    //die(‘xxx’);
    return apply_filters( ‘bp_docs_get_item_term_id’, $term_id, $item_id, $item_type, $item_name );
    }
    Description
    The function is called when you create a document from the front office.
    I have modified the function where it going to check the corresponding slug is present in the table wp_terms.
    First I get all the category slug from BP_group , then I use them to verify if they are present in the table wp_term, if present therefore no need to add a second (prevent duplication).

    Result: No duplication but the category is null from the front office.

  • You must be logged in to reply to this topic.
Skip to toolbar