Files
beep/includes/class-moderation.php
Krystie ccead50116 Initial commit: Beep WordPress plugin
- Custom post type with likes, replies, moderation, shortcodes
- Beep icon and logo assets
- CSS and JS for frontend
2026-05-18 02:22:57 -07:00

51 lines
1.7 KiB
PHP
Executable File

<?php
if (!defined('ABSPATH')) {
exit;
}
class Beep_Moderation {
const BAN_META_KEY = 'beep_banned';
public static function init() {
add_action('show_user_profile', [__CLASS__, 'profile_field']);
add_action('edit_user_profile', [__CLASS__, 'profile_field']);
add_action('personal_options_update', [__CLASS__, 'save_profile_field']);
add_action('edit_user_profile_update', [__CLASS__, 'save_profile_field']);
}
public static function profile_field($user) {
if (!current_user_can('edit_users') && get_current_user_id() !== $user->ID) {
return;
}
$can_ban = current_user_can('edit_users');
$banned = get_user_meta($user->ID, self::BAN_META_KEY, true) === '1';
?>
<h2>Beep moderation</h2>
<table class="form-table">
<tr>
<th><label for="beep_banned">Beep status</label></th>
<td>
<?php if ($can_ban) : ?>
<label>
<input type="checkbox" name="beep_banned" id="beep_banned" value="1" <?php checked($banned); ?>>
Suspend this user from beeping, liking, and replying
</label>
<?php else : ?>
<?php echo $banned ? 'Your account is currently suspended.' : 'Active.'; ?>
<?php endif; ?>
</td>
</tr>
</table>
<?php
}
public static function save_profile_field($user_id) {
if (!current_user_can('edit_users')) {
return;
}
$val = isset($_POST['beep_banned']) ? '1' : '';
update_user_meta($user_id, self::BAN_META_KEY, $val);
}
}