WordPress.org

Making WordPress.org

Changeset 5605


Ignore:
Timestamp:
06/29/2017 09:32:41 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Support Forums: Only allow 3 published topics from a user in the first 24 hours.

If the user has exceeded their limit, move any new topics to moderation queue.

Props Clorith.
Fixes #2261.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-users.php

    r4144 r5605  
    1515        // Custom user contact methods.
    1616        add_filter( 'user_contactmethods', array( $this, 'custom_contact_methods' ) );
     17
     18        // Only allow 3 published topics from a user in the first 24 hours.
     19        add_action( 'bbp_new_topic_pre_insert', array( $this, 'limit_new_user_topics' ) );
    1720    }
    1821
     
    6366    }
    6467
     68    /**
     69     * Only allow 3 published topics from a user in the first 24 hours.
     70     *
     71     * If the user has exceeded their limit, move any new topics to moderation queue.
     72     *
     73     * @param array $topic_data Topic data.
     74     * @return array Filtered topic data.
     75     */
     76    public function limit_new_user_topics( $topic_data ) {
     77        $current_user = wp_get_current_user();
     78
     79        if ( time() - strtotime( $current_user->user_registered ) >= DAY_IN_SECONDS ) {
     80            return $topic_data;
     81        }
     82
     83        if ( 'publish' === $topic_data['post_status'] && bbp_get_user_topic_count_raw( $current_user->ID ) >= 3 ) {
     84            $topic_data['post_status'] = 'pending';
     85        }
     86
     87        return $topic_data;
     88    }
     89
    6590}
Note: See TracChangeset for help on using the changeset viewer.