Skip to:
Content

BuddyPress.org

Ticket #4758: 4758.2.patch

File 4758.2.patch, 1.8 KB (added by johnjamesjacoby, 14 years ago)
  • bp-forums/bp-forums-functions.php

     
    352352 * @param int $user_id The user id
    353353 */
    354354function bp_forums_reply_exists( $text = '', $topic_id = 0, $user_id = 0 ) {
    355         global $wpdb;
    356355
    357356        $reply_exists = false;
    358357
     
    364363                        'topic_id'       => $topic_id
    365364                );
    366365
    367                 // BB_Query's post_text parameter does a MATCH, while we need exact matches
    368                 add_filter( 'get_posts_where', create_function( '$q', 'return $q . " AND p.post_text = \'' . $wpdb->escape( $text ) . '\'";' ) );
     366                // Set the reply_exists_text so we can check it in the filter below
     367                buddypress()->forums->reply_exists_text = $text;
    369368
     369                // BB_Query's post_text parameter does a MATCH, while we need exact matches
     370                add_filter( 'get_posts_where', '_bp_forums_reply_exists_posts_where' );
    370371                $query = new BB_Query( 'post', $args );
     372                remove_filter( 'get_posts_where', '_bp_forums_reply_exists_posts_where' );
    371373
    372                 $reply_exists = !empty( $query->results );
     374                // Cleanup
     375                unset( buddypress()->forums->reply_exists_text );
     376
     377                $reply_exists = (bool) !empty( $query->results );
    373378        }
    374379
    375         return apply_filters( 'bp_forums_reply_exists', $reply_exists, $text, $topic_id, $user_id );
     380        return (bool) apply_filters( 'bp_forums_reply_exists', $reply_exists, $text, $topic_id, $user_id );
    376381}
     382        /**
     383         * Private one-time-use function used in conjunction with bp_forums_reply_exists()
     384         *
     385         * @since BuddyPress (1.7)
     386         * @access private
     387         * @global WPDB $wpdb
     388         * @param string $where
     389         * @return string
     390         */
     391        function _bp_forums_reply_exists_posts_where( $where = '' ) {
     392                return $where . " AND p.post_text = '" . buddypress()->forums->reply_exists_text . "'";
     393        }
    377394
    378395/**
    379396 * Get a total "Topics Started" count for a given user