Skip to:
Content

BuddyPress.org

Changeset 6778


Ignore:
Timestamp:
02/08/2013 09:33:37 AM (14 years ago)
Author:
johnjamesjacoby
Message:

Update bp_forums_reply_exists() to use external helper filter instead of escaped create_function() usage. Fixes #4758.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-forums/bp-forums-functions.php

    r6716 r6778  
    353353 */
    354354function bp_forums_reply_exists( $text = '', $topic_id = 0, $user_id = 0 ) {
    355         global $wpdb;
    356355
    357356        $reply_exists = false;
     
    365364                );
    366365
     366                // Set the reply_exists_text so we can check it in the filter below
     367                buddypress()->forums->reply_exists_text = $text;
     368
    367369                // 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 ) . '\'";' ) );
    369 
     370                add_filter( 'get_posts_where', '_bp_forums_reply_exists_posts_where' );
    370371                $query = new BB_Query( 'post', $args );
    371 
    372                 $reply_exists = !empty( $query->results );
    373         }
    374 
    375         return apply_filters( 'bp_forums_reply_exists', $reply_exists, $text, $topic_id, $user_id );
    376 }
     372                remove_filter( 'get_posts_where', '_bp_forums_reply_exists_posts_where' );
     373
     374                // Cleanup
     375                unset( buddypress()->forums->reply_exists_text );
     376
     377                $reply_exists = (bool) !empty( $query->results );
     378        }
     379
     380        return (bool) apply_filters( 'bp_forums_reply_exists', $reply_exists, $text, $topic_id, $user_id );
     381}
     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/**
Note: See TracChangeset for help on using the changeset viewer.