Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Add Custom Hook Limit
- * @version 1.0
- */
- function mycred_pro_add_custom_hook_limit( $limits ) {
- $limits['h'] = '4 hours';
- return $limits;
- }
- add_filter( 'mycred_hook_limits', 'mycred_pro_add_custom_hook_limit' );
- /**
- * Enforce Custom Hook Limit
- * @version 1.0
- */
- function mycred_pro_run_custom_hook_limit( $over_limit, $instance, $reference, $user_id, $ref_id, $hook ) {
- // Only applicable for the "Viewing Content" hook
- if ( $reference != 'view_content' ) return $over_limit;
- // Prefs
- $prefs = $this->prefs[ $instance ]['limit'];
- // No limit is set, bail
- if ( $prefs == '0/x' ) return $over_limit;
- $prefs = explode( '/', $prefs );
- // Some other limit is used, bail
- if ( $prefs[1] != 'h' ) return $over_limit;
- $maximum = $prefs[0];
- // Get the timestamp for 4 hours ago
- $four_hours_ago = current_time( 'timestamp' ) - ( 4 * HOUR_IN_SECONDS );
- global $wpdb, $mycred_log_table;
- $total_last4_hours = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$mycred_log_table} WHERE ref = %s AND user_id = %d AND time >= %d;", $reference, $user_id, $four_hours_ago ) );
- // Check if we are over the limit
- if ( $total_last4_hours >= $maximum ) return false;
- return true;
- }
- add_filter( 'mycred_over_hook_limit', 'mycred_pro_run_custom_hook_limit', 10, 6 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement