Skip to:
Content

BuddyPress.org

Ticket #4758: 4758.patch

File 4758.patch, 1.7 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                $reply_exists = (bool) !empty( $query->results );
    373375        }
    374376
    375         return apply_filters( 'bp_forums_reply_exists', $reply_exists, $text, $topic_id, $user_id );
     377        return (bool) apply_filters( 'bp_forums_reply_exists', $reply_exists, $text, $topic_id, $user_id );
    376378}
     379        /**
     380         * Private one-time-use function used in conjunction with bp_forums_reply_exists()
     381         *
     382         * @since BuddyPress (1.7)
     383         * @access private
     384         * @global WPDB $wpdb
     385         * @param string $where
     386         * @return string
     387         */
     388        function _bp_forums_reply_exists_posts_where( $where = '' ) {
     389                global $wpdb;
     390                return $where . $wpdb->prepare( " AND p.post_text = '%s'", buddypress()->forums->reply_exists_text );
     391        }
    377392
    378393/**
    379394 * Get a total "Topics Started" count for a given user