Changeset 38279
- Timestamp:
- 08/18/2016 07:38:18 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/query.php
r38125 r38279 1320 1320 1321 1321 private $compat_methods = array( 'init_query_flags', 'parse_tax_query' ); 1322 1323 /** 1324 * @since 4.7.0 1325 * @access protected 1326 * @var wpdb 1327 */ 1328 protected $db; 1322 1329 1323 1330 /** … … 2115 2122 * @since 3.7.0 2116 2123 * 2117 * @global wpdb $wpdb WordPress database abstraction object.2118 *2119 2124 * @param array $q Query variables. 2120 2125 * @return string WHERE clause. 2121 2126 */ 2122 2127 protected function parse_search( &$q ) { 2123 global $wpdb;2124 2125 2128 $search = ''; 2126 2129 … … 2162 2165 2163 2166 if ( $n && $include ) { 2164 $like = '%' . $ wpdb->esc_like( $term ) . '%';2165 $q['search_orderby_title'][] = $ wpdb->prepare( "$wpdb->posts.post_title LIKE %s", $like );2166 } 2167 2168 $like = $n . $ wpdb->esc_like( $term ) . $n;2169 $search .= $ wpdb->prepare( "{$searchand}(($wpdb->posts.post_title $like_op %s) $andor_op ($wpdb->posts.post_excerpt $like_op %s) $andor_op ($wpdb->posts.post_content $like_op %s))", $like, $like, $like );2167 $like = '%' . $this->db->esc_like( $term ) . '%'; 2168 $q['search_orderby_title'][] = $this->db->prepare( "{$this->db->posts}.post_title LIKE %s", $like ); 2169 } 2170 2171 $like = $n . $this->db->esc_like( $term ) . $n; 2172 $search .= $this->db->prepare( "{$searchand}(({$this->db->posts}.post_title $like_op %s) $andor_op ({$this->db->posts}.post_excerpt $like_op %s) $andor_op ({$this->db->posts}.post_content $like_op %s))", $like, $like, $like ); 2170 2173 $searchand = ' AND '; 2171 2174 } … … 2173 2176 if ( ! empty( $search ) ) { 2174 2177 $search = " AND ({$search}) "; 2175 if ( ! is_user_logged_in() ) 2176 $search .= " AND ($wpdb->posts.post_password = '') "; 2178 if ( ! is_user_logged_in() ) { 2179 $search .= " AND ({$this->db->posts}.post_password = '') "; 2180 } 2177 2181 } 2178 2182 … … 2257 2261 * Generate SQL for the ORDER BY condition based on passed search terms. 2258 2262 * 2259 * @global wpdb $wpdb WordPress database abstraction object.2260 *2261 2263 * @param array $q Query variables. 2262 2264 * @return string ORDER BY clause. 2263 2265 */ 2264 2266 protected function parse_search_order( &$q ) { 2265 global $wpdb;2266 2267 2267 if ( $q['search_terms_count'] > 1 ) { 2268 2268 $num_terms = count( $q['search_orderby_title'] ); … … 2271 2271 $like = ''; 2272 2272 if ( ! preg_match( '/(?:\s|^)\-/', $q['s'] ) ) { 2273 $like = '%' . $ wpdb->esc_like( $q['s'] ) . '%';2273 $like = '%' . $this->db->esc_like( $q['s'] ) . '%'; 2274 2274 } 2275 2275 … … 2278 2278 // sentence match in 'post_title' 2279 2279 if ( $like ) { 2280 $search_orderby .= $ wpdb->prepare( "WHEN $wpdb->posts.post_title LIKE %s THEN 1 ", $like );2280 $search_orderby .= $this->db->prepare( "WHEN {$this->db->posts}.post_title LIKE %s THEN 1 ", $like ); 2281 2281 } 2282 2282 … … 2293 2293 // Sentence match in 'post_content' and 'post_excerpt'. 2294 2294 if ( $like ) { 2295 $search_orderby .= $ wpdb->prepare( "WHEN $wpdb->posts.post_excerpt LIKE %s THEN 4 ", $like );2296 $search_orderby .= $ wpdb->prepare( "WHEN $wpdb->posts.post_content LIKE %s THEN 5 ", $like );2295 $search_orderby .= $this->db->prepare( "WHEN {$this->db->posts}.post_excerpt LIKE %s THEN 4 ", $like ); 2296 $search_orderby .= $this->db->prepare( "WHEN {$this->db->posts}.post_content LIKE %s THEN 5 ", $like ); 2297 2297 } 2298 2298 … … 2315 2315 * @access protected 2316 2316 * 2317 * @global wpdb $wpdb WordPress database abstraction object.2318 *2319 2317 * @param string $orderby Alias for the field to order by. 2320 2318 * @return string|false Table-prefixed value to used in the ORDER clause. False otherwise. 2321 2319 */ 2322 2320 protected function parse_orderby( $orderby ) { 2323 global $wpdb;2324 2325 2321 // Used to filter values. 2326 2322 $allowed_keys = array( … … 2369 2365 case 'menu_order': 2370 2366 case 'comment_count': 2371 $orderby_clause = " $wpdb->posts.{$orderby}";2367 $orderby_clause = "{$this->db->posts}.{$orderby}"; 2372 2368 break; 2373 2369 case 'rand': … … 2394 2390 } else { 2395 2391 // Default: order by post field. 2396 $orderby_clause = " $wpdb->posts.post_" . sanitize_key( $orderby );2392 $orderby_clause = "{$this->db->posts}.post_" . sanitize_key( $orderby ); 2397 2393 } 2398 2394 … … 2481 2477 * @access public 2482 2478 * 2483 * @global wpdb $wpdb WordPress database abstraction object.2484 *2485 2479 * @return array List of posts. 2486 2480 */ 2487 2481 public function get_posts() { 2488 global $wpdb;2489 2490 2482 $this->parse_query(); 2491 2483 … … 2623 2615 switch ( $q['fields'] ) { 2624 2616 case 'ids': 2625 $fields = " $wpdb->posts.ID";2617 $fields = "{$this->db->posts}.ID"; 2626 2618 break; 2627 2619 case 'id=>parent': 2628 $fields = " $wpdb->posts.ID, $wpdb->posts.post_parent";2620 $fields = "{$this->db->posts}.ID, {$this->db->posts}.post_parent"; 2629 2621 break; 2630 2622 default: 2631 $fields = " $wpdb->posts.*";2632 } 2633 2634 if ( '' !== $q['menu_order'] ) 2635 $where .= " AND $wpdb->posts.menu_order = " . $q['menu_order'];2636 2623 $fields = "{$this->db->posts}.*"; 2624 } 2625 2626 if ( '' !== $q['menu_order'] ) { 2627 $where .= " AND {$this->db->posts}.menu_order = " . $q['menu_order']; 2628 } 2637 2629 // The "m" parameter is meant for months but accepts datetimes of varying specificity 2638 2630 if ( $q['m'] ) { 2639 $where .= " AND YEAR($wpdb->posts.post_date)=" . substr($q['m'], 0, 4); 2640 if ( strlen($q['m']) > 5 ) 2641 $where .= " AND MONTH($wpdb->posts.post_date)=" . substr($q['m'], 4, 2); 2642 if ( strlen($q['m']) > 7 ) 2643 $where .= " AND DAYOFMONTH($wpdb->posts.post_date)=" . substr($q['m'], 6, 2); 2644 if ( strlen($q['m']) > 9 ) 2645 $where .= " AND HOUR($wpdb->posts.post_date)=" . substr($q['m'], 8, 2); 2646 if ( strlen($q['m']) > 11 ) 2647 $where .= " AND MINUTE($wpdb->posts.post_date)=" . substr($q['m'], 10, 2); 2648 if ( strlen($q['m']) > 13 ) 2649 $where .= " AND SECOND($wpdb->posts.post_date)=" . substr($q['m'], 12, 2); 2631 $where .= " AND YEAR({$this->db->posts}.post_date)=" . substr($q['m'], 0, 4); 2632 if ( strlen($q['m']) > 5 ) { 2633 $where .= " AND MONTH({$this->db->posts}.post_date)=" . substr($q['m'], 4, 2); 2634 } 2635 if ( strlen($q['m']) > 7 ) { 2636 $where .= " AND DAYOFMONTH({$this->db->posts}.post_date)=" . substr($q['m'], 6, 2); 2637 } 2638 if ( strlen($q['m']) > 9 ) { 2639 $where .= " AND HOUR({$this->db->posts}.post_date)=" . substr($q['m'], 8, 2); 2640 } 2641 if ( strlen($q['m']) > 11 ) { 2642 $where .= " AND MINUTE({$this->db->posts}.post_date)=" . substr($q['m'], 10, 2); 2643 } 2644 if ( strlen($q['m']) > 13 ) { 2645 $where .= " AND SECOND({$this->db->posts}.post_date)=" . substr($q['m'], 12, 2); 2646 } 2650 2647 } 2651 2648 … … 2710 2707 2711 2708 if ( '' !== $q['title'] ) { 2712 $where .= $ wpdb->prepare( " AND $wpdb->posts.post_title = %s", stripslashes( $q['title'] ) );2709 $where .= $this->db->prepare( " AND {$this->db->posts}.post_title = %s", stripslashes( $q['title'] ) ); 2713 2710 } 2714 2711 … … 2716 2713 if ( '' != $q['name'] ) { 2717 2714 $q['name'] = sanitize_title_for_query( $q['name'] ); 2718 $where .= " AND $wpdb->posts.post_name = '" . $q['name'] . "'";2715 $where .= " AND {$this->db->posts}.post_name = '" . $q['name'] . "'"; 2719 2716 } elseif ( '' != $q['pagename'] ) { 2720 2717 if ( isset($this->queried_object_id) ) { … … 2745 2742 $q['pagename'] = sanitize_title_for_query( wp_basename( $q['pagename'] ) ); 2746 2743 $q['name'] = $q['pagename']; 2747 $where .= " AND ( $wpdb->posts.ID = '$reqpage')";2744 $where .= " AND ({$this->db->posts}.ID = '$reqpage')"; 2748 2745 $reqpage_obj = get_post( $reqpage ); 2749 2746 if ( is_object($reqpage_obj) && 'attachment' == $reqpage_obj->post_type ) { … … 2757 2754 $q['attachment'] = sanitize_title_for_query( wp_basename( $q['attachment'] ) ); 2758 2755 $q['name'] = $q['attachment']; 2759 $where .= " AND $wpdb->posts.post_name = '" . $q['attachment'] . "'";2756 $where .= " AND {$this->db->posts}.post_name = '" . $q['attachment'] . "'"; 2760 2757 } elseif ( is_array( $q['post_name__in'] ) && ! empty( $q['post_name__in'] ) ) { 2761 2758 $q['post_name__in'] = array_map( 'sanitize_title_for_query', $q['post_name__in'] ); 2762 2759 $post_name__in = "'" . implode( "','", $q['post_name__in'] ) . "'"; 2763 $where .= " AND $wpdb->posts.post_name IN ($post_name__in)";2760 $where .= " AND {$this->db->posts}.post_name IN ($post_name__in)"; 2764 2761 } 2765 2762 … … 2770 2767 // If a post number is specified, load that post 2771 2768 if ( $q['p'] ) { 2772 $where .= " AND {$ wpdb->posts}.ID = " . $q['p'];2769 $where .= " AND {$this->db->posts}.ID = " . $q['p']; 2773 2770 } elseif ( $q['post__in'] ) { 2774 2771 $post__in = implode(',', array_map( 'absint', $q['post__in'] )); 2775 $where .= " AND {$ wpdb->posts}.ID IN ($post__in)";2772 $where .= " AND {$this->db->posts}.ID IN ($post__in)"; 2776 2773 } elseif ( $q['post__not_in'] ) { 2777 2774 $post__not_in = implode(',', array_map( 'absint', $q['post__not_in'] )); 2778 $where .= " AND {$ wpdb->posts}.ID NOT IN ($post__not_in)";2775 $where .= " AND {$this->db->posts}.ID NOT IN ($post__not_in)"; 2779 2776 } 2780 2777 2781 2778 if ( is_numeric( $q['post_parent'] ) ) { 2782 $where .= $ wpdb->prepare( " AND $wpdb->posts.post_parent = %d ", $q['post_parent'] );2779 $where .= $this->db->prepare( " AND {$this->db->posts}.post_parent = %d ", $q['post_parent'] ); 2783 2780 } elseif ( $q['post_parent__in'] ) { 2784 2781 $post_parent__in = implode( ',', array_map( 'absint', $q['post_parent__in'] ) ); 2785 $where .= " AND {$ wpdb->posts}.post_parent IN ($post_parent__in)";2782 $where .= " AND {$this->db->posts}.post_parent IN ($post_parent__in)"; 2786 2783 } elseif ( $q['post_parent__not_in'] ) { 2787 2784 $post_parent__not_in = implode( ',', array_map( 'absint', $q['post_parent__not_in'] ) ); 2788 $where .= " AND {$ wpdb->posts}.post_parent NOT IN ($post_parent__not_in)";2785 $where .= " AND {$this->db->posts}.post_parent NOT IN ($post_parent__not_in)"; 2789 2786 } 2790 2787 … … 2792 2789 if ( ('page' != get_option('show_on_front') ) || ( $q['page_id'] != get_option('page_for_posts') ) ) { 2793 2790 $q['p'] = $q['page_id']; 2794 $where = " AND {$ wpdb->posts}.ID = " . $q['page_id'];2791 $where = " AND {$this->db->posts}.ID = " . $q['page_id']; 2795 2792 } 2796 2793 } … … 2817 2814 $this->parse_tax_query( $q ); 2818 2815 2819 $clauses = $this->tax_query->get_sql( $ wpdb->posts, 'ID' );2816 $clauses = $this->tax_query->get_sql( $this->db->posts, 'ID' ); 2820 2817 2821 2818 $join .= $clauses['join']; … … 2901 2898 2902 2899 if ( !empty( $this->tax_query->queries ) || !empty( $this->meta_query->queries ) ) { 2903 $groupby = "{$ wpdb->posts}.ID";2900 $groupby = "{$this->db->posts}.ID"; 2904 2901 } 2905 2902 … … 2918 2915 if ( ! empty( $q['author__not_in'] ) ) { 2919 2916 $author__not_in = implode( ',', array_map( 'absint', array_unique( (array) $q['author__not_in'] ) ) ); 2920 $where .= " AND {$ wpdb->posts}.post_author NOT IN ($author__not_in) ";2917 $where .= " AND {$this->db->posts}.post_author NOT IN ($author__not_in) "; 2921 2918 } elseif ( ! empty( $q['author__in'] ) ) { 2922 2919 $author__in = implode( ',', array_map( 'absint', array_unique( (array) $q['author__in'] ) ) ); 2923 $where .= " AND {$ wpdb->posts}.post_author IN ($author__in) ";2920 $where .= " AND {$this->db->posts}.post_author IN ($author__in) "; 2924 2921 } 2925 2922 … … 2939 2936 if ( $q['author'] ) 2940 2937 $q['author'] = $q['author']->ID; 2941 $whichauthor .= " AND ( $wpdb->posts.post_author = " . absint($q['author']) . ')';2938 $whichauthor .= " AND ({$this->db->posts}.post_author = " . absint($q['author']) . ')'; 2942 2939 } 2943 2940 2944 2941 // MIME-Type stuff for attachment browsing 2945 2942 2946 if ( isset( $q['post_mime_type'] ) && '' != $q['post_mime_type'] ) 2947 $whichmimetype = wp_post_mime_type_where( $q['post_mime_type'], $ wpdb->posts );2948 2943 if ( isset( $q['post_mime_type'] ) && '' != $q['post_mime_type'] ) { 2944 $whichmimetype = wp_post_mime_type_where( $q['post_mime_type'], $this->db->posts ); 2945 } 2949 2946 $where .= $search . $whichauthor . $whichmimetype; 2950 2947 2951 2948 if ( ! empty( $this->meta_query->queries ) ) { 2952 $clauses = $this->meta_query->get_sql( 'post', $ wpdb->posts, 'ID', $this );2949 $clauses = $this->meta_query->get_sql( 'post', $this->db->posts, 'ID', $this ); 2953 2950 $join .= $clauses['join']; 2954 2951 $where .= $clauses['where']; … … 2971 2968 $orderby = ''; 2972 2969 } else { 2973 $orderby = " $wpdb->posts.post_date " . $q['order'];2970 $orderby = "{$this->db->posts}.post_date " . $q['order']; 2974 2971 } 2975 2972 } elseif ( 'none' == $q['orderby'] ) { 2976 2973 $orderby = ''; 2977 2974 } elseif ( $q['orderby'] == 'post__in' && ! empty( $post__in ) ) { 2978 $orderby = "FIELD( {$ wpdb->posts}.ID, $post__in )";2975 $orderby = "FIELD( {$this->db->posts}.ID, $post__in )"; 2979 2976 } elseif ( $q['orderby'] == 'post_parent__in' && ! empty( $post_parent__in ) ) { 2980 $orderby = "FIELD( {$ wpdb->posts}.post_parent, $post_parent__in )";2977 $orderby = "FIELD( {$this->db->posts}.post_parent, $post_parent__in )"; 2981 2978 } elseif ( $q['orderby'] == 'post_name__in' && ! empty( $post_name__in ) ) { 2982 $orderby = "FIELD( {$ wpdb->posts}.post_name, $post_name__in )";2979 $orderby = "FIELD( {$this->db->posts}.post_name, $post_name__in )"; 2983 2980 } else { 2984 2981 $orderby_array = array(); … … 3012 3009 3013 3010 if ( empty( $orderby ) ) { 3014 $orderby = " $wpdb->posts.post_date " . $q['order'];3011 $orderby = "{$this->db->posts}.post_date " . $q['order']; 3015 3012 } elseif ( ! empty( $q['order'] ) ) { 3016 3013 $orderby .= " {$q['order']}"; … … 3052 3049 3053 3050 if ( isset( $q['post_password'] ) ) { 3054 $where .= $ wpdb->prepare( " AND $wpdb->posts.post_password = %s", $q['post_password'] );3051 $where .= $this->db->prepare( " AND {$this->db->posts}.post_password = %s", $q['post_password'] ); 3055 3052 if ( empty( $q['perm'] ) ) { 3056 3053 $q['perm'] = 'readable'; 3057 3054 } 3058 3055 } elseif ( isset( $q['has_password'] ) ) { 3059 $where .= sprintf( " AND $wpdb->posts.post_password %s ''", $q['has_password'] ? '!=' : '=' );3056 $where .= sprintf( " AND {$this->db->posts}.post_password %s ''", $q['has_password'] ? '!=' : '=' ); 3060 3057 } 3061 3058 3062 3059 if ( ! empty( $q['comment_status'] ) ) { 3063 $where .= $ wpdb->prepare( " AND $wpdb->posts.comment_status = %s ", $q['comment_status'] );3060 $where .= $this->db->prepare( " AND {$this->db->posts}.comment_status = %s ", $q['comment_status'] ); 3064 3061 } 3065 3062 3066 3063 if ( ! empty( $q['ping_status'] ) ) { 3067 $where .= $ wpdb->prepare( " AND $wpdb->posts.ping_status = %s ", $q['ping_status'] );3064 $where .= $this->db->prepare( " AND {$this->db->posts}.ping_status = %s ", $q['ping_status'] ); 3068 3065 } 3069 3066 3070 3067 if ( 'any' == $post_type ) { 3071 3068 $in_search_post_types = get_post_types( array('exclude_from_search' => false) ); 3072 if ( empty( $in_search_post_types ) ) 3069 if ( empty( $in_search_post_types ) ) { 3073 3070 $where .= ' AND 1=0 '; 3074 else 3075 $where .= " AND $wpdb->posts.post_type IN ('" . join("', '", $in_search_post_types ) . "')"; 3071 } else { 3072 $where .= " AND {$this->db->posts}.post_type IN ('" . join("', '", $in_search_post_types ) . "')"; 3073 } 3076 3074 } elseif ( !empty( $post_type ) && is_array( $post_type ) ) { 3077 $where .= " AND $wpdb->posts.post_type IN ('" . join("', '", $post_type) . "')";3075 $where .= " AND {$this->db->posts}.post_type IN ('" . join("', '", $post_type) . "')"; 3078 3076 } elseif ( ! empty( $post_type ) ) { 3079 $where .= " AND $wpdb->posts.post_type = '$post_type'";3077 $where .= " AND {$this->db->posts}.post_type = '$post_type'"; 3080 3078 $post_type_object = get_post_type_object ( $post_type ); 3081 3079 } elseif ( $this->is_attachment ) { 3082 $where .= " AND $wpdb->posts.post_type = 'attachment'";3080 $where .= " AND {$this->db->posts}.post_type = 'attachment'"; 3083 3081 $post_type_object = get_post_type_object ( 'attachment' ); 3084 3082 } elseif ( $this->is_page ) { 3085 $where .= " AND $wpdb->posts.post_type = 'page'";3083 $where .= " AND {$this->db->posts}.post_type = 'page'"; 3086 3084 $post_type_object = get_post_type_object ( 'page' ); 3087 3085 } else { 3088 $where .= " AND $wpdb->posts.post_type = 'post'";3086 $where .= " AND {$this->db->posts}.post_type = 'post'"; 3089 3087 $post_type_object = get_post_type_object ( 'post' ); 3090 3088 } … … 3115 3113 foreach ( get_post_stati( array( 'exclude_from_search' => true ) ) as $status ) { 3116 3114 if ( ! in_array( $status, $q_status ) ) { 3117 $e_status[] = " $wpdb->posts.post_status <> '$status'";3115 $e_status[] = "{$this->db->posts}.post_status <> '$status'"; 3118 3116 } 3119 3117 } … … 3121 3119 foreach ( get_post_stati() as $status ) { 3122 3120 if ( in_array( $status, $q_status ) ) { 3123 if ( 'private' == $status ) 3124 $p_status[] = "$wpdb->posts.post_status = '$status'"; 3125 else 3126 $r_status[] = "$wpdb->posts.post_status = '$status'"; 3121 if ( 'private' == $status ) { 3122 $p_status[] = "{$this->db->posts}.post_status = '$status'"; 3123 } else { 3124 $r_status[] = "{$this->db->posts}.post_status = '$status'"; 3125 } 3127 3126 } 3128 3127 } … … 3138 3137 } 3139 3138 if ( !empty($r_status) ) { 3140 if ( !empty($q['perm'] ) && 'editable' == $q['perm'] && !current_user_can($edit_others_cap) ) 3141 $statuswheres[] = "( $wpdb->posts.post_author = $user_id " . "AND (" . join( ' OR ', $r_status ) . "))";3142 else3139 if ( !empty($q['perm'] ) && 'editable' == $q['perm'] && !current_user_can($edit_others_cap) ) { 3140 $statuswheres[] = "({$this->db->posts}.post_author = $user_id " . "AND (" . join( ' OR ', $r_status ) . "))"; 3141 } else { 3143 3142 $statuswheres[] = "(" . join( ' OR ', $r_status ) . ")"; 3143 } 3144 3144 } 3145 3145 if ( !empty($p_status) ) { 3146 if ( !empty($q['perm'] ) && 'readable' == $q['perm'] && !current_user_can($read_private_cap) ) 3147 $statuswheres[] = "( $wpdb->posts.post_author = $user_id " . "AND (" . join( ' OR ', $p_status ) . "))";3148 else3146 if ( !empty($q['perm'] ) && 'readable' == $q['perm'] && !current_user_can($read_private_cap) ) { 3147 $statuswheres[] = "({$this->db->posts}.post_author = $user_id " . "AND (" . join( ' OR ', $p_status ) . "))"; 3148 } else { 3149 3149 $statuswheres[] = "(" . join( ' OR ', $p_status ) . ")"; 3150 } 3150 3151 } 3151 3152 if ( $post_status_join ) { 3152 $join .= " LEFT JOIN $wpdb->posts AS p2 ON ($wpdb->posts.post_parent = p2.ID) "; 3153 foreach ( $statuswheres as $index => $statuswhere ) 3154 $statuswheres[$index] = "($statuswhere OR ($wpdb->posts.post_status = 'inherit' AND " . str_replace($wpdb->posts, 'p2', $statuswhere) . "))"; 3153 $join .= " LEFT JOIN {$this->db->posts} AS p2 ON ({$this->db->posts}.post_parent = p2.ID) "; 3154 foreach ( $statuswheres as $index => $statuswhere ) { 3155 $statuswheres[$index] = "($statuswhere OR ({$this->db->posts}.post_status = 'inherit' AND " . str_replace( $this->db->posts, 'p2', $statuswhere ) . "))"; 3156 } 3155 3157 } 3156 3158 $where_status = implode( ' OR ', $statuswheres ); … … 3159 3161 } 3160 3162 } elseif ( !$this->is_singular ) { 3161 $where .= " AND ( $wpdb->posts.post_status = 'publish'";3163 $where .= " AND ({$this->db->posts}.post_status = 'publish'"; 3162 3164 3163 3165 // Add public states. … … 3166 3168 if ( 'publish' == $state ) // Publish is hard-coded above. 3167 3169 continue; 3168 $where .= " OR $wpdb->posts.post_status = '$state'";3170 $where .= " OR {$this->db->posts}.post_status = '$state'"; 3169 3171 } 3170 3172 … … 3172 3174 // Add protected states that should show in the admin all list. 3173 3175 $admin_all_states = get_post_stati( array('protected' => true, 'show_in_admin_all_list' => true) ); 3174 foreach ( (array) $admin_all_states as $state ) 3175 $where .= " OR $wpdb->posts.post_status = '$state'"; 3176 foreach ( (array) $admin_all_states as $state ) { 3177 $where .= " OR {$this->db->posts}.post_status = '$state'"; 3178 } 3176 3179 } 3177 3180 … … 3179 3182 // Add private states that are limited to viewing by the author of a post or someone who has caps to read private states. 3180 3183 $private_states = get_post_stati( array('private' => true) ); 3181 foreach ( (array) $private_states as $state ) 3182 $where .= current_user_can( $read_private_cap ) ? " OR $wpdb->posts.post_status = '$state'" : " OR $wpdb->posts.post_author = $user_id AND $wpdb->posts.post_status = '$state'"; 3184 foreach ( (array) $private_states as $state ) { 3185 $where .= current_user_can( $read_private_cap ) ? " OR {$this->db->posts}.post_status = '$state'" : " OR {$this->db->posts}.post_author = $user_id AND {$this->db->posts}.post_status = '$state'"; 3186 } 3183 3187 } 3184 3188 … … 3231 3235 if ( $this->is_comment_feed && ! $this->is_singular ) { 3232 3236 if ( $this->is_archive || $this->is_search ) { 3233 $cjoin = "JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) $join ";3237 $cjoin = "JOIN {$this->db->posts} ON ({$this->db->comments}.comment_post_ID = {$this->db->posts}.ID) $join "; 3234 3238 $cwhere = "WHERE comment_approved = '1' $where"; 3235 $cgroupby = " $wpdb->comments.comment_id";3239 $cgroupby = "{$this->db->comments}.comment_id"; 3236 3240 } else { // Other non singular e.g. front 3237 $cjoin = "JOIN $wpdb->posts ON ( $wpdb->comments.comment_post_ID = $wpdb->posts.ID )";3241 $cjoin = "JOIN {$this->db->posts} ON ( {$this->db->comments}.comment_post_ID = {$this->db->posts}.ID )"; 3238 3242 $cwhere = "WHERE ( post_status = 'publish' OR ( post_status = 'inherit' && post_type = 'attachment' ) ) AND comment_approved = '1'"; 3239 3243 $cgroupby = ''; … … 3294 3298 $corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : ''; 3295 3299 3296 $comments = (array) $ wpdb->get_results("SELECT $distinct $wpdb->comments.* FROM $wpdb->comments$cjoin $cwhere $cgroupby $corderby $climits");3300 $comments = (array) $this->db->get_results("SELECT $distinct {$this->db->comments}.* FROM {$this->db->comments} $cjoin $cwhere $cgroupby $corderby $climits"); 3297 3301 // Convert to WP_Comment 3298 3302 $this->comments = array_map( 'get_comment', $comments ); … … 3306 3310 $post_ids = join(',', $post_ids); 3307 3311 $join = ''; 3308 if ( $post_ids ) 3309 $where = "AND $wpdb->posts.ID IN ($post_ids) ";3310 else3312 if ( $post_ids ) { 3313 $where = "AND {$this->db->posts}.ID IN ($post_ids) "; 3314 } else { 3311 3315 $where = "AND 0"; 3316 } 3312 3317 } 3313 3318 … … 3548 3553 $found_rows = 'SQL_CALC_FOUND_ROWS'; 3549 3554 3550 $this->request = $old_request = "SELECT $found_rows $distinct $fields FROM $wpdb->posts$join WHERE 1=1 $where $groupby $orderby $limits";3555 $this->request = $old_request = "SELECT $found_rows $distinct $fields FROM {$this->db->posts} $join WHERE 1=1 $where $groupby $orderby $limits"; 3551 3556 3552 3557 if ( !$q['suppress_filters'] ) { … … 3582 3587 if ( 'ids' == $q['fields'] ) { 3583 3588 if ( null === $this->posts ) { 3584 $this->posts = $ wpdb->get_col( $this->request );3589 $this->posts = $this->db->get_col( $this->request ); 3585 3590 } 3586 3591 … … 3594 3599 if ( 'id=>parent' == $q['fields'] ) { 3595 3600 if ( null === $this->posts ) { 3596 $this->posts = $ wpdb->get_results( $this->request );3601 $this->posts = $this->db->get_results( $this->request ); 3597 3602 } 3598 3603 … … 3612 3617 3613 3618 if ( null === $this->posts ) { 3614 $split_the_query = ( $old_request == $this->request && " $wpdb->posts.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 );3619 $split_the_query = ( $old_request == $this->request && "{$this->db->posts}.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 ); 3615 3620 3616 3621 /** … … 3631 3636 // First get the IDs and then fill in the objects 3632 3637 3633 $this->request = "SELECT $found_rows $distinct $wpdb->posts.ID FROM $wpdb->posts$join WHERE 1=1 $where $groupby $orderby $limits";3638 $this->request = "SELECT $found_rows $distinct {$this->db->posts}.ID FROM {$this->db->posts} $join WHERE 1=1 $where $groupby $orderby $limits"; 3634 3639 3635 3640 /** … … 3643 3648 $this->request = apply_filters( 'posts_request_ids', $this->request, $this ); 3644 3649 3645 $ids = $ wpdb->get_col( $this->request );3650 $ids = $this->db->get_col( $this->request ); 3646 3651 3647 3652 if ( $ids ) { … … 3653 3658 } 3654 3659 } else { 3655 $this->posts = $ wpdb->get_results( $this->request );3660 $this->posts = $this->db->get_results( $this->request ); 3656 3661 $this->set_found_posts( $q, $limits ); 3657 3662 } … … 3693 3698 $climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option('posts_per_rss'), &$this ) ); 3694 3699 3695 $comments_request = "SELECT $wpdb->comments.* FROM $wpdb->comments$cjoin $cwhere $cgroupby $corderby $climits";3696 $comments = $ wpdb->get_results($comments_request);3700 $comments_request = "SELECT {$this->db->comments}.* FROM {$this->db->comments} $cjoin $cwhere $cgroupby $corderby $climits"; 3701 $comments = $this->db->get_results($comments_request); 3697 3702 // Convert to WP_Comment 3698 3703 $this->comments = array_map( 'get_comment', $comments ); … … 3837 3842 * @access private 3838 3843 * 3839 * @global wpdb $wpdb WordPress database abstraction object.3840 *3841 3844 * @param array $q Query variables. 3842 3845 * @param string $limits LIMIT clauses of the query. 3843 3846 */ 3844 3847 private function set_found_posts( $q, $limits ) { 3845 global $wpdb;3846 3847 3848 // Bail if posts is an empty array. Continue if posts is an empty string, 3848 3849 // null, or false to accommodate caching plugins that fill posts later. … … 3859 3860 * @param WP_Query &$this The WP_Query instance (passed by reference). 3860 3861 */ 3861 $this->found_posts = $ wpdb->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) );3862 $this->found_posts = $this->db->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) ); 3862 3863 } else { 3863 3864 $this->found_posts = count( $this->posts ); … … 4157 4158 * @param string|array $query URL query string or array of vars. 4158 4159 */ 4159 public function __construct($query = '') { 4160 if ( ! empty($query) ) { 4161 $this->query($query); 4160 public function __construct( $query = '' ) { 4161 $this->db = $GLOBALS['wpdb']; 4162 4163 if ( ! empty( $query ) ) { 4164 $this->query( $query ); 4162 4165 } 4163 4166 }
Note: See TracChangeset
for help on using the changeset viewer.