|
@@ 88-109 (lines=22) @@
|
| 85 |
|
* @param int $max_id Maximum post ID. |
| 86 |
|
* @return int Number of posts. |
| 87 |
|
*/ |
| 88 |
|
public function post_count( $status = null, $min_id = null, $max_id = null ) { |
| 89 |
|
global $wpdb; |
| 90 |
|
|
| 91 |
|
$where = ''; |
| 92 |
|
|
| 93 |
|
if ( $status ) { |
| 94 |
|
$where = "post_status = '" . esc_sql( $status ) . "'"; |
| 95 |
|
} else { |
| 96 |
|
$where = '1=1'; |
| 97 |
|
} |
| 98 |
|
|
| 99 |
|
if ( null !== $min_id ) { |
| 100 |
|
$where .= ' AND ID >= ' . intval( $min_id ); |
| 101 |
|
} |
| 102 |
|
|
| 103 |
|
if ( null !== $max_id ) { |
| 104 |
|
$where .= ' AND ID <= ' . intval( $max_id ); |
| 105 |
|
} |
| 106 |
|
|
| 107 |
|
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 108 |
|
return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE $where" ); |
| 109 |
|
} |
| 110 |
|
|
| 111 |
|
/** |
| 112 |
|
* Retrieve the posts with a particular post status. |
|
@@ 269-290 (lines=22) @@
|
| 266 |
|
* @param int $max_id Maximum comment ID. |
| 267 |
|
* @return int Number of comments. |
| 268 |
|
*/ |
| 269 |
|
public function comment_count( $status = null, $min_id = null, $max_id = null ) { |
| 270 |
|
global $wpdb; |
| 271 |
|
|
| 272 |
|
$comment_approved = $this->comment_status_to_approval_value( $status ); |
| 273 |
|
|
| 274 |
|
if ( false !== $comment_approved ) { |
| 275 |
|
$where = "comment_approved = '" . esc_sql( $comment_approved ) . "'"; |
| 276 |
|
} else { |
| 277 |
|
$where = '1=1'; |
| 278 |
|
} |
| 279 |
|
|
| 280 |
|
if ( null !== $min_id ) { |
| 281 |
|
$where .= ' AND comment_ID >= ' . intval( $min_id ); |
| 282 |
|
} |
| 283 |
|
|
| 284 |
|
if ( null !== $max_id ) { |
| 285 |
|
$where .= ' AND comment_ID <= ' . intval( $max_id ); |
| 286 |
|
} |
| 287 |
|
|
| 288 |
|
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 289 |
|
return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE $where" ); |
| 290 |
|
} |
| 291 |
|
|
| 292 |
|
/** |
| 293 |
|
* Translate a comment status to a value of the comment_approved field. |