Ticket #37463: 37463.diff
File 37463.diff, 23.2 KB (added by , 8 years ago) |
---|
-
src/wp-includes/class-wp-comment-query.php
14 14 * 15 15 * @see WP_Comment_Query::__construct() for accepted arguments. 16 16 */ 17 class WP_Comment_Query {17 class WP_Comment_Query extends WP_Object_Query{ 18 18 19 19 /** 20 * SQL for database query.21 *22 * @since 4.0.123 * @access public24 * @var string25 */26 public $request;27 28 /**29 20 * Metadata query container 30 21 * 31 22 * @since 3.5.0 … … 42 33 * @var array 43 34 */ 44 35 protected $meta_query_clauses; 36 45 37 46 38 /** 47 * SQL query clauses.48 *49 * @since 4.4.050 * @access protected51 * @var array52 */53 protected $sql_clauses = array(54 'select' => '',55 'from' => '',56 'where' => array(),57 'groupby' => '',58 'orderby' => '',59 'limits' => '',60 );61 62 /**63 39 * SQL WHERE clause. 64 40 * 65 41 * Stored after the {@see 'comments_clauses'} filter is run on the compiled WHERE sub-clauses. … … 69 45 * @var string 70 46 */ 71 47 protected $filtered_where_clause; 72 48 73 49 /** 74 * Date query container75 *76 * @since 3.7.077 * @access public78 * @var object WP_Date_Query79 */80 public $date_query = false;81 82 /**83 * Query vars set by the user.84 *85 * @since 3.1.086 * @access public87 * @var array88 */89 public $query_vars;90 91 /**92 * Default values for query vars.93 *94 * @since 4.2.095 * @access public96 * @var array97 */98 public $query_var_defaults;99 100 /**101 50 * List of comments located by the query. 102 51 * 103 52 * @since 4.0.0 … … 115 64 */ 116 65 public $found_comments = 0; 117 66 118 /**119 * The number of pages.120 *121 * @since 4.4.0122 * @access public123 * @var int124 */125 public $max_num_pages = 0;126 67 127 68 /** 128 * Make private/protected methods readable for backward compatibility.129 *130 * @since 4.0.0131 * @access public132 *133 * @param callable $name Method to call.134 * @param array $arguments Arguments to pass when calling.135 * @return mixed|false Return value of the callback, false otherwise.136 */137 public function __call( $name, $arguments ) {138 if ( 'get_search_sql' === $name ) {139 return call_user_func_array( array( $this, $name ), $arguments );140 }141 return false;142 }143 144 /**145 69 * Constructor. 146 70 * 147 71 * Sets up the comment query, based on the query vars passed. … … 260 184 * } 261 185 */ 262 186 public function __construct( $query = '' ) { 187 $this->object_type = 'comment'; 263 188 $this->query_var_defaults = array( 264 189 'author_email' => '', 265 190 'author_url' => '', … … 312 237 } 313 238 } 314 239 315 /**316 * Parse arguments passed to the comment query with default query parameters.317 *318 * @since 4.2.0 Extracted from WP_Comment_Query::query().319 *320 * @access public321 *322 * @param string|array $query WP_Comment_Query arguments. See WP_Comment_Query::__construct()323 */324 public function parse_query( $query = '' ) {325 if ( empty( $query ) ) {326 $query = $this->query_vars;327 }328 240 329 $this->query_vars = wp_parse_args( $query, $this->query_var_defaults ); 330 331 /** 332 * Fires after the comment query vars have been parsed. 333 * 334 * @since 4.2.0 335 * 336 * @param WP_Comment_Query &$this The WP_Comment_Query instance (passed by reference). 337 */ 338 do_action_ref_array( 'parse_comment_query', array( &$this ) ); 339 } 340 341 /** 342 * Sets up the WordPress query for retrieving comments. 343 * 344 * @since 3.1.0 345 * @since 4.1.0 Introduced 'comment__in', 'comment__not_in', 'post_author__in', 346 * 'post_author__not_in', 'author__in', 'author__not_in', 'post__in', 347 * 'post__not_in', 'include_unapproved', 'type__in', and 'type__not_in' 348 * arguments to $query_vars. 349 * @since 4.2.0 Moved parsing to WP_Comment_Query::parse_query(). 350 * @access public 351 * 352 * @param string|array $query Array or URL query string of parameters. 353 * @return array|int List of comments, or number of comments when 'count' is passed as a query var. 354 */ 355 public function query( $query ) { 356 $this->query_vars = wp_parse_args( $query ); 241 protected function get_objects(){ 357 242 return $this->get_comments(); 358 243 } 359 244 … … 914 799 * @global wpdb $wpdb WordPress database abstraction object. 915 800 */ 916 801 private function set_found_comments() { 917 global $wpdb; 918 919 if ( $this->query_vars['number'] && ! $this->query_vars['no_found_rows'] ) { 920 /** 921 * Filters the query used to retrieve found comment count. 922 * 923 * @since 4.4.0 924 * 925 * @param string $found_comments_query SQL query. Default 'SELECT FOUND_ROWS()'. 926 * @param WP_Comment_Query $comment_query The `WP_Comment_Query` instance. 927 */ 928 $found_comments_query = apply_filters( 'found_comments_query', 'SELECT FOUND_ROWS()', $this ); 929 930 $this->found_comments = (int) $wpdb->get_var( $found_comments_query ); 931 } 802 $this->set_found_objects(); 932 803 } 933 804 934 805 /** … … 1060 931 1061 932 return $comments; 1062 933 } 934 1063 935 1064 936 /** 1065 * Used internally to generate an SQL string for searching across multiple columns1066 *1067 * @since 3.1.01068 * @access protected1069 *1070 * @global wpdb $wpdb WordPress database abstraction object.1071 *1072 * @param string $string1073 * @param array $cols1074 * @return string1075 */1076 protected function get_search_sql( $string, $cols ) {1077 global $wpdb;1078 1079 $like = '%' . $wpdb->esc_like( $string ) . '%';1080 1081 $searches = array();1082 foreach ( $cols as $col ) {1083 $searches[] = $wpdb->prepare( "$col LIKE %s", $like );1084 }1085 1086 return ' AND (' . implode(' OR ', $searches) . ')';1087 }1088 1089 /**1090 937 * Parse and sanitize 'orderby' keys passed to the comment query. 1091 938 * 1092 939 * @since 4.2.0 … … 1149 996 1150 997 return $parsed; 1151 998 } 1152 1153 /** 1154 * Parse an 'order' query variable and cast it to ASC or DESC as necessary. 1155 * 1156 * @since 4.2.0 1157 * @access protected 1158 * 1159 * @param string $order The 'order' query variable. 1160 * @return string The sanitized 'order' query variable. 1161 */ 1162 protected function parse_order( $order ) { 1163 if ( ! is_string( $order ) || empty( $order ) ) { 1164 return 'DESC'; 1165 } 1166 1167 if ( 'ASC' === strtoupper( $order ) ) { 1168 return 'ASC'; 1169 } else { 1170 return 'DESC'; 1171 } 1172 } 999 1173 1000 } -
src/wp-includes/class-wp-network-query.php
14 14 * 15 15 * @see WP_Network_Query::__construct() for accepted arguments. 16 16 */ 17 class WP_Network_Query {17 class WP_Network_Query extends WP_Object_Query{ 18 18 19 19 /** 20 * SQL for database query.21 *22 * @since 4.6.023 * @access public24 * @var string25 */26 public $request;27 28 /**29 * SQL query clauses.30 *31 * @since 4.6.032 * @access protected33 * @var array34 */35 protected $sql_clauses = array(36 'select' => '',37 'from' => '',38 'where' => array(),39 'groupby' => '',40 'orderby' => '',41 'limits' => '',42 );43 44 /**45 * Query vars set by the user.46 *47 * @since 4.6.048 * @access public49 * @var array50 */51 public $query_vars;52 53 /**54 * Default values for query vars.55 *56 * @since 4.6.057 * @access public58 * @var array59 */60 public $query_var_defaults;61 62 /**63 20 * List of networks located by the query. 64 21 * 65 22 * @since 4.6.0 … … 77 34 */ 78 35 public $found_networks = 0; 79 36 80 /**81 * The number of pages.82 *83 * @since 4.6.084 * @access public85 * @var int86 */87 public $max_num_pages = 0;88 37 89 38 /** 90 39 * Constructor. … … 124 73 * } 125 74 */ 126 75 public function __construct( $query = '' ) { 76 $this->object_type = 'network'; 127 77 $this->query_var_defaults = array( 128 78 'network__in' => '', 129 79 'network__not_in' => '', … … 149 99 } 150 100 } 151 101 152 /** 153 * Parses arguments passed to the network query with default query parameters. 154 * 155 * @since 4.6.0 156 * 157 * @access public 158 * 159 * @param string|array $query WP_Network_Query arguments. See WP_Network_Query::__construct() 160 */ 161 public function parse_query( $query = '' ) { 162 if ( empty( $query ) ) { 163 $query = $this->query_vars; 164 } 165 166 $this->query_vars = wp_parse_args( $query, $this->query_var_defaults ); 167 168 /** 169 * Fires after the network query vars have been parsed. 170 * 171 * @since 4.6.0 172 * 173 * @param WP_Network_Query &$this The WP_Network_Query instance (passed by reference). 174 */ 175 do_action_ref_array( 'parse_network_query', array( &$this ) ); 176 } 177 178 /** 179 * Sets up the WordPress query for retrieving networks. 180 * 181 * @since 4.6.0 182 * @access public 183 * 184 * @param string|array $query Array or URL query string of parameters. 185 * @return array|int List of networks, or number of networks when 'count' is passed as a query var. 186 */ 187 public function query( $query ) { 188 $this->query_vars = wp_parse_args( $query ); 102 protected function get_objects(){ 189 103 return $this->get_networks(); 190 104 } 191 105 … … 483 397 } 484 398 485 399 /** 486 * Used internally to generate an SQL string for searching across multiple columns.487 *488 * @since 4.6.0489 * @access protected490 *491 * @global wpdb $wpdb WordPress database abstraction object.492 *493 * @param string $string Search string.494 * @param array $columns Columns to search.495 *496 * @return string Search SQL.497 */498 protected function get_search_sql( $string, $columns ) {499 global $wpdb;500 501 $like = '%' . $wpdb->esc_like( $string ) . '%';502 503 $searches = array();504 foreach ( $columns as $column ) {505 $searches[] = $wpdb->prepare( "$column LIKE %s", $like );506 }507 508 return '(' . implode( ' OR ', $searches ) . ')';509 }510 511 /**512 400 * Parses and sanitizes 'orderby' keys passed to the network query. 513 401 * 514 402 * @since 4.6.0 … … 541 429 542 430 return $parsed; 543 431 } 544 545 /**546 * Parses an 'order' query variable and cast it to 'ASC' or 'DESC' as necessary.547 *548 * @since 4.6.0549 * @access protected550 *551 * @param string $order The 'order' query variable.552 * @return string The sanitized 'order' query variable.553 */554 protected function parse_order( $order ) {555 if ( ! is_string( $order ) || empty( $order ) ) {556 return 'ASC';557 }558 559 if ( 'ASC' === strtoupper( $order ) ) {560 return 'ASC';561 } else {562 return 'DESC';563 }564 }565 432 } -
src/wp-includes/class-wp-object-qurey.php
1 <?php 2 3 4 abstract class WP_Object_Query 5 { 6 /** 7 * SQL for database query. 8 * 9 * @since 4.7.0 10 * @access public 11 * @var string 12 */ 13 public $request; 14 15 /** 16 * SQL query clauses. 17 * 18 * @since 4.7.0 19 * @access protected 20 * @var array 21 */ 22 protected $sql_clauses = array( 23 'select' => '', 24 'from' => '', 25 'where' => array(), 26 'groupby' => '', 27 'orderby' => '', 28 'limits' => '', 29 ); 30 31 /** 32 * Date query container. 33 * 34 * @since 4.7.0 35 * @access public 36 * @var object WP_Date_Query 37 */ 38 public $date_query = false; 39 40 /** 41 * Query vars set by the user. 42 * 43 * @since 4.7.0 44 * @access public 45 * @var array 46 */ 47 public $query_vars; 48 49 /** 50 * Default values for query vars. 51 * 52 * @since 4.7.0 53 * @access public 54 * @var array 55 */ 56 public $query_var_defaults; 57 58 /** 59 * The number of pages. 60 * 61 * @since 4.7.0 62 * @access public 63 * @var int 64 */ 65 public $max_num_pages = 0; 66 67 68 /** 69 * Parse arguments passed to the query with default query parameters. 70 * 71 * @since 4.2.0 Extracted from WP_Object_Query::query(). 72 * 73 * @access public 74 * 75 * @param string|array $query WP_Object_Query arguments. See WP_Object_Query::__construct() 76 */ 77 public function parse_query( $query = '' ) { 78 if ( empty( $query ) ) { 79 $query = $this->query_vars; 80 } 81 82 $this->query_vars = wp_parse_args( $query, $this->query_var_defaults ); 83 84 /** 85 * Fires after the comment query vars have been parsed. 86 * 87 * @since 4.2.0 88 * 89 * @param WP_Comment_Query &$this The WP_Comment_Query instance (passed by reference). 90 */ 91 do_action_ref_array( 'parse_' . $this->object_type . '_query', array( &$this ) ); 92 } 93 94 /** 95 * Sets up the WordPress query for retrieving sites. 96 * 97 * @since 4.7.0 98 * @access public 99 * 100 * @param string|array $query Array or URL query string of parameters. 101 * @return array|int List of sites, or number of sites when 'count' is passed as a query var. 102 */ 103 public function query( $query ) { 104 $this->query_vars = wp_parse_args( $query ); 105 106 return $this->get_objects(); 107 } 108 109 110 /** 111 * Populates found_sites and max_num_pages properties for the current query 112 * if the limit clause was used. 113 * 114 * @since 4.7.0 115 * @access private 116 * 117 * @global wpdb $wpdb WordPress database abstraction object. 118 */ 119 protected function set_found_objects() 120 { 121 global $wpdb; 122 123 if ($this->query_vars['number'] && !$this->query_vars['no_found_rows']) { 124 /** 125 * Filters the query used to retrieve found object count. 126 * 127 * @since 4.7.0 128 * 129 * @param string $found_object_query SQL query. Default 'SELECT FOUND_ROWS()'. 130 * @param WP_Object_Query $site_query The `WP_Object_Query` instance. 131 */ 132 $found_object_query = apply_filters('found_' . $this->object_type . '_query', 'SELECT FOUND_ROWS()', $this); 133 134 $this->found_objects = (int)$wpdb->get_var($found_object_query); 135 } 136 } 137 138 /** 139 * Make private/protected methods readable for backward compatibility. 140 * 141 * @since 4.7.0 142 * @access public 143 * 144 * @param callable $name Method to call. 145 * @param array $arguments Arguments to pass when calling. 146 * @return mixed|false Return value of the callback, false otherwise. 147 */ 148 public function __call( $name, $arguments ) { 149 if ( 'get_search_sql' === $name ) { 150 return call_user_func_array( array( $this, $name ), $arguments ); 151 } 152 return false; 153 } 154 155 /** 156 * Used internally to generate an SQL string for searching across multiple columns 157 * 158 * @since 4.7.0 159 * @access protected 160 * 161 * @global wpdb $wpdb WordPress database abstraction object. 162 * 163 * @param string $string 164 * @param array $cols 165 * @return string 166 */ 167 protected function get_search_sql($string, $cols) 168 { 169 global $wpdb; 170 171 $like = '%' . $wpdb->esc_like($string) . '%'; 172 173 $searches = array(); 174 foreach ($cols as $col) { 175 $searches[] = $wpdb->prepare("$col LIKE %s", $like); 176 } 177 178 return ' AND (' . implode(' OR ', $searches) . ')'; 179 } 180 181 /** 182 * Parses and sanitizes 'orderby' keys passed to the network query. 183 * 184 * @since 4.7.0 185 * @access protected 186 * 187 * @global wpdb $wpdb WordPress database abstraction object. 188 * 189 * @param string $orderby Alias for the field to order by. 190 * @return string|false Value to used in the ORDER clause. False otherwise. 191 */ 192 protected function parse_orderby($orderby) 193 { 194 return ''; 195 } 196 197 /** 198 * Parses an 'order' query variable and cast it to 'ASC' or 'DESC' as necessary. 199 * 200 * @since 4.7.0 201 * @access protected 202 * 203 * @param string $order The 'order' query variable. 204 * @return string The sanitized 'order' query variable. 205 */ 206 protected function parse_order($order) 207 { 208 if (!is_string($order) || empty($order)) { 209 return 'ASC'; 210 } 211 212 if ('ASC' === strtoupper($order)) { 213 return 'ASC'; 214 } else { 215 return 'DESC'; 216 } 217 } 218 } 219 No newline at end of file -
src/wp-includes/class-wp-site-query.php
14 14 * 15 15 * @see WP_Site_Query::__construct() for accepted arguments. 16 16 */ 17 class WP_Site_Query {17 class WP_Site_Query extends WP_Object_Query{ 18 18 19 19 /** 20 20 * SQL for database query. … … 147 147 * } 148 148 */ 149 149 public function __construct( $query = '' ) { 150 $this->object_type = 'site'; 150 151 $this->query_var_defaults = array( 151 152 'fields' => '', 152 153 'ID' => '', … … 183 184 } 184 185 } 185 186 186 /** 187 * Parses arguments passed to the site query with default query parameters. 188 * 189 * @since 4.6.0 190 * @access public 191 * 192 * @see WP_Site_Query::__construct() 193 * 194 * @param string|array $query Array or string of WP_Site_Query arguments. See WP_Site_Query::__construct(). 195 */ 196 public function parse_query( $query = '' ) { 197 if ( empty( $query ) ) { 198 $query = $this->query_vars; 199 } 200 201 $this->query_vars = wp_parse_args( $query, $this->query_var_defaults ); 202 203 /** 204 * Fires after the site query vars have been parsed. 205 * 206 * @since 4.6.0 207 * 208 * @param WP_Site_Query &$this The WP_Site_Query instance (passed by reference). 209 */ 210 do_action_ref_array( 'parse_site_query', array( &$this ) ); 211 } 212 213 /** 214 * Sets up the WordPress query for retrieving sites. 215 * 216 * @since 4.6.0 217 * @access public 218 * 219 * @param string|array $query Array or URL query string of parameters. 220 * @return array|int List of sites, or number of sites when 'count' is passed as a query var. 221 */ 222 public function query( $query ) { 223 $this->query_vars = wp_parse_args( $query ); 224 187 protected function get_objects(){ 225 188 return $this->get_sites(); 226 189 } 227 190 … … 576 539 * @global wpdb $wpdb WordPress database abstraction object. 577 540 */ 578 541 private function set_found_sites() { 579 global $wpdb; 580 581 if ( $this->query_vars['number'] && ! $this->query_vars['no_found_rows'] ) { 582 /** 583 * Filters the query used to retrieve found site count. 584 * 585 * @since 4.6.0 586 * 587 * @param string $found_sites_query SQL query. Default 'SELECT FOUND_ROWS()'. 588 * @param WP_Site_Query $site_query The `WP_Site_Query` instance. 589 */ 590 $found_sites_query = apply_filters( 'found_sites_query', 'SELECT FOUND_ROWS()', $this ); 591 592 $this->found_sites = (int) $wpdb->get_var( $found_sites_query ); 593 } 542 $this->set_found_objects(); 594 543 } 595 544 596 545 /** … … 669 618 670 619 return $parsed; 671 620 } 672 673 /**674 * Parses an 'order' query variable and cast it to 'ASC' or 'DESC' as necessary.675 *676 * @since 4.6.0677 * @access protected678 *679 * @param string $order The 'order' query variable.680 * @return string The sanitized 'order' query variable.681 */682 protected function parse_order( $order ) {683 if ( ! is_string( $order ) || empty( $order ) ) {684 return 'ASC';685 }686 687 if ( 'ASC' === strtoupper( $order ) ) {688 return 'ASC';689 } else {690 return 'DESC';691 }692 }693 621 } -
src/wp-includes/class-wp-user-query.php
14 14 * 15 15 * @see WP_User_Query::prepare_query() for information on accepted arguments. 16 16 */ 17 class WP_User_Query {17 class WP_User_Query extends WP_Object_Query{ 18 18 19 19 /** 20 20 * Query vars, after parsing … … 78 78 * @param null|string|array $query Optional. The query variables. 79 79 */ 80 80 public function __construct( $query = null ) { 81 81 82 if ( ! empty( $query ) ) { 82 83 $this->prepare_query( $query ); 83 84 $this->query(); … … 714 715 return $_orderby; 715 716 } 716 717 717 /**718 * Parse an 'order' query variable and cast it to ASC or DESC as necessary.719 *720 * @since 4.2.0721 * @access protected722 *723 * @param string $order The 'order' query variable.724 * @return string The sanitized 'order' query variable.725 */726 protected function parse_order( $order ) {727 if ( ! is_string( $order ) || empty( $order ) ) {728 return 'DESC';729 }730 718 731 if ( 'ASC' === strtoupper( $order ) ) {732 return 'ASC';733 } else {734 return 'DESC';735 }736 }737 738 719 /** 739 720 * Make private properties readable for backward compatibility. 740 721 * … … 795 776 } 796 777 } 797 778 798 /**799 * Make private/protected methods readable for backward compatibility.800 *801 * @since 4.0.0802 * @access public803 *804 * @param callable $name Method to call.805 * @param array $arguments Arguments to pass when calling.806 * @return mixed Return value of the callback, false otherwise.807 */808 public function __call( $name, $arguments ) {809 if ( 'get_search_sql' === $name ) {810 return call_user_func_array( array( $this, $name ), $arguments );811 }812 return false;813 }814 779 } -
src/wp-includes/query.php
849 849 * @since 1.5.0 850 850 * @since 4.5.0 Removed the `$comments_popup` property. 851 851 */ 852 class WP_Query {852 class WP_Query extends WP_Object_Query{ 853 853 854 854 /** 855 855 * Query vars set by the user … … 861 861 public $query; 862 862 863 863 /** 864 * Query vars, after parsing865 *866 * @since 1.5.0867 * @access public868 * @var array869 */870 public $query_vars = array();871 872 /**873 864 * Taxonomy query, as passed to get_tax_sql() 874 865 * 875 866 * @since 3.1.0 … … 916 907 */ 917 908 public $queried_object_id; 918 909 919 /**920 * Get post database query.921 *922 * @since 2.0.1923 * @access public924 * @var string925 */926 public $request;927 910 911 928 912 /** 929 913 * List of posts. 930 914 * … … 1017 1001 */ 1018 1002 public $found_posts = 0; 1019 1003 1020 /**1021 * The amount of pages.1022 *1023 * @since 2.1.01024 * @access public1025 * @var int1026 */1027 public $max_num_pages = 0;1028 1004 1005 1029 1006 /** 1030 1007 * The amount of comment pages. 1031 1008 * … … 2402 2379 return $orderby_clause; 2403 2380 } 2404 2381 2405 /**2406 * Parse an 'order' query variable and cast it to ASC or DESC as necessary.2407 *2408 * @since 4.0.02409 * @access protected2410 *2411 * @param string $order The 'order' query variable.2412 * @return string The sanitized 'order' query variable.2413 */2414 protected function parse_order( $order ) {2415 if ( ! is_string( $order ) || empty( $order ) ) {2416 return 'DESC';2417 }2418 2382 2419 if ( 'ASC' === strtoupper( $order ) ) {2420 return 'ASC';2421 } else {2422 return 'DESC';2423 }2424 }2425 2426 2383 /** 2427 2384 * Sets the 404 property and saves whether query is feed. 2428 2385 * … … 4035 3992 } 4036 3993 } 4037 3994 4038 /** 4039 * Sets up the WordPress query by parsing query string. 4040 * 4041 * @since 1.5.0 4042 * @access public 4043 * 4044 * @param string $query URL query string. 4045 * @return array List of posts. 4046 */ 4047 public function query( $query ) { 4048 $this->init(); 4049 $this->query = $this->query_vars = wp_parse_args( $query ); 3995 protected function get_objects(){ 4050 3996 return $this->get_posts(); 4051 3997 } 4052 3998 -
src/wp-settings.php
111 111 112 112 // Attach the default filters. 113 113 require( ABSPATH . WPINC . '/default-filters.php' ); 114 require( ABSPATH . WPINC . '/class-wp-object-qurey.php' ); 114 115 115 116 // Initialize multisite if enabled. 116 117 if ( is_multisite() ) {