Changeset 5827 for trunk/src/includes/common/functions.php
- Timestamp:
- 07/14/2015 12:31:42 AM (11 years ago)
- File:
-
- 1 edited
-
trunk/src/includes/common/functions.php (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/common/functions.php
r5790 r5827 672 672 } 673 673 674 // Define global to use get_meta_sql() and get_var() methods675 global $wpdb;676 677 674 // Parse arguments against default values 678 675 $r = bbp_parse_args( $post_data, array( … … 685 682 ), 'check_for_duplicate' ); 686 683 684 // Get the DB 685 $bbp_db = bbp_db(); 686 687 687 // Check for anonymous post 688 688 if ( empty( $r['post_author'] ) && ( !empty( $r['anonymous_data'] ) && !empty( $r['anonymous_data']['bbp_anonymous_email'] ) ) ) { … … 690 690 'key' => '_bbp_anonymous_email', 691 691 'value' => $r['anonymous_data']['bbp_anonymous_email'] 692 ) ), 'post', $ wpdb->posts, 'ID' );692 ) ), 'post', $bbp_db->posts, 'ID' ); 693 693 694 694 $join = $clauses['join']; … … 698 698 } 699 699 700 // Unslash $r to pass through $wpdb->prepare()700 // Unslash $r to pass through DB->prepare() 701 701 // 702 702 // @see: https://bbpress.trac.wordpress.org/ticket/2185/ … … 705 705 706 706 // Prepare duplicate check query 707 $query = $ wpdb->prepare( "SELECT ID FROM {$wpdb->posts} {$join} WHERE post_type = %s AND post_status != %s AND post_author = %d AND post_content = %s {$where}", $r['post_type'], $r['post_status'], $r['post_author'], $r['post_content'] );708 $query .= !empty( $r['post_parent'] ) ? $ wpdb->prepare( " AND post_parent = %d", $r['post_parent'] ) : '';707 $query = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} {$join} WHERE post_type = %s AND post_status != %s AND post_author = %d AND post_content = %s {$where}", $r['post_type'], $r['post_status'], $r['post_author'], $r['post_content'] ); 708 $query .= !empty( $r['post_parent'] ) ? $bbp_db->prepare( " AND post_parent = %d", $r['post_parent'] ) : ''; 709 709 $query .= " LIMIT 1"; 710 710 $dupe = apply_filters( 'bbp_check_for_duplicate_query', $query, $r ); 711 711 712 if ( $ wpdb->get_var( $dupe ) ) {712 if ( $bbp_db->get_var( $dupe ) ) { 713 713 do_action( 'bbp_check_for_duplicate_trigger', $post_data ); 714 714 return false; … … 1451 1451 * 1452 1452 * @since bbPress (r2996) 1453 * 1454 * @global DB $wpdb1453 * @deprecated bbPress (r5814) 1454 * 1455 1455 * @global WP $wp 1456 1456 * @param string $where … … 1459 1459 */ 1460 1460 function bbp_query_post_parent__in( $where, $object = '' ) { 1461 global $wp db, $wp;1461 global $wp; 1462 1462 1463 1463 // Noop if WP core supports this already … … 1476 1476 } 1477 1477 1478 // Get the DB 1479 $bbp_db = bbp_db(); 1480 1478 1481 // Including specific post_parent's 1479 1482 if ( ! empty( $object->query_vars['post_parent__in'] ) ) { 1480 1483 $ids = implode( ',', wp_parse_id_list( $object->query_vars['post_parent__in'] ) ); 1481 $where .= " AND {$ wpdb->posts}.post_parent IN ($ids)";1484 $where .= " AND {$bbp_db->posts}.post_parent IN ($ids)"; 1482 1485 1483 1486 // Excluding specific post_parent's 1484 1487 } elseif ( ! empty( $object->query_vars['post_parent__not_in'] ) ) { 1485 1488 $ids = implode( ',', wp_parse_id_list( $object->query_vars['post_parent__not_in'] ) ); 1486 $where .= " AND {$ wpdb->posts}.post_parent NOT IN ($ids)";1489 $where .= " AND {$bbp_db->posts}.post_parent NOT IN ($ids)"; 1487 1490 } 1488 1491 … … 1506 1509 */ 1507 1510 function bbp_get_public_child_last_id( $parent_id = 0, $post_type = 'post' ) { 1508 global $wpdb;1509 1511 1510 1512 // Bail if nothing passed … … 1528 1530 // Join post statuses together 1529 1531 $post_status = "'" . implode( "', '", $post_status ) . "'"; 1530 1531 $child_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC LIMIT 1;", $parent_id, $post_type ) ); 1532 $bbp_db = bbp_db(); 1533 $query = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC LIMIT 1;", $parent_id, $post_type ); 1534 $child_id = (int) $bbp_db->get_var( $query ); 1532 1535 1533 1536 wp_cache_set( $cache_id, $child_id, 'bbpress_posts' ); … … 1557 1560 */ 1558 1561 function bbp_get_public_child_count( $parent_id = 0, $post_type = 'post' ) { 1559 global $wpdb;1560 1562 1561 1563 // Bail if nothing passed … … 1579 1581 // Join post statuses together 1580 1582 $post_status = "'" . implode( "', '", $post_status ) . "'"; 1581 1582 $child_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $parent_id, $post_type ) ); 1583 $bbp_db = bbp_db(); 1584 $query = $bbp_db->prepare( "SELECT COUNT(ID) FROM {$bbp_db->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $parent_id, $post_type ); 1585 $child_count = (int) $bbp_db->get_var( $query ); 1583 1586 1584 1587 wp_cache_set( $cache_id, $child_count, 'bbpress_posts' ); … … 1610 1613 */ 1611 1614 function bbp_get_public_child_ids( $parent_id = 0, $post_type = 'post' ) { 1612 global $wpdb;1613 1615 1614 1616 // Bail if nothing passed … … 1632 1634 // Join post statuses together 1633 1635 $post_status = "'" . implode( "', '", $post_status ) . "'"; 1634 1635 $child_ids = (array) $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type ) ); 1636 $bbp_db = bbp_db(); 1637 $query = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type ); 1638 $child_ids = (array) $bbp_db->get_col( $query ); 1636 1639 1637 1640 wp_cache_set( $cache_id, $child_ids, 'bbpress_posts' ); … … 1670 1673 */ 1671 1674 function bbp_get_all_child_ids( $parent_id = 0, $post_type = 'post' ) { 1672 global $wpdb;1673 1675 1674 1676 // Bail if nothing passed … … 1712 1714 // Join post statuses together 1713 1715 $post_status = "'" . implode( "', '", $post_status ) . "'"; 1714 1715 $child_ids = (array) $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type ) ); 1716 $bbp_db = bbp_db(); 1717 $query = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type ); 1718 $child_ids = (array) $bbp_db->get_col( $query ); 1716 1719 1717 1720 wp_cache_set( $cache_id, $child_ids, 'bbpress_posts' );
Note: See TracChangeset
for help on using the changeset viewer.