Skip to:
Content

bbPress.org

Changeset 4166


Ignore:
Timestamp:
08/21/2012 07:11:11 AM (13 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.
Location:
branches/plugin/bbp-includes
Files:
2 edited

Legend:

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

    r4162 r4166  
    224224    /** Topic Tags ************************************************************/
    225225
    226     if ( !empty( $_POST['bbp_topic_tags'] ) )
     226    // Either replace terms
     227    if ( bbp_allow_topic_tags() && current_user_can( 'assign_topic_tags' ) && ! empty( $_POST['bbp_topic_tags'] ) ) {
    227228        $terms = esc_attr( strip_tags( $_POST['bbp_topic_tags'] ) );
     229
     230    // ...or remove them.
     231    } elseif ( isset( $_POST['bbp_topic_tags'] ) ) {
     232        $terms = '';
     233
     234    // Existing terms
     235    } else {
     236        $terms = bbp_get_topic_tag_names( $topic_id );
     237    }
    228238
    229239    /** Additional Actions (Before Save) **************************************/
     
    486496    /** Topic Tags ************************************************************/
    487497
    488     if ( !empty( $_POST['bbp_topic_tags'] ) )
     498    // Either replace terms
     499    if ( bbp_allow_topic_tags() && current_user_can( 'assign_topic_tags' ) && ! empty( $_POST['bbp_topic_tags'] ) ) {
    489500        $terms = esc_attr( strip_tags( $_POST['bbp_topic_tags'] ) );
     501
     502    // ...or remove them.
     503    } elseif ( isset( $_POST['bbp_topic_tags'] ) ) {
     504        $terms = '';
     505
     506    // Existing terms
     507    } else {
     508        $terms = bbp_get_topic_tag_names( $topic_id );
     509    }
    490510
    491511    /** Additional Actions (Before Save) **************************************/
  • 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.