Skip to:
Content

bbPress.org

Changeset 6915


Ignore:
Timestamp:
11/03/2019 03:27:08 AM (5 years ago)
Author:
johnjamesjacoby
Message:

Stickies: make sure unapproved topics are unstuck also.

This commit removes a hard coded call to bbp_unstick_topic() and hooks into the neighboring bbp_stick_topic action, while also hooking into the bbp_unapprove_topic action.

A small bit of code clean-up and inline documentation additions accompany this commit, to improve a bit of the surrounding relevant code.

Fixes #3246.

Location:
trunk/src/includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/core/actions.php

    r6876 r6915  
    240240
    241241// Sticky
    242 add_action( 'bbp_spam_topic',   'bbp_unstick_topic' );
    243 add_action( 'bbp_trash_topic',  'bbp_unstick_topic' );
    244 add_action( 'bbp_delete_topic', 'bbp_unstick_topic' );
     242add_action( 'bbp_stick_topic',     'bbp_unstick_topic' );
     243add_action( 'bbp_unapprove_topic', 'bbp_unstick_topic' );
     244add_action( 'bbp_spam_topic',      'bbp_unstick_topic' );
     245add_action( 'bbp_trash_topic',     'bbp_unstick_topic' );
     246add_action( 'bbp_delete_topic',    'bbp_unstick_topic' );
    245247
    246248// Update topic branch
  • trunk/src/includes/topics/functions.php

    r6855 r6915  
    31093109    }
    31103110
    3111     // We may have a super sticky to which we want to convert into a normal
    3112     // sticky and vice versa; unstick the topic first to avoid any possible error.
    3113     bbp_unstick_topic( $topic_id );
    3114 
    3115     $forum_id = empty( $super ) ? bbp_get_topic_forum_id( $topic_id ) : 0;
     3111    do_action( 'bbp_stick_topic', $topic_id, $super );
     3112
     3113    // Maybe get the forum ID if not getting supers
     3114    $forum_id = empty( $super )
     3115        ? bbp_get_topic_forum_id( $topic_id )
     3116        : 0;
     3117
     3118    // Get the stickies, maybe from the forum ID
    31163119    $stickies = bbp_get_stickies( $forum_id );
    31173120
    3118     do_action( 'bbp_stick_topic', $topic_id, $super );
    3119 
    3120     if ( ! is_array( $stickies ) ) {
    3121         $stickies   = array( $topic_id );
    3122     } else {
    3123         $stickies[] = $topic_id;
    3124     }
     3121    // Add the topic to the stickies
     3122    $stickies[] = $topic_id;
    31253123
    31263124    // Pull out duplicates and empties
     
    31363134    // Reset keys
    31373135    $stickies = array_values( $stickies );
    3138     $success  = ! empty( $super ) ? update_option( '_bbp_super_sticky_topics', $stickies ) : update_post_meta( $forum_id, '_bbp_sticky_topics', $stickies );
     3136
     3137    // Update
     3138    $success  = ! empty( $super )
     3139        ? update_option( '_bbp_super_sticky_topics', $stickies )
     3140        : update_post_meta( $forum_id, '_bbp_sticky_topics', $stickies );
    31393141
    31403142    do_action( 'bbp_stuck_topic', $topic_id, $super, $success );
     
    32383240 */
    32393241function bbp_unstick_topic( $topic_id = 0 ) {
     3242
     3243    // Get topic sticky status
    32403244    $topic_id = bbp_get_topic_id( $topic_id );
    32413245    $super    = bbp_is_topic_super_sticky( $topic_id );
     
    32463250    do_action( 'bbp_unstick_topic', $topic_id );
    32473251
     3252    // Nothing to unstick
    32483253    if ( empty( $stickies ) ) {
    32493254        $success = true;
     3255
     3256    // Topic not in stickies
    32503257    } elseif ( ! in_array( $topic_id, $stickies, true ) ) {
    32513258        $success = true;
     3259
     3260    // Topic not in stickies
    32523261    } elseif ( false === $offset ) {
    32533262        $success = true;
     3263
     3264    // Splice out the offset
    32543265    } else {
    32553266        array_splice( $stickies, $offset, 1 );
     3267
    32563268        if ( empty( $stickies ) ) {
    3257             $success = ! empty( $super ) ? delete_option( '_bbp_super_sticky_topics'            ) : delete_post_meta( $forum_id, '_bbp_sticky_topics'            );
     3269            $success = ! empty( $super )
     3270                ? delete_option( '_bbp_super_sticky_topics' )
     3271                : delete_post_meta( $forum_id, '_bbp_sticky_topics' );
    32583272        } else {
    3259             $success = ! empty( $super ) ? update_option( '_bbp_super_sticky_topics', $stickies ) : update_post_meta( $forum_id, '_bbp_sticky_topics', $stickies );
     3273            $success = ! empty( $super )
     3274                ? update_option( '_bbp_super_sticky_topics', $stickies )
     3275                : update_post_meta( $forum_id, '_bbp_sticky_topics', $stickies );
    32603276        }
    32613277    }
Note: See TracChangeset for help on using the changeset viewer.