hooks(); } return self::$instance; } private function __construct() {} private function hooks(): void { add_action( 'wp_ajax_arshid6social_resolve_report', array( $this, 'ajax_resolve_report' ) ); add_action( 'wp_ajax_arshid6social_admin_suspend_from_report', array( $this, 'ajax_suspend_from_report' ) ); // Register columns for Screen Options column-visibility checkboxes. add_filter( 'manage_' . $this->screen_id . '_columns', array( $this, 'get_columns' ) ); // Save per-page screen option. add_filter( 'set_screen_option_arshid6social_moderation_per_page', array( $this, 'save_per_page' ), 10, 3 ); add_filter( 'set-screen-option', array( $this, 'save_per_page_legacy' ), 10, 3 ); } // ── Screen Options ──────────────────────────────────────────────────────── public function setup_screen_options(): void { add_screen_option( 'per_page', array( 'label' => __( 'Reports per page', '6arshid-social-community' ), 'default' => 20, 'option' => 'arshid6social_moderation_per_page', ) ); } /** @return array */ public function get_columns(): array { return array( 'report_id' => __( 'ID', '6arshid-social-community' ), 'reporter' => __( 'Reporter', '6arshid-social-community' ), 'reported' => __( 'Reported', '6arshid-social-community' ), 'type' => __( 'Type', '6arshid-social-community' ), 'reason' => __( 'Reason', '6arshid-social-community' ), 'notes' => __( 'Notes / Attachment', '6arshid-social-community' ), 'date' => __( 'Date', '6arshid-social-community' ), 'actions' => __( 'Actions', '6arshid-social-community' ), ); } public function save_per_page( $status, string $option, $value ): int { return (int) $value; } public function save_per_page_legacy( $status, string $option, $value ) { if ( 'arshid6social_moderation_per_page' === $option ) { return (int) $value; } return $status; } // ── Groups tab ──────────────────────────────────────────────────────────── private function render_groups_tab(): void { global $wpdb; $suspend_reasons = $this->get_suspend_reasons(); // phpcs:ignore WordPress.DB.DirectDatabaseQuery $groups = $wpdb->get_results( "SELECT id, name, slug, is_suspended, suspend_reason, creator_id, date_created FROM {$wpdb->prefix}arshid6social_groups ORDER BY is_suspended DESC, date_created DESC LIMIT 100" ); ?>

creator_id ); $is_suspended = (bool) $group->is_suspended; $group_url = home_url( '/groups/' . $group->slug . '/' ); ?>
name ); ?> display_name ); ?> — suspend_reason ? esc_html( $group->suspend_reason ) : '—'; ?>
in_array( $col, $hidden_columns, true ) ? ' hidden' : ''; // ── Request params ──────────────────────────────────────────────────── $view = isset( $_GET['moderation_view'] ) ? sanitize_key( wp_unslash( $_GET['moderation_view'] ) ) : 'reports'; // phpcs:ignore WordPress.Security.NonceVerification $status = isset( $_GET['report_status'] ) ? sanitize_key( wp_unslash( $_GET['report_status'] ) ) : 'pending'; // phpcs:ignore WordPress.Security.NonceVerification $paged = isset( $_GET['paged'] ) ? max( 1, absint( $_GET['paged'] ) ) : 1; // phpcs:ignore WordPress.Security.NonceVerification $allowed_statuses = array( 'pending', 'resolved', 'dismissed' ); if ( ! in_array( $status, $allowed_statuses, true ) ) { $status = 'pending'; } $offset = ( $paged - 1 ) * $per_page; $reports = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}arshid6social_reports WHERE status = %s ORDER BY date_reported DESC LIMIT %d OFFSET %d", $status, $per_page, $offset ) ); $counts = array(); foreach ( $allowed_statuses as $s ) { $counts[ $s ] = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}arshid6social_reports WHERE status = %s", $s ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery } $total = $counts[ $status ]; $total_pages = (int) ceil( $total / $per_page ); $suspend_reasons = $this->get_suspend_reasons(); ?>


render_groups_tab(); ?>
1 ) : ?> add_query_arg( 'paged', '%#%' ), 'format' => '', 'current' => $paged, 'total' => $total_pages, 'prev_text' => '«', 'next_text' => '»', ) ) ); ?>

reporter_id ); $report_date = wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $report->date_reported ) ); $item_link = $this->get_item_link( (int) $report->item_id, $report->item_type ); $reported_user_id = ( 'profile' === $report->item_type ) ? (int) $report->item_id : 0; $reported_user = $reported_user_id ? get_userdata( $reported_user_id ) : null; $is_suspended = $reported_user_id ? (bool) get_user_meta( $reported_user_id, 'arshid6social_suspended', true ) : false; ?>
id ); ?> display_name ); ?> item_id ) ); ?> item_type ) ); ?> reason ); ?> notes ) : ?>

notes, 20 ) ); ?>

attachment_url ) ) : ?> <?php esc_attr_e( 'Report attachment', '6arshid-social-community' ); ?> notes ) : ?>
1 ) : ?>
add_query_arg( 'paged', '%#%' ), 'format' => '', 'current' => $paged, 'total' => $total_pages, 'prev_text' => '«', 'next_text' => '»', ) ) ); ?>
home_url( '/members/' . $user->user_nicename . '/' ), 'label' => $user->display_name, ); case 'group': global $wpdb; $slug = $wpdb->get_var( $wpdb->prepare( "SELECT slug FROM {$wpdb->prefix}arshid6social_groups WHERE id = %d", $item_id ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery $name = $wpdb->get_var( $wpdb->prepare( "SELECT name FROM {$wpdb->prefix}arshid6social_groups WHERE id = %d", $item_id ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery if ( ! $slug ) { return null; } return array( 'url' => home_url( '/groups/' . $slug . '/' ), /* translators: %d: group ID */ 'label' => $name ?: sprintf( __( 'Group #%d', '6arshid-social-community' ), $item_id ), ); case 'activity': return array( 'url' => home_url( '/activity/' ), /* translators: %d: activity ID */ 'label' => sprintf( __( 'Activity #%d', '6arshid-social-community' ), $item_id ), ); default: return null; } } /** * Returns the list of suspension reasons from settings. * * @return string[] */ private function get_suspend_reasons(): array { $default = "Spam activity\nHarassment\nHate speech or discrimination\nInappropriate content\nMultiple violations\nViolation of community guidelines\nOther"; $raw = get_option( 'arshid6social_suspend_reasons', $default ); return array_values( array_filter( array_map( 'trim', explode( "\n", $raw ) ) ) ); } // ── AJAX handlers ───────────────────────────────────────────────────────── public function ajax_resolve_report(): void { $report_id = absint( $_POST['report_id'] ?? 0 ); // phpcs:ignore WordPress.Security.NonceVerification $action_type = sanitize_key( $_POST['action_type'] ?? '' ); // phpcs:ignore WordPress.Security.NonceVerification if ( ! check_ajax_referer( 'arshid6social_resolve_report_' . $report_id, 'nonce', false ) ) { wp_send_json_error( array( 'message' => __( 'Security check failed.', '6arshid-social-community' ) ), 403 ); } if ( ! current_user_can( 'arshid6social_manage_reports' ) ) { wp_send_json_error( array( 'message' => __( 'Permission denied.', '6arshid-social-community' ) ), 403 ); } $allowed = array( 'resolved', 'dismissed' ); if ( ! in_array( $action_type, $allowed, true ) ) { wp_send_json_error( array( 'message' => __( 'Invalid action.', '6arshid-social-community' ) ), 400 ); } global $wpdb; $updated = $wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->prefix . 'arshid6social_reports', array( 'status' => $action_type, 'date_resolved' => current_time( 'mysql' ), 'resolved_by' => get_current_user_id(), ), array( 'id' => $report_id ), array( '%s', '%s', '%d' ), array( '%d' ) ); if ( false === $updated ) { wp_send_json_error( array( 'message' => __( 'Database error.', '6arshid-social-community' ) ), 500 ); } \Arshid6Social\Components\Moderation\Moderation::log_action( get_current_user_id(), 'report_' . $action_type, 'report', $report_id ); wp_send_json_success( array( 'message' => __( 'Report updated.', '6arshid-social-community' ) ) ); } public function ajax_suspend_from_report(): void { $report_id = absint( $_POST['report_id'] ?? 0 ); // phpcs:ignore WordPress.Security.NonceVerification $user_id = absint( $_POST['user_id'] ?? 0 ); // phpcs:ignore WordPress.Security.NonceVerification if ( ! check_ajax_referer( 'arshid6social_suspend_report_' . $report_id, 'nonce', false ) ) { wp_send_json_error( array( 'message' => __( 'Security check failed.', '6arshid-social-community' ) ), 403 ); } if ( ! current_user_can( 'arshid6social_manage_reports' ) ) { wp_send_json_error( array( 'message' => __( 'Permission denied.', '6arshid-social-community' ) ), 403 ); } if ( ! $user_id || ! get_userdata( $user_id ) ) { wp_send_json_error( array( 'message' => __( 'Invalid user.', '6arshid-social-community' ) ), 400 ); } $reason = sanitize_text_field( wp_unslash( $_POST['reason'] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification $currently_suspended = (bool) get_user_meta( $user_id, 'arshid6social_suspended', true ); $new_state = ! $currently_suspended; update_user_meta( $user_id, 'arshid6social_suspended', $new_state ); if ( $new_state && $reason ) { update_user_meta( $user_id, 'arshid6social_suspended_reason', $reason ); } elseif ( ! $new_state ) { delete_user_meta( $user_id, 'arshid6social_suspended_reason' ); } do_action( 'arshid6social_user_suspension_changed', $user_id, $new_state ); \Arshid6Social\Components\Moderation\Moderation::log_action( get_current_user_id(), $new_state ? 'user_suspended' : 'user_unsuspended', 'user', $user_id, array( 'reason' => $reason, 'report_id' => $report_id, ) ); wp_send_json_success( array( 'suspended' => $new_state, 'label' => $new_state ? __( 'Unsuspend', '6arshid-social-community' ) : __( 'Suspend User', '6arshid-social-community' ), ) ); } }