Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/clone/wp-inclu...
File: class-wp-comment-query.php
}
[500] Fix | Delete
}
[501] Fix | Delete
[502] Fix | Delete
// Prime comment post caches.
[503] Fix | Delete
if ( $this->query_vars['update_comment_post_cache'] ) {
[504] Fix | Delete
$comment_post_ids = array();
[505] Fix | Delete
foreach ( $_comments as $_comment ) {
[506] Fix | Delete
$comment_post_ids[] = $_comment->comment_post_ID;
[507] Fix | Delete
}
[508] Fix | Delete
[509] Fix | Delete
_prime_post_caches( $comment_post_ids, false, false );
[510] Fix | Delete
}
[511] Fix | Delete
[512] Fix | Delete
/**
[513] Fix | Delete
* Filters the comment query results.
[514] Fix | Delete
*
[515] Fix | Delete
* @since 3.1.0
[516] Fix | Delete
*
[517] Fix | Delete
* @param WP_Comment[] $_comments An array of comments.
[518] Fix | Delete
* @param WP_Comment_Query $query Current instance of WP_Comment_Query (passed by reference).
[519] Fix | Delete
*/
[520] Fix | Delete
$_comments = apply_filters_ref_array( 'the_comments', array( $_comments, &$this ) );
[521] Fix | Delete
[522] Fix | Delete
// Convert to WP_Comment instances.
[523] Fix | Delete
$comments = array_map( 'get_comment', $_comments );
[524] Fix | Delete
[525] Fix | Delete
if ( $this->query_vars['hierarchical'] ) {
[526] Fix | Delete
$comments = $this->fill_descendants( $comments );
[527] Fix | Delete
}
[528] Fix | Delete
[529] Fix | Delete
$this->comments = $comments;
[530] Fix | Delete
return $this->comments;
[531] Fix | Delete
}
[532] Fix | Delete
[533] Fix | Delete
/**
[534] Fix | Delete
* Used internally to get a list of comment IDs matching the query vars.
[535] Fix | Delete
*
[536] Fix | Delete
* @since 4.4.0
[537] Fix | Delete
*
[538] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[539] Fix | Delete
*
[540] Fix | Delete
* @return int|array A single count of comment IDs if a count query. An array of comment IDs if a full query.
[541] Fix | Delete
*/
[542] Fix | Delete
protected function get_comment_ids() {
[543] Fix | Delete
global $wpdb;
[544] Fix | Delete
[545] Fix | Delete
// Assemble clauses related to 'comment_approved'.
[546] Fix | Delete
$approved_clauses = array();
[547] Fix | Delete
[548] Fix | Delete
// 'status' accepts an array or a comma-separated string.
[549] Fix | Delete
$status_clauses = array();
[550] Fix | Delete
$statuses = wp_parse_list( $this->query_vars['status'] );
[551] Fix | Delete
[552] Fix | Delete
// Empty 'status' should be interpreted as 'all'.
[553] Fix | Delete
if ( empty( $statuses ) ) {
[554] Fix | Delete
$statuses = array( 'all' );
[555] Fix | Delete
}
[556] Fix | Delete
[557] Fix | Delete
// 'any' overrides other statuses.
[558] Fix | Delete
if ( ! in_array( 'any', $statuses, true ) ) {
[559] Fix | Delete
foreach ( $statuses as $status ) {
[560] Fix | Delete
switch ( $status ) {
[561] Fix | Delete
case 'hold':
[562] Fix | Delete
$status_clauses[] = "comment_approved = '0'";
[563] Fix | Delete
break;
[564] Fix | Delete
[565] Fix | Delete
case 'approve':
[566] Fix | Delete
$status_clauses[] = "comment_approved = '1'";
[567] Fix | Delete
break;
[568] Fix | Delete
[569] Fix | Delete
case 'all':
[570] Fix | Delete
case '':
[571] Fix | Delete
$status_clauses[] = "( comment_approved = '0' OR comment_approved = '1' )";
[572] Fix | Delete
break;
[573] Fix | Delete
[574] Fix | Delete
default:
[575] Fix | Delete
$status_clauses[] = $wpdb->prepare( 'comment_approved = %s', $status );
[576] Fix | Delete
break;
[577] Fix | Delete
}
[578] Fix | Delete
}
[579] Fix | Delete
[580] Fix | Delete
if ( ! empty( $status_clauses ) ) {
[581] Fix | Delete
$approved_clauses[] = '( ' . implode( ' OR ', $status_clauses ) . ' )';
[582] Fix | Delete
}
[583] Fix | Delete
}
[584] Fix | Delete
[585] Fix | Delete
// User IDs or emails whose unapproved comments are included, regardless of $status.
[586] Fix | Delete
if ( ! empty( $this->query_vars['include_unapproved'] ) ) {
[587] Fix | Delete
$include_unapproved = wp_parse_list( $this->query_vars['include_unapproved'] );
[588] Fix | Delete
[589] Fix | Delete
foreach ( $include_unapproved as $unapproved_identifier ) {
[590] Fix | Delete
// Numeric values are assumed to be user IDs.
[591] Fix | Delete
if ( is_numeric( $unapproved_identifier ) ) {
[592] Fix | Delete
$approved_clauses[] = $wpdb->prepare( "( user_id = %d AND comment_approved = '0' )", $unapproved_identifier );
[593] Fix | Delete
} else {
[594] Fix | Delete
// Otherwise we match against email addresses.
[595] Fix | Delete
if ( ! empty( $_GET['unapproved'] ) && ! empty( $_GET['moderation-hash'] ) ) {
[596] Fix | Delete
// Only include requested comment.
[597] Fix | Delete
$approved_clauses[] = $wpdb->prepare( "( comment_author_email = %s AND comment_approved = '0' AND {$wpdb->comments}.comment_ID = %d )", $unapproved_identifier, (int) $_GET['unapproved'] );
[598] Fix | Delete
} else {
[599] Fix | Delete
// Include all of the author's unapproved comments.
[600] Fix | Delete
$approved_clauses[] = $wpdb->prepare( "( comment_author_email = %s AND comment_approved = '0' )", $unapproved_identifier );
[601] Fix | Delete
}
[602] Fix | Delete
}
[603] Fix | Delete
}
[604] Fix | Delete
}
[605] Fix | Delete
[606] Fix | Delete
// Collapse comment_approved clauses into a single OR-separated clause.
[607] Fix | Delete
if ( ! empty( $approved_clauses ) ) {
[608] Fix | Delete
if ( 1 === count( $approved_clauses ) ) {
[609] Fix | Delete
$this->sql_clauses['where']['approved'] = $approved_clauses[0];
[610] Fix | Delete
} else {
[611] Fix | Delete
$this->sql_clauses['where']['approved'] = '( ' . implode( ' OR ', $approved_clauses ) . ' )';
[612] Fix | Delete
}
[613] Fix | Delete
}
[614] Fix | Delete
[615] Fix | Delete
$order = ( 'ASC' === strtoupper( $this->query_vars['order'] ) ) ? 'ASC' : 'DESC';
[616] Fix | Delete
[617] Fix | Delete
// Disable ORDER BY with 'none', an empty array, or boolean false.
[618] Fix | Delete
if ( in_array( $this->query_vars['orderby'], array( 'none', array(), false ), true ) ) {
[619] Fix | Delete
$orderby = '';
[620] Fix | Delete
} elseif ( ! empty( $this->query_vars['orderby'] ) ) {
[621] Fix | Delete
$ordersby = is_array( $this->query_vars['orderby'] ) ?
[622] Fix | Delete
$this->query_vars['orderby'] :
[623] Fix | Delete
preg_split( '/[,\s]/', $this->query_vars['orderby'] );
[624] Fix | Delete
[625] Fix | Delete
$orderby_array = array();
[626] Fix | Delete
$found_orderby_comment_id = false;
[627] Fix | Delete
foreach ( $ordersby as $_key => $_value ) {
[628] Fix | Delete
if ( ! $_value ) {
[629] Fix | Delete
continue;
[630] Fix | Delete
}
[631] Fix | Delete
[632] Fix | Delete
if ( is_int( $_key ) ) {
[633] Fix | Delete
$_orderby = $_value;
[634] Fix | Delete
$_order = $order;
[635] Fix | Delete
} else {
[636] Fix | Delete
$_orderby = $_key;
[637] Fix | Delete
$_order = $_value;
[638] Fix | Delete
}
[639] Fix | Delete
[640] Fix | Delete
if ( ! $found_orderby_comment_id && in_array( $_orderby, array( 'comment_ID', 'comment__in' ), true ) ) {
[641] Fix | Delete
$found_orderby_comment_id = true;
[642] Fix | Delete
}
[643] Fix | Delete
[644] Fix | Delete
$parsed = $this->parse_orderby( $_orderby );
[645] Fix | Delete
[646] Fix | Delete
if ( ! $parsed ) {
[647] Fix | Delete
continue;
[648] Fix | Delete
}
[649] Fix | Delete
[650] Fix | Delete
if ( 'comment__in' === $_orderby ) {
[651] Fix | Delete
$orderby_array[] = $parsed;
[652] Fix | Delete
continue;
[653] Fix | Delete
}
[654] Fix | Delete
[655] Fix | Delete
$orderby_array[] = $parsed . ' ' . $this->parse_order( $_order );
[656] Fix | Delete
}
[657] Fix | Delete
[658] Fix | Delete
// If no valid clauses were found, order by comment_date_gmt.
[659] Fix | Delete
if ( empty( $orderby_array ) ) {
[660] Fix | Delete
$orderby_array[] = "$wpdb->comments.comment_date_gmt $order";
[661] Fix | Delete
}
[662] Fix | Delete
[663] Fix | Delete
// To ensure determinate sorting, always include a comment_ID clause.
[664] Fix | Delete
if ( ! $found_orderby_comment_id ) {
[665] Fix | Delete
$comment_id_order = '';
[666] Fix | Delete
[667] Fix | Delete
// Inherit order from comment_date or comment_date_gmt, if available.
[668] Fix | Delete
foreach ( $orderby_array as $orderby_clause ) {
[669] Fix | Delete
if ( preg_match( '/comment_date(?:_gmt)*\ (ASC|DESC)/', $orderby_clause, $match ) ) {
[670] Fix | Delete
$comment_id_order = $match[1];
[671] Fix | Delete
break;
[672] Fix | Delete
}
[673] Fix | Delete
}
[674] Fix | Delete
[675] Fix | Delete
// If no date-related order is available, use the date from the first available clause.
[676] Fix | Delete
if ( ! $comment_id_order ) {
[677] Fix | Delete
foreach ( $orderby_array as $orderby_clause ) {
[678] Fix | Delete
if ( str_contains( 'ASC', $orderby_clause ) ) {
[679] Fix | Delete
$comment_id_order = 'ASC';
[680] Fix | Delete
} else {
[681] Fix | Delete
$comment_id_order = 'DESC';
[682] Fix | Delete
}
[683] Fix | Delete
[684] Fix | Delete
break;
[685] Fix | Delete
}
[686] Fix | Delete
}
[687] Fix | Delete
[688] Fix | Delete
// Default to DESC.
[689] Fix | Delete
if ( ! $comment_id_order ) {
[690] Fix | Delete
$comment_id_order = 'DESC';
[691] Fix | Delete
}
[692] Fix | Delete
[693] Fix | Delete
$orderby_array[] = "$wpdb->comments.comment_ID $comment_id_order";
[694] Fix | Delete
}
[695] Fix | Delete
[696] Fix | Delete
$orderby = implode( ', ', $orderby_array );
[697] Fix | Delete
} else {
[698] Fix | Delete
$orderby = "$wpdb->comments.comment_date_gmt $order";
[699] Fix | Delete
}
[700] Fix | Delete
[701] Fix | Delete
$number = absint( $this->query_vars['number'] );
[702] Fix | Delete
$offset = absint( $this->query_vars['offset'] );
[703] Fix | Delete
$paged = absint( $this->query_vars['paged'] );
[704] Fix | Delete
$limits = '';
[705] Fix | Delete
[706] Fix | Delete
if ( ! empty( $number ) ) {
[707] Fix | Delete
if ( $offset ) {
[708] Fix | Delete
$limits = 'LIMIT ' . $offset . ',' . $number;
[709] Fix | Delete
} else {
[710] Fix | Delete
$limits = 'LIMIT ' . ( $number * ( $paged - 1 ) ) . ',' . $number;
[711] Fix | Delete
}
[712] Fix | Delete
}
[713] Fix | Delete
[714] Fix | Delete
if ( $this->query_vars['count'] ) {
[715] Fix | Delete
$fields = 'COUNT(*)';
[716] Fix | Delete
} else {
[717] Fix | Delete
$fields = "$wpdb->comments.comment_ID";
[718] Fix | Delete
}
[719] Fix | Delete
[720] Fix | Delete
$post_id = absint( $this->query_vars['post_id'] );
[721] Fix | Delete
if ( ! empty( $post_id ) ) {
[722] Fix | Delete
$this->sql_clauses['where']['post_id'] = $wpdb->prepare( 'comment_post_ID = %d', $post_id );
[723] Fix | Delete
}
[724] Fix | Delete
[725] Fix | Delete
// Parse comment IDs for an IN clause.
[726] Fix | Delete
if ( ! empty( $this->query_vars['comment__in'] ) ) {
[727] Fix | Delete
$this->sql_clauses['where']['comment__in'] = "$wpdb->comments.comment_ID IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['comment__in'] ) ) . ' )';
[728] Fix | Delete
}
[729] Fix | Delete
[730] Fix | Delete
// Parse comment IDs for a NOT IN clause.
[731] Fix | Delete
if ( ! empty( $this->query_vars['comment__not_in'] ) ) {
[732] Fix | Delete
$this->sql_clauses['where']['comment__not_in'] = "$wpdb->comments.comment_ID NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['comment__not_in'] ) ) . ' )';
[733] Fix | Delete
}
[734] Fix | Delete
[735] Fix | Delete
// Parse comment parent IDs for an IN clause.
[736] Fix | Delete
if ( ! empty( $this->query_vars['parent__in'] ) ) {
[737] Fix | Delete
$this->sql_clauses['where']['parent__in'] = 'comment_parent IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['parent__in'] ) ) . ' )';
[738] Fix | Delete
}
[739] Fix | Delete
[740] Fix | Delete
// Parse comment parent IDs for a NOT IN clause.
[741] Fix | Delete
if ( ! empty( $this->query_vars['parent__not_in'] ) ) {
[742] Fix | Delete
$this->sql_clauses['where']['parent__not_in'] = 'comment_parent NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['parent__not_in'] ) ) . ' )';
[743] Fix | Delete
}
[744] Fix | Delete
[745] Fix | Delete
// Parse comment post IDs for an IN clause.
[746] Fix | Delete
if ( ! empty( $this->query_vars['post__in'] ) ) {
[747] Fix | Delete
$this->sql_clauses['where']['post__in'] = 'comment_post_ID IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post__in'] ) ) . ' )';
[748] Fix | Delete
}
[749] Fix | Delete
[750] Fix | Delete
// Parse comment post IDs for a NOT IN clause.
[751] Fix | Delete
if ( ! empty( $this->query_vars['post__not_in'] ) ) {
[752] Fix | Delete
$this->sql_clauses['where']['post__not_in'] = 'comment_post_ID NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post__not_in'] ) ) . ' )';
[753] Fix | Delete
}
[754] Fix | Delete
[755] Fix | Delete
if ( '' !== $this->query_vars['author_email'] ) {
[756] Fix | Delete
$this->sql_clauses['where']['author_email'] = $wpdb->prepare( 'comment_author_email = %s', $this->query_vars['author_email'] );
[757] Fix | Delete
}
[758] Fix | Delete
[759] Fix | Delete
if ( '' !== $this->query_vars['author_url'] ) {
[760] Fix | Delete
$this->sql_clauses['where']['author_url'] = $wpdb->prepare( 'comment_author_url = %s', $this->query_vars['author_url'] );
[761] Fix | Delete
}
[762] Fix | Delete
[763] Fix | Delete
if ( '' !== $this->query_vars['karma'] ) {
[764] Fix | Delete
$this->sql_clauses['where']['karma'] = $wpdb->prepare( 'comment_karma = %d', $this->query_vars['karma'] );
[765] Fix | Delete
}
[766] Fix | Delete
[767] Fix | Delete
// Filtering by comment_type: 'type', 'type__in', 'type__not_in'.
[768] Fix | Delete
$raw_types = array(
[769] Fix | Delete
'IN' => array_merge( (array) $this->query_vars['type'], (array) $this->query_vars['type__in'] ),
[770] Fix | Delete
'NOT IN' => (array) $this->query_vars['type__not_in'],
[771] Fix | Delete
);
[772] Fix | Delete
[773] Fix | Delete
$comment_types = array();
[774] Fix | Delete
foreach ( $raw_types as $operator => $_raw_types ) {
[775] Fix | Delete
$_raw_types = array_unique( $_raw_types );
[776] Fix | Delete
[777] Fix | Delete
foreach ( $_raw_types as $type ) {
[778] Fix | Delete
switch ( $type ) {
[779] Fix | Delete
// An empty translates to 'all', for backward compatibility.
[780] Fix | Delete
case '':
[781] Fix | Delete
case 'all':
[782] Fix | Delete
break;
[783] Fix | Delete
[784] Fix | Delete
case 'comment':
[785] Fix | Delete
case 'comments':
[786] Fix | Delete
$comment_types[ $operator ][] = "''";
[787] Fix | Delete
$comment_types[ $operator ][] = "'comment'";
[788] Fix | Delete
break;
[789] Fix | Delete
[790] Fix | Delete
case 'pings':
[791] Fix | Delete
$comment_types[ $operator ][] = "'pingback'";
[792] Fix | Delete
$comment_types[ $operator ][] = "'trackback'";
[793] Fix | Delete
break;
[794] Fix | Delete
[795] Fix | Delete
default:
[796] Fix | Delete
$comment_types[ $operator ][] = $wpdb->prepare( '%s', $type );
[797] Fix | Delete
break;
[798] Fix | Delete
}
[799] Fix | Delete
}
[800] Fix | Delete
[801] Fix | Delete
if ( ! empty( $comment_types[ $operator ] ) ) {
[802] Fix | Delete
$types_sql = implode( ', ', $comment_types[ $operator ] );
[803] Fix | Delete
$this->sql_clauses['where'][ 'comment_type__' . strtolower( str_replace( ' ', '_', $operator ) ) ] = "comment_type $operator ($types_sql)";
[804] Fix | Delete
}
[805] Fix | Delete
}
[806] Fix | Delete
[807] Fix | Delete
$parent = $this->query_vars['parent'];
[808] Fix | Delete
if ( $this->query_vars['hierarchical'] && ! $parent ) {
[809] Fix | Delete
$parent = 0;
[810] Fix | Delete
}
[811] Fix | Delete
[812] Fix | Delete
if ( '' !== $parent ) {
[813] Fix | Delete
$this->sql_clauses['where']['parent'] = $wpdb->prepare( 'comment_parent = %d', $parent );
[814] Fix | Delete
}
[815] Fix | Delete
[816] Fix | Delete
if ( is_array( $this->query_vars['user_id'] ) ) {
[817] Fix | Delete
$this->sql_clauses['where']['user_id'] = 'user_id IN (' . implode( ',', array_map( 'absint', $this->query_vars['user_id'] ) ) . ')';
[818] Fix | Delete
} elseif ( '' !== $this->query_vars['user_id'] ) {
[819] Fix | Delete
$this->sql_clauses['where']['user_id'] = $wpdb->prepare( 'user_id = %d', $this->query_vars['user_id'] );
[820] Fix | Delete
}
[821] Fix | Delete
[822] Fix | Delete
// Falsey search strings are ignored.
[823] Fix | Delete
if ( isset( $this->query_vars['search'] ) && strlen( $this->query_vars['search'] ) ) {
[824] Fix | Delete
$search_sql = $this->get_search_sql(
[825] Fix | Delete
$this->query_vars['search'],
[826] Fix | Delete
array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content' )
[827] Fix | Delete
);
[828] Fix | Delete
[829] Fix | Delete
// Strip leading 'AND'.
[830] Fix | Delete
$this->sql_clauses['where']['search'] = preg_replace( '/^\s*AND\s*/', '', $search_sql );
[831] Fix | Delete
}
[832] Fix | Delete
[833] Fix | Delete
// If any post-related query vars are passed, join the posts table.
[834] Fix | Delete
$join_posts_table = false;
[835] Fix | Delete
$plucked = wp_array_slice_assoc( $this->query_vars, array( 'post_author', 'post_name', 'post_parent' ) );
[836] Fix | Delete
$post_fields = array_filter( $plucked );
[837] Fix | Delete
[838] Fix | Delete
if ( ! empty( $post_fields ) ) {
[839] Fix | Delete
$join_posts_table = true;
[840] Fix | Delete
foreach ( $post_fields as $field_name => $field_value ) {
[841] Fix | Delete
// $field_value may be an array.
[842] Fix | Delete
$esses = array_fill( 0, count( (array) $field_value ), '%s' );
[843] Fix | Delete
[844] Fix | Delete
// phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
[845] Fix | Delete
$this->sql_clauses['where'][ $field_name ] = $wpdb->prepare( " {$wpdb->posts}.{$field_name} IN (" . implode( ',', $esses ) . ')', $field_value );
[846] Fix | Delete
}
[847] Fix | Delete
}
[848] Fix | Delete
[849] Fix | Delete
// 'post_status' and 'post_type' are handled separately, due to the specialized behavior of 'any'.
[850] Fix | Delete
foreach ( array( 'post_status', 'post_type' ) as $field_name ) {
[851] Fix | Delete
$q_values = array();
[852] Fix | Delete
if ( ! empty( $this->query_vars[ $field_name ] ) ) {
[853] Fix | Delete
$q_values = $this->query_vars[ $field_name ];
[854] Fix | Delete
if ( ! is_array( $q_values ) ) {
[855] Fix | Delete
$q_values = explode( ',', $q_values );
[856] Fix | Delete
}
[857] Fix | Delete
[858] Fix | Delete
// 'any' will cause the query var to be ignored.
[859] Fix | Delete
if ( in_array( 'any', $q_values, true ) || empty( $q_values ) ) {
[860] Fix | Delete
continue;
[861] Fix | Delete
}
[862] Fix | Delete
[863] Fix | Delete
$join_posts_table = true;
[864] Fix | Delete
[865] Fix | Delete
$esses = array_fill( 0, count( $q_values ), '%s' );
[866] Fix | Delete
[867] Fix | Delete
// phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
[868] Fix | Delete
$this->sql_clauses['where'][ $field_name ] = $wpdb->prepare( " {$wpdb->posts}.{$field_name} IN (" . implode( ',', $esses ) . ')', $q_values );
[869] Fix | Delete
}
[870] Fix | Delete
}
[871] Fix | Delete
[872] Fix | Delete
// Comment author IDs for an IN clause.
[873] Fix | Delete
if ( ! empty( $this->query_vars['author__in'] ) ) {
[874] Fix | Delete
$this->sql_clauses['where']['author__in'] = 'user_id IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['author__in'] ) ) . ' )';
[875] Fix | Delete
}
[876] Fix | Delete
[877] Fix | Delete
// Comment author IDs for a NOT IN clause.
[878] Fix | Delete
if ( ! empty( $this->query_vars['author__not_in'] ) ) {
[879] Fix | Delete
$this->sql_clauses['where']['author__not_in'] = 'user_id NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['author__not_in'] ) ) . ' )';
[880] Fix | Delete
}
[881] Fix | Delete
[882] Fix | Delete
// Post author IDs for an IN clause.
[883] Fix | Delete
if ( ! empty( $this->query_vars['post_author__in'] ) ) {
[884] Fix | Delete
$join_posts_table = true;
[885] Fix | Delete
$this->sql_clauses['where']['post_author__in'] = 'post_author IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post_author__in'] ) ) . ' )';
[886] Fix | Delete
}
[887] Fix | Delete
[888] Fix | Delete
// Post author IDs for a NOT IN clause.
[889] Fix | Delete
if ( ! empty( $this->query_vars['post_author__not_in'] ) ) {
[890] Fix | Delete
$join_posts_table = true;
[891] Fix | Delete
$this->sql_clauses['where']['post_author__not_in'] = 'post_author NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post_author__not_in'] ) ) . ' )';
[892] Fix | Delete
}
[893] Fix | Delete
[894] Fix | Delete
$join = '';
[895] Fix | Delete
$groupby = '';
[896] Fix | Delete
[897] Fix | Delete
if ( $join_posts_table ) {
[898] Fix | Delete
$join .= "JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID";
[899] Fix | Delete
}
[900] Fix | Delete
[901] Fix | Delete
if ( ! empty( $this->meta_query_clauses ) ) {
[902] Fix | Delete
$join .= $this->meta_query_clauses['join'];
[903] Fix | Delete
[904] Fix | Delete
// Strip leading 'AND'.
[905] Fix | Delete
$this->sql_clauses['where']['meta_query'] = preg_replace( '/^\s*AND\s*/', '', $this->meta_query_clauses['where'] );
[906] Fix | Delete
[907] Fix | Delete
if ( ! $this->query_vars['count'] ) {
[908] Fix | Delete
$groupby = "{$wpdb->comments}.comment_ID";
[909] Fix | Delete
}
[910] Fix | Delete
}
[911] Fix | Delete
[912] Fix | Delete
if ( ! empty( $this->query_vars['date_query'] ) && is_array( $this->query_vars['date_query'] ) ) {
[913] Fix | Delete
$this->date_query = new WP_Date_Query( $this->query_vars['date_query'], 'comment_date' );
[914] Fix | Delete
[915] Fix | Delete
// Strip leading 'AND'.
[916] Fix | Delete
$this->sql_clauses['where']['date_query'] = preg_replace( '/^\s*AND\s*/', '', $this->date_query->get_sql() );
[917] Fix | Delete
}
[918] Fix | Delete
[919] Fix | Delete
$where = implode( ' AND ', $this->sql_clauses['where'] );
[920] Fix | Delete
[921] Fix | Delete
$pieces = array( 'fields', 'join', 'where', 'orderby', 'limits', 'groupby' );
[922] Fix | Delete
[923] Fix | Delete
/**
[924] Fix | Delete
* Filters the comment query clauses.
[925] Fix | Delete
*
[926] Fix | Delete
* @since 3.1.0
[927] Fix | Delete
*
[928] Fix | Delete
* @param string[] $clauses {
[929] Fix | Delete
* Associative array of the clauses for the query.
[930] Fix | Delete
*
[931] Fix | Delete
* @type string $fields The SELECT clause of the query.
[932] Fix | Delete
* @type string $join The JOIN clause of the query.
[933] Fix | Delete
* @type string $where The WHERE clause of the query.
[934] Fix | Delete
* @type string $orderby The ORDER BY clause of the query.
[935] Fix | Delete
* @type string $limits The LIMIT clause of the query.
[936] Fix | Delete
* @type string $groupby The GROUP BY clause of the query.
[937] Fix | Delete
* }
[938] Fix | Delete
* @param WP_Comment_Query $query Current instance of WP_Comment_Query (passed by reference).
[939] Fix | Delete
*/
[940] Fix | Delete
$clauses = apply_filters_ref_array( 'comments_clauses', array( compact( $pieces ), &$this ) );
[941] Fix | Delete
[942] Fix | Delete
$fields = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
[943] Fix | Delete
$join = isset( $clauses['join'] ) ? $clauses['join'] : '';
[944] Fix | Delete
$where = isset( $clauses['where'] ) ? $clauses['where'] : '';
[945] Fix | Delete
$orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
[946] Fix | Delete
$limits = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
[947] Fix | Delete
$groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
[948] Fix | Delete
[949] Fix | Delete
$this->filtered_where_clause = $where;
[950] Fix | Delete
[951] Fix | Delete
if ( $where ) {
[952] Fix | Delete
$where = 'WHERE ' . $where;
[953] Fix | Delete
}
[954] Fix | Delete
[955] Fix | Delete
if ( $groupby ) {
[956] Fix | Delete
$groupby = 'GROUP BY ' . $groupby;
[957] Fix | Delete
}
[958] Fix | Delete
[959] Fix | Delete
if ( $orderby ) {
[960] Fix | Delete
$orderby = "ORDER BY $orderby";
[961] Fix | Delete
}
[962] Fix | Delete
[963] Fix | Delete
$found_rows = '';
[964] Fix | Delete
if ( ! $this->query_vars['no_found_rows'] ) {
[965] Fix | Delete
$found_rows = 'SQL_CALC_FOUND_ROWS';
[966] Fix | Delete
}
[967] Fix | Delete
[968] Fix | Delete
$this->sql_clauses['select'] = "SELECT $found_rows $fields";
[969] Fix | Delete
$this->sql_clauses['from'] = "FROM $wpdb->comments $join";
[970] Fix | Delete
$this->sql_clauses['groupby'] = $groupby;
[971] Fix | Delete
$this->sql_clauses['orderby'] = $orderby;
[972] Fix | Delete
$this->sql_clauses['limits'] = $limits;
[973] Fix | Delete
[974] Fix | Delete
// Beginning of the string is on a new line to prevent leading whitespace. See https://core.trac.wordpress.org/ticket/56841.
[975] Fix | Delete
$this->request =
[976] Fix | Delete
"{$this->sql_clauses['select']}
[977] Fix | Delete
{$this->sql_clauses['from']}
[978] Fix | Delete
{$where}
[979] Fix | Delete
{$this->sql_clauses['groupby']}
[980] Fix | Delete
{$this->sql_clauses['orderby']}
[981] Fix | Delete
{$this->sql_clauses['limits']}";
[982] Fix | Delete
[983] Fix | Delete
if ( $this->query_vars['count'] ) {
[984] Fix | Delete
return (int) $wpdb->get_var( $this->request );
[985] Fix | Delete
} else {
[986] Fix | Delete
$comment_ids = $wpdb->get_col( $this->request );
[987] Fix | Delete
return array_map( 'intval', $comment_ids );
[988] Fix | Delete
}
[989] Fix | Delete
}
[990] Fix | Delete
[991] Fix | Delete
/**
[992] Fix | Delete
* Populates found_comments and max_num_pages properties for the current
[993] Fix | Delete
* query if the limit clause was used.
[994] Fix | Delete
*
[995] Fix | Delete
* @since 4.6.0
[996] Fix | Delete
*
[997] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[998] Fix | Delete
*/
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function