Skip to:
Content

Changeset 6401


Ignore:
Timestamp:
04/20/2017 04:36:57 PM (13 months ago)
Author:
johnjamesjacoby
Message:

Stickies: Update forum/topic meta early in bbp_update_topic()

  • Makes meta-data available earlier for downstream functions
  • Removes ineffective assumption of forum-topic-id when empty

This fixes a situation where trying to stick a new topic to a forum would look for the _bbp_forum_id meta-data before it was updated.

Fixes #3103.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/topics/functions.php

    r6400 r6401  
    811811    }
    812812
    813     // Check forum_id
    814     if ( empty( $forum_id ) ) {
    815         $forum_id = bbp_get_topic_forum_id( $topic_id );
    816     }
     813    // Forum/Topic meta (early, for use in downstream functions)
     814    bbp_update_topic_forum_id( $topic_id, $forum_id );
     815    bbp_update_topic_topic_id( $topic_id, $topic_id );
    817816
    818817    // Get the topic types
     
    820819
    821820    // Sticky check after 'bbp_new_topic' action so forum ID meta is set
    822     if ( ! empty( $_POST['bbp_stick_topic'] ) && in_array( $_POST['bbp_stick_topic'], array_keys( $topic_types ) ) ) {
     821    if ( ! empty( $_POST['bbp_stick_topic'] ) && in_array( $_POST['bbp_stick_topic'], array_keys( $topic_types ), true ) ) {
    823822
    824823        // What's the caps?
     
    866865    if ( bbp_is_subscriptions_active() && ! empty( $author_id ) ) {
    867866        $subscribed = bbp_is_user_subscribed( $author_id, $topic_id );
    868         $subscheck  = ( ! empty( $_POST['bbp_topic_subscription'] ) && ( 'bbp_subscribe' === $_POST['bbp_topic_subscription'] ) ) ? true : false;
     867        $subscheck  = ( ! empty( $_POST['bbp_topic_subscription'] ) && ( 'bbp_subscribe' === $_POST['bbp_topic_subscription'] ) )
     868            ? true
     869            : false;
    869870
    870871        // Subscribed and unsubscribing
     
    877878        }
    878879    }
    879 
    880     // Forum topic meta
    881     bbp_update_topic_forum_id( $topic_id, $forum_id );
    882     bbp_update_topic_topic_id( $topic_id, $topic_id );
    883880
    884881    // Update associated topic values if this is a new topic
     
    20812078 */
    20822079function bbp_get_stickies( $forum_id = 0 ) {
    2083     $stickies = empty( $forum_id ) ? bbp_get_super_stickies() : get_post_meta( $forum_id, '_bbp_sticky_topics', true );
    2084     $stickies = ( empty( $stickies ) || ! is_array( $stickies ) ) ? array() : $stickies;
    2085 
    2086     return apply_filters( 'bbp_get_stickies', $stickies, $forum_id );
     2080
     2081    // Get stickies (maybe super if empty)
     2082    $stickies = empty( $forum_id )
     2083        ? bbp_get_super_stickies()
     2084        : get_post_meta( $forum_id, '_bbp_sticky_topics', true );
     2085
     2086    // Cast as array
     2087    $stickies = ( empty( $stickies ) || ! is_array( $stickies ) )
     2088        ? array()
     2089        : $stickies;
     2090
     2091    // Filter and return
     2092    return (array) apply_filters( 'bbp_get_stickies', $stickies, $forum_id );
    20872093}
    20882094
     
    20972103 */
    20982104function bbp_get_super_stickies() {
     2105
     2106    // Get super stickies
    20992107    $stickies = get_option( '_bbp_super_sticky_topics', array() );
    2100     $stickies = ( empty( $stickies ) || ! is_array( $stickies ) ) ? array() : $stickies;
    2101 
    2102     return apply_filters( 'bbp_get_super_stickies', $stickies );
     2108
     2109    // Cast as array
     2110    $stickies = ( empty( $stickies ) || ! is_array( $stickies ) )
     2111        ? array()
     2112        : $stickies;
     2113
     2114    // Filter and return
     2115    return (array) apply_filters( 'bbp_get_super_stickies', $stickies );
    21032116}
    21042117
Note: See TracChangeset for help on using the changeset viewer.