Skip to:
Content

bbPress.org

Changeset 4499


Ignore:
Timestamp:
11/24/2012 06:52:37 PM (13 years ago)
Author:
johnjamesjacoby
Message:

Extract:

  • Remove extract() from bbp_check_for_duplicate().
  • Improve code in bbp_check_for_duplicate() to support this.
  • See #2056.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/common/functions.php

    r4492 r4499  
    643643 * @return bool True if it is not a duplicate, false if it is
    644644 */
    645 function bbp_check_for_duplicate( $post_data ) {
     645function bbp_check_for_duplicate( $post_data = array() ) {
    646646
    647647    // No duplicate checks for those who can throttle
     
    649649        return true;
    650650
    651     global $wpdb;
    652 
    653     extract( $post_data, EXTR_SKIP );
     651    $r = bbp_parse_args( $post_data, array(
     652        'post_author'    => 0,
     653        'post_type'      => array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ),
     654        'post_parent'    => 0,
     655        'post_content'   => '',
     656        'post_status'    => bbp_get_trash_status_id(),
     657        'anonymous_data' => false
     658    ), 'check_for_duplicate' );
    654659
    655660    // Check for anonymous post
    656     if ( empty( $post_author ) && ( isset( $anonymous_data ) && !empty( $anonymous_data['bbp_anonymous_email'] ) ) ) {
     661    if ( empty( $r['post_author'] ) && ( !empty( $r['anonymous_data'] ) && !empty( $r['anonymous_data']['bbp_anonymous_email'] ) ) ) {
    657662        $clauses = get_meta_sql( array( array(
    658663            'key'   => '_bbp_anonymous_email',
    659             'value' => $anonymous_data['bbp_anonymous_email']
     664            'value' => $r['anonymous_data']['bbp_anonymous_email']
    660665        ) ), 'post', $wpdb->posts, 'ID' );
    661666
     
    668673    // Simple duplicate check
    669674    // Expected slashed ($post_type, $post_parent, $post_author, $post_content, $anonymous_data)
    670     $status = bbp_get_trash_status_id();
    671     $dupe   = "SELECT ID FROM {$wpdb->posts} {$join} WHERE post_type = '{$post_type}' AND post_status != '{$status}' AND post_author = {$post_author} AND post_content = '{$post_content}' {$where}";
    672     $dupe  .= !empty( $post_parent ) ? " AND post_parent = '{$post_parent}'" : '';
    673     $dupe  .= " LIMIT 1";
    674     $dupe   = apply_filters( 'bbp_check_for_duplicate_query', $dupe, $post_data );
     675    $query  = "SELECT ID FROM {$wpdb->posts} {$join} WHERE post_type = '{$r['post_type']}' AND post_status != '{$r['post_status']}' AND post_author = {$r['post_author']} AND post_content = '{$r['post_content']}' {$where}";
     676    $query .= !empty( $r['post_parent'] ) ? " AND post_parent = '{$r['post_parent']}'" : '';
     677    $query .= " LIMIT 1";
     678    $dupe   = apply_filters( 'bbp_check_for_duplicate_query', $query, $r );
     679
     680    global $wpdb;
    675681
    676682    if ( $wpdb->get_var( $dupe ) ) {
Note: See TracChangeset for help on using the changeset viewer.