@@ 118-139 (lines=22) @@ | ||
115 | * @param int $max_id Maximum post ID. |
|
116 | * @return int Number of posts. |
|
117 | */ |
|
118 | public function post_count( $status = null, $min_id = null, $max_id = null ) { |
|
119 | global $wpdb; |
|
120 | ||
121 | $where = ''; |
|
122 | ||
123 | if ( $status ) { |
|
124 | $where = "post_status = '" . esc_sql( $status ) . "'"; |
|
125 | } else { |
|
126 | $where = '1=1'; |
|
127 | } |
|
128 | ||
129 | if ( ! empty( $min_id ) ) { |
|
130 | $where .= ' AND ID >= ' . intval( $min_id ); |
|
131 | } |
|
132 | ||
133 | if ( ! empty( $max_id ) ) { |
|
134 | $where .= ' AND ID <= ' . intval( $max_id ); |
|
135 | } |
|
136 | ||
137 | // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
138 | return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE $where" ); |
|
139 | } |
|
140 | ||
141 | /** |
|
142 | * Retrieve the posts with a particular post status. |
|
@@ 299-320 (lines=22) @@ | ||
296 | * @param int $max_id Maximum comment ID. |
|
297 | * @return int Number of comments. |
|
298 | */ |
|
299 | public function comment_count( $status = null, $min_id = null, $max_id = null ) { |
|
300 | global $wpdb; |
|
301 | ||
302 | $comment_approved = $this->comment_status_to_approval_value( $status ); |
|
303 | ||
304 | if ( false !== $comment_approved ) { |
|
305 | $where = "comment_approved = '" . esc_sql( $comment_approved ) . "'"; |
|
306 | } else { |
|
307 | $where = '1=1'; |
|
308 | } |
|
309 | ||
310 | if ( ! empty( $min_id ) ) { |
|
311 | $where .= ' AND comment_ID >= ' . intval( $min_id ); |
|
312 | } |
|
313 | ||
314 | if ( ! empty( $max_id ) ) { |
|
315 | $where .= ' AND comment_ID <= ' . intval( $max_id ); |
|
316 | } |
|
317 | ||
318 | // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
319 | return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE $where" ); |
|
320 | } |
|
321 | ||
322 | /** |
|
323 | * Translate a comment status to a value of the comment_approved field. |