hooks(); } return self::$instance; } private function __construct() {} private function hooks(): void { add_action( 'wp_ajax_arshid6social_admin_suspend_user', array( $this, 'ajax_suspend_user' ) ); add_action( 'wp_ajax_arshid6social_admin_delete_member_data', array( $this, 'ajax_delete_member_data' ) ); // 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_members_per_page', array( $this, 'save_per_page' ), 10, 3 ); add_filter( 'set-screen-option', array( $this, 'save_per_page_legacy' ), 10, 3 ); } // ── Screen Options ──────────────────────────────────────────────────────── /** * Called on load-{hook} — registers the per-page Screen Option. */ public function setup_screen_options(): void { add_screen_option( 'per_page', array( 'label' => __( 'Members per page', '6arshid-social-community' ), 'default' => 20, 'option' => 'arshid6social_members_per_page', ) ); } /** * Returns all available columns (used by WP to build Screen Options checkboxes). * * @return array */ public function get_columns(): array { return array( 'member' => __( 'Member', '6arshid-social-community' ), 'email' => __( 'Email', '6arshid-social-community' ), 'registered' => __( 'Registered', '6arshid-social-community' ), 'status' => __( 'Status', '6arshid-social-community' ), 'actions' => __( 'Actions', '6arshid-social-community' ), ); } /** Saves the per-page value (WP 5.4.2+). */ public function save_per_page( $status, string $option, $value ): int { return (int) $value; } /** Saves the per-page value (WP < 5.4.2 compatibility). */ public function save_per_page_legacy( $status, string $option, $value ) { if ( 'arshid6social_members_per_page' === $option ) { return (int) $value; } return $status; } // ── Render ──────────────────────────────────────────────────────────────── /** * Renders the admin members page. */ public function render(): void { if ( ! current_user_can( 'arshid6social_manage_members' ) ) { wp_die( esc_html__( 'Permission denied.', '6arshid-social-community' ) ); } // ── Screen Options values ───────────────────────────────────────────── $per_page = (int) get_user_option( 'arshid6social_members_per_page' ); if ( $per_page < 1 ) { $per_page = 20; } $screen = get_current_screen(); $hidden_columns = $screen ? get_hidden_columns( $screen ) : array(); // Helper: returns ' hidden' class if column should be hidden. $col_class = fn( string $col ) => in_array( $col, $hidden_columns, true ) ? ' hidden' : ''; // ── Request params ──────────────────────────────────────────────────── $search = isset( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification $paged = isset( $_GET['paged'] ) ? max( 1, absint( $_GET['paged'] ) ) : 1; // phpcs:ignore WordPress.Security.NonceVerification $args = array( 'number' => $per_page, 'offset' => ( $paged - 1 ) * $per_page, 'search' => $search ? '*' . $search . '*' : '', ); $users = get_users( $args ); $total_users = (int) ( new \WP_User_Query( array_merge( $args, array( 'count_total' => true, 'number' => 0, 'offset' => 0, ) ) ) )->get_total(); $total_pages = (int) ceil( $total_users / $per_page ); ?>


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

ID, 'arshid6social_suspended', true ); ?>
ID, 32 ); ?> display_name ); ?>
user_registered ) ) ); ?> ID, 'arshid6social_suspended_reason', true ); if ( $susp_reason && 'auto_threshold' !== $susp_reason ) : ?>

1 ) : ?>
add_query_arg( 'paged', '%#%' ), 'format' => '', 'current' => $paged, 'total' => $total_pages, 'prev_text' => '«', 'next_text' => '»', ) ) ); ?>
__( 'Security check failed.', '6arshid-social-community' ) ), 403 ); } if ( ! current_user_can( 'arshid6social_manage_members' ) ) { 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 ); } $currently_suspended = (bool) get_user_meta( $user_id, 'arshid6social_suspended', true ); $new_state = ! $currently_suspended; $reason = sanitize_text_field( wp_unslash( $_POST['reason'] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification 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' ); } clean_user_cache( $user_id ); if ( $new_state ) { self::delete_user_standard_attachments( $user_id ); delete_transient( 'arshid6social_sweep_done' ); } 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 ) ); wp_send_json_success( array( 'suspended' => $new_state, 'reason' => $reason, 'label' => $new_state ? __( 'Unsuspend', '6arshid-social-community' ) : __( 'Suspend', '6arshid-social-community' ), ) ); } /** * Permanently deletes all WP Media Library attachments that live in the standard * uploads/YYYY/MM/ path for the given user. Files already inside social-network/ * are skipped because those are served through the PHP endpoint and checked there. * * @param int $user_id WordPress user ID. */ private static function delete_user_standard_attachments( int $user_id ): void { global $wpdb; $upload_dir = wp_upload_dir(); $upload_base = $upload_dir['basedir']; // phpcs:ignore WordPress.DB.DirectDatabaseQuery $rows = $wpdb->get_results( $wpdb->prepare( "SELECT p.ID, pm.meta_value AS rel_path FROM {$wpdb->posts} p JOIN {$wpdb->postmeta} pm ON pm.post_id = p.ID AND pm.meta_key = '_wp_attached_file' WHERE p.post_type = 'attachment' AND p.post_author = %d AND pm.meta_value NOT LIKE %s", $user_id, $wpdb->esc_like( 'social-network/' ) . '%' ) ); if ( ! $rows ) { return; } foreach ( $rows as $row ) { $att_id = (int) $row->ID; $rel_path = (string) $row->rel_path; $abs_path = $upload_base . '/' . ltrim( $rel_path, '/' ); if ( is_file( $abs_path ) ) { unlink( $abs_path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.unlink_unlink } // phpcs:ignore WordPress.DB.DirectDatabaseQuery $meta_raw = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = '_wp_attachment_metadata' LIMIT 1", $att_id ) ); if ( $meta_raw ) { $meta = maybe_unserialize( $meta_raw ); if ( is_array( $meta ) && ! empty( $meta['sizes'] ) ) { $dir = dirname( $abs_path ); foreach ( $meta['sizes'] as $size_data ) { if ( ! empty( $size_data['file'] ) ) { $thumb = $dir . '/' . basename( $size_data['file'] ); if ( is_file( $thumb ) ) { unlink( $thumb ); // phpcs:ignore WordPress.WP.AlternativeFunctions.unlink_unlink } } } } } // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->delete( $wpdb->posts, array( 'ID' => $att_id ), array( '%d' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->delete( $wpdb->postmeta, array( 'post_id' => $att_id ), array( '%d' ) ); } } /** * AJAX: Deletes all social network data for a user (GDPR erasure). */ public function ajax_delete_member_data(): void { $user_id = absint( $_POST['user_id'] ?? 0 ); // phpcs:ignore WordPress.Security.NonceVerification if ( ! check_ajax_referer( 'arshid6social_delete_data_' . $user_id, 'nonce', false ) ) { wp_send_json_error( array( 'message' => __( 'Security check failed.', '6arshid-social-community' ) ), 403 ); } if ( ! current_user_can( 'arshid6social_manage_members' ) ) { wp_send_json_error( array( 'message' => __( 'Permission denied.', '6arshid-social-community' ) ), 403 ); } do_action( 'arshid6social_before_delete_member_data', $user_id ); \Arshid6Social\Components\Moderation\Moderation::purge_user_data( $user_id ); do_action( 'arshid6social_deleted_member_data', $user_id ); wp_send_json_success( array( 'message' => __( 'Member data deleted.', '6arshid-social-community' ) ) ); } }