Skip to:
Content

bbPress.org

#3222 closed defect (fixed)

Allow editing forever does not work

Reported by: wpdennis Owned by: johnjamesjacoby
Milestone: 2.7 Priority: normal
Severity: normal Version:
Component: API - Moderation Keywords: commit
Cc:

Description

If _bbp_edit_lock is set to 0, to allow editing forever, it will lock immediately.

The function bbp_past_edit_lock() should return true, if editing is no longer possible and false if editing is still possible.

In bbp_past_edit_lock():

<?php

                // "0" minutes set, so allow forever
                if ( 0 === $minutes ) {
                        $retval = true;

$retval should be false in this case.

And turning the logic around to start with $retval = true should be safer, too. If bbp_allow_content_edit() is false or the post date is empty, the return value will be the default value.

With the default value being false it means we are allowed to edit, which is not correct.

Shouldn't it look like this in the trunk:?

<?php
function bbp_past_edit_lock( $post_date_gmt = '' ) {
        
                // Default value
                $retval = true;
        
                // Get number of minutes to allow editing for
                $minutes = (int) get_option( '_bbp_edit_lock', 5 );
        
                // Now
                $cur_time = current_time( 'timestamp', true );
        
                // Period of time
                $lockable  = "+{$minutes} minutes";
        
                // Add lockable time to post time
                $lock_time = strtotime( $lockable, strtotime( $post_date_gmt ) );
        
                // Check if date and editing is allowed
                if ( ! empty( $post_date_gmt ) && bbp_allow_content_edit() ) {
        
                        // "0" minutes set, so allow forever
                        if ( 0 === $minutes ) {
                                $retval = false;
        
                        // Not "0" so compare
                        } elseif ( $cur_time <= $lock_time ) {
                                $retval = false;
                        }
                }
        
                // Filter & return
                return (bool) apply_filters( 'bbp_past_edit_lock', $retval, $cur_time, $lock_time, $post_date_gmt );
        }


Change History (2)

#1 @johnjamesjacoby
11 months ago

  • Component changed from General to API - Moderation
  • Keywords commit added; dev-feedback removed
  • Milestone changed from Awaiting Review to 2.7
  • Owner set to johnjamesjacoby

#2 @johnjamesjacoby
11 months ago

  • Resolution set to fixed
  • Status changed from new to closed

In 6869:

Edit Locking Improvements:

  • Refactor to avoid doing unnecessary computations
  • Invert default return value from false to true, requiring time to pass validation as opposed to assuming
  • Improve obviousness of math computations for easier debuggability
  • Update variables passed into the end return filter
  • Add 6 unit tests for before/on/after, plus support for "0" as infinite
  • Fix bug causing "0" values to return the opposite value
  • Ensure only gmt/utc values are compared
  • Add optional flag to use WordPress time instead
  • Improve inline and function documentation

Fixes #3222. Props wpdennis.

Note: See TracTickets for help on using tickets.