Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function get_user_comments_count_for_last_month() {
- if ( ! is_user_logged_in() ) {
- return 0;
- }
- $user_id = get_current_user_id();
- $last_month = date( 'Y-m-d', strtotime( '-1 month' ) );
- // Get user comments number for the last month
- $args = array(
- 'user_id' => $user_id,
- 'status' => 'approve',
- 'date_query' => array(
- array(
- 'after' => $last_month
- )
- ),
- 'count' => true
- );
- $comments_count = get_comments( $args );
- return $comments_count;
- }
- add_shortcode( 'comments-counter', 'render_comments_counter' );
- function render_comments_counter() {
- $comments_count = get_user_comments_count_for_last_month();
- $message = '';
- if ( $comments_count < 5 ) {
- $diff = 5 - $comments_count;
- $message = $diff . ' Comments still needed';
- } else {
- $message = 'You are elegible for a giveaway!';
- }
- return $message;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement