Skip to:
Content

bbPress.org


Ignore:
Timestamp:
05/29/2017 08:02:13 PM (8 years ago)
Author:
johnjamesjacoby
Message:

Settings: Add _allow_ settings for editing & flooding, and revise the verbiage.

This allows for flood checking & editing to be:

  • Completely disabled
  • Overridden via filters
  • Editing allowed forever
  • A bit more descriptive with additional context provided
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/common/functions.php

    r6438 r6442  
    173173 * @param string $post_date_gmt
    174174 *
     175 * @uses bbp_allow_content_edit()() To make sure editing is allowed
    175176 * @uses get_option() Get the edit lock time
    176177 * @uses current_time() Get the current time
     
    180181 * @return bool
    181182 */
    182 function bbp_past_edit_lock( $post_date_gmt ) {
     183function bbp_past_edit_lock( $post_date_gmt = '' ) {
    183184
    184185    // Assume editing is allowed
    185186    $retval = false;
    186187
    187     // Bail if empty date
    188     if ( ! empty( $post_date_gmt ) ) {
    189 
    190         // Period of time
    191         $lockable  = '+' . get_option( '_bbp_edit_lock', '5' ) . ' minutes';
    192 
    193         // Now
    194         $cur_time  = current_time( 'timestamp', true );
    195 
    196         // Add lockable time to post time
    197         $lock_time = strtotime( $lockable, strtotime( $post_date_gmt ) );
    198 
    199         // Compare
    200         if ( $cur_time >= $lock_time ) {
     188    // Check if date and editing is allowed
     189    if ( ! empty( $post_date_gmt ) && bbp_allow_content_edit() ) {
     190
     191        // Get number of minutes to allow editing for
     192        $minutes = get_option( '_bbp_edit_lock', '5' );
     193
     194        // "0" minutes set, so allow forever
     195        if ( 0 === (int) $minutes ) {
    201196            $retval = true;
     197
     198        // Not "0" so compare
     199        } else {
     200
     201            // Period of time
     202            $lockable  = "+{$minutes} minutes";
     203
     204            // Now
     205            $cur_time  = current_time( 'timestamp', true );
     206
     207            // Add lockable time to post time
     208            $lock_time = strtotime( $lockable, strtotime( $post_date_gmt ) );
     209
     210            // Compare
     211            if ( $cur_time >= $lock_time ) {
     212                $retval = true;
     213            }
    202214        }
    203215    }
    204216
    205217    // Filter & return
    206     return apply_filters( 'bbp_past_edit_lock', (bool) $retval, $cur_time, $lock_time, $post_date_gmt );
     218    return (bool) apply_filters( 'bbp_past_edit_lock', $retval, $cur_time, $lock_time, $post_date_gmt );
    207219}
    208220
     
    669681 * @param int $author_id Optional. Supply if it's a post by a logged in user.
    670682 *                        Do not supply if supplying $anonymous_data.
     683 *
     684 * @suse bbp_allow_content_throttle() To make sure flood checking is enabled
    671685 * @uses get_option() To get the throttle time
    672686 * @uses get_transient() To get the last posted transient of the ip
    673687 * @uses bbp_get_user_last_posted() To get the last posted time of the user
    674688 * @uses current_user_can() To check if the current user can throttle
     689 *
    675690 * @return bool True if there is no flooding, false if there is
    676691 */
    677692function bbp_check_for_flood( $anonymous_data = array(), $author_id = 0 ) {
     693
     694    // Allow for flood check to be skipped
     695    if ( apply_filters( 'bbp_bypass_check_for_flood', false, $anonymous_data, $author_id ) ) {
     696        return true;
     697    }
    678698
    679699    // Option disabled. No flood checks.
    680700    $throttle_time = get_option( '_bbp_throttle_time' );
    681     if ( empty( $throttle_time ) ) {
     701    if ( empty( $throttle_time ) || ! bbp_allow_content_throttle() ) {
    682702        return true;
    683703    }
Note: See TracChangeset for help on using the changeset viewer.