'moderate' ) ); global $bbmodsuite_cache; $bbmodsuite_cache['banplus'] = array( 'bans' => array(), 'options' => array( 'min_level' => 'moderate' ) ); } function bbmodsuite_banplus_uninstall() { bb_delete_option( 'bbmodsuite_banplus_current_bans' ); bb_delete_option( 'bbmodsuite_banplus_options' ); } /** * bbmodsuite_banplus_set_ban() - Set a ban on a user * * @param int|string $user_id The ID or username of the user to ban. * @param string $type 'temp' for temporary. Other plugins can add more. * @param int $length How long the ban should be in seconds. Defaults to 1 day. * @param string $notes The reason for the ban. * @return bool true on success, false on error * @global $bbmodsuite_cache Cache of options and bans */ function bbmodsuite_banplus_set_ban( $user_id, $type = 'temp', $length = 86400, $notes = '' ) { global $bbmodsuite_cache; $the_options = $bbmodsuite_cache['banplus']['options']; if ( !bb_current_user_can( $the_options['min_level'] ) ) return false; $user_id = bb_get_user_id( $user_id ); if ( !$user_id ) return false; if ( $user_id === bb_get_current_user_info( 'ID' ) ) return false; if ( class_exists( 'BP_User' ) ) $user = new BP_User( $user_id ); else $user = new WP_User( $user_id ); if ( ( $user->has_cap( 'moderate' ) && !bb_current_user_can( 'administrate' ) ) || ( $user->has_cap( 'administrate' ) && !bb_current_user_can( 'use_keys' ) ) ) return false; $current_bans = $bbmodsuite_cache['bans']; if ( $type === 'unban' ) { if ( !isset( $current_bans[$user_id] ) ) return true; unset( $current_bans[$user_id] ); bb_update_option( 'bbmodsuite_banplus_current_bans', $current_bans ); return true; } $length = (int)$length; if ($length <= 0) return false; $until = time() + $length; if ( !in_array( $type, bbmodsuite_banplus_get_ban_types() ) ) return false; if ( $current_bans[$user_id]['type'] === $type && $current_bans[$user_id]['length'] === $length ) return true; if ( isset( $current_bans[$user_id] ) ) return false; $notes = bb_autop( htmlspecialchars( trim( $notes ) ) ); $current_bans[$user_id] = array( 'type' => $type, 'length' => $length, 'on' => time(), 'until' => $until, 'banned_by' => bb_get_current_user_info( 'ID' ), 'notes' => $notes, ); $bbmodsuite_cache['bans'] = $current_bans; bb_update_option( 'bbmodsuite_banplus_current_bans', $current_bans ); return true; } function bbmodsuite_banplus_init() { $current_bans = (array)bb_get_option( 'bbmodsuite_banplus_current_bans' ); $changed = false; foreach ( $current_bans as $user_id => $ban ) { if ( $ban['until'] < time() ) { unset( $current_bans[$user_id] ); $changed = true; } } if ( $changed ) bb_update_option( 'bbmodsuite_banplus_current_bans', $current_bans ); global $bbmodsuite_cache; if ( empty( $bbmodsuite_cache['banplus'] ) ) $bbmodsuite_cache['banplus'] = array( 'bans' => $current_bans, 'options' => bb_get_option( 'bbmodsuite_banplus_options' ) ); } bbmodsuite_banplus_init(); function bbmodsuite_banplus_maybe_block_user() { global $bbmodsuite_cache; $current_bans = $bbmodsuite_cache['banplus']['bans']; if ( !empty( $current_bans[bb_get_current_user_info( 'ID' )] ) ) { switch ( $current_bans[bb_get_current_user_info( 'ID' )]['type'] ) { case 'temp': bb_die( sprintf( __( 'You are banned from this forum until %s from now. The person who banned you said the reason was: %s', 'bbpress-moderation-suite' ), bb_since( time() - ( $current_bans[bb_get_current_user_info( 'ID' )]['until'] - time() ), true ), $current_bans[bb_get_current_user_info( 'ID' )]['notes'] ) ); break; } } } bbmodsuite_banplus_maybe_block_user(); function bbmodsuite_banplus_get_ban_types() { global $bbmodsuite_active_plugins; $types = array( 'temp' ); if ( isset( $bbmodsuite_active_plugins['probation'] ) ) $types[] = 'probation'; return $types; } function bbmodsuite_ban_plus_admin_css() { ?>