PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.0.20
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.0.20
1.2.73 1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 All 173 releases
userswp / includes / helpers / count.php

count.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.0.20, at includes/helpers/count.php

65 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Gets the post count for a given post type.
4 *
5 * @since 1.0.0
6 * @package userswp
7 * @param int $user_id User Id.
8 * @param string $post_type Post Type.
9 * @param string $extra_post_status Optional. Extra post status.
10 * @return int Post count.
11 */
12 function uwp_post_count($user_id, $post_type, $extra_post_status = '') {
13 global $wpdb;
14
15 $post_status = "";
16 if ($user_id == get_current_user_id()) {
17 $post_status = ' OR post_status = "draft" OR post_status = "private" ';
18 }
19
20 if (!empty($extra_post_status)) {
21 $post_status .= $extra_post_status;
22 }
23
24 $post_status_where = ' AND ( post_status = "publish" ' . $post_status . ' )';
25
26 if($extra_post_status == 'any'){
27 $post_status_where = '';
28 }
29
30 $count = $wpdb->get_var('
31 SELECT COUNT(ID)
32 FROM ' . $wpdb->posts. '
33 WHERE post_author = "' . $user_id . '"
34 ' . $post_status_where . '
35 AND post_type = "' . $post_type . '"'
36 );
37 return $count;
38 }
39
40 /**
41 * Gets the comment count.
42 *
43 * @since 1.0.0
44 * @package userswp
45 * @param int $user_id User ID.
46 * @return int Comment count.
47 */
48 function uwp_comment_count($user_id) {
49 global $wpdb;
50
51 $count = $wpdb->get_var(
52 "SELECT COUNT(comment_ID)
53 FROM ".$wpdb->comments."
54 WHERE comment_post_ID in (
55 SELECT ID
56 FROM ".$wpdb->posts."
57 WHERE post_type = 'post'
58 AND post_status = 'publish')
59 AND user_id = " . $user_id . "
60 AND comment_approved = '1'
61 AND comment_type NOT IN ('pingback', 'trackback' )"
62 );
63
64 return $count;
65 }