| 1208 | // Check if a throttle time is required. |
| 1209 | if ( $r['throttle'] > 0 ) { |
| 1210 | |
| 1211 | // Throttle to one activity of this type per 2 hours |
| 1212 | $existing = bp_activity_get( array( |
| 1213 | 'max' => 1, |
| 1214 | 'filter' => array( |
| 1215 | 'user_id' => $r['user_id'] |
| 1216 | 'object' => $r['component'], |
| 1217 | 'action' => $r['action'], |
| 1218 | ), |
| 1219 | ) ); |
| 1220 | |
| 1221 | // Default throttle time is 2 hours. Filter to change (in seconds) |
| 1222 | if ( ! empty( $existing['activities'] ) ) { |
| 1223 | $throttle_period = apply_filters( 'bp_' . $r['component'] . '_' . $r['action'] . '_activity_throttle_time', HOUR_IN_SECONDS * 2 ); |
| 1224 | $then = strtotime( $existing['activities'][0]->date_recorded ); |
| 1225 | $now = strtotime( bp_core_current_time() ); |
| 1226 | |
| 1227 | // Bail if throttled |
| 1228 | if ( ( $now - $then ) < $throttle_period ) { |
| 1229 | return false; |
| 1230 | } |
| 1231 | } |
| 1232 | } |
| 1233 | |