Skip to:
Content

bbPress.org


Ignore:
Timestamp:
08/21/2012 07:11:11 AM (14 years ago)
Author:
johnjamesjacoby
Message:

Topic Tags:

  • When posting a topic or reply, check that user can assign tags to topics.
  • If user cannot assign tags, and topic-tag value is not set, use existing topic tags.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-topic-functions.php

    r4149 r4166  
    430430    $topic = $topic_id = $forum_id = $anonymous_data = 0;
    431431    $topic_title = $topic_content = $topic_edit_reason = '';
    432     $terms = array( bbp_get_topic_tag_tax_id() => array() );
    433432
    434433    /** Topic *****************************************************************/
     
    552551    /** Topic Tags ************************************************************/
    553552
    554     // Tags
    555     if ( bbp_allow_topic_tags() && !empty( $_POST['bbp_topic_tags'] ) ) {
     553    // Either replace terms
     554    if ( bbp_allow_topic_tags() && current_user_can( 'assign_topic_tags' ) && ! empty( $_POST['bbp_topic_tags'] ) ) {
    556555
    557556        // Escape tag input
     
    564563        // Add topic tag ID as main key
    565564        $terms = array( bbp_get_topic_tag_tax_id() => $terms );
     565
     566    // ...or remove them.
     567    } elseif ( isset( $_POST['bbp_topic_tags'] ) ) {
     568        $terms = array( bbp_get_topic_tag_tax_id() => array() );
     569
     570    // Existing terms
     571    } else {
     572        $terms = array( bbp_get_topic_tag_tax_id() => explode( ',', bbp_get_topic_tag_names( $topic_id, ',' ) ) );
    566573    }
    567574
     
    30693076}
    30703077
     3078/** Topic Tags ****************************************************************/
     3079
     3080/**
     3081 * Get topic tags for a specific topic ID
     3082 *
     3083 * @since bbPress (r4165)
     3084 *
     3085 * @param int $topic_id
     3086 * @param string $sep
     3087 * @return string
     3088 */
     3089function bbp_get_topic_tag_names( $topic_id = 0, $sep = ', ' ) {
     3090    $topic_id   = bbp_get_topic_id( $topic_id );
     3091    $topic_tags = array_filter( (array) get_the_terms( $topic_id, bbp_get_topic_tag_tax_id() ) );
     3092    $terms      = array();
     3093    foreach( $topic_tags as $term ) {
     3094        $terms[] = $term->name;
     3095    }
     3096    $terms = !empty( $terms ) ? implode( $sep, $terms ) : '';
     3097
     3098    return apply_filters( 'bbp_get_topic_tags', $terms, $topic_id );
     3099}
     3100
    30713101/** Autoembed *****************************************************************/
    30723102
Note: See TracChangeset for help on using the changeset viewer.