hooks(); } return self::$instance; } private function __construct() {} private function hooks(): void { add_action( 'admin_init', array( $this, 'handle_actions' ) ); // 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_verification_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' => __( 'Requests per page', '6arshid-social-community' ), 'default' => 20, 'option' => 'arshid6social_verification_per_page', ) ); } /** @return array */ public function get_columns(): array { return array( 'user' => __( 'User', '6arshid-social-community' ), 'type' => __( 'Type', '6arshid-social-community' ), 'full_name' => __( 'Full Name', '6arshid-social-community' ), 'category' => __( 'Category', '6arshid-social-community' ), 'links' => __( 'Links', '6arshid-social-community' ), 'doc' => __( 'Doc', '6arshid-social-community' ), 'submitted' => __( 'Submitted', '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_verification_per_page' === $option ) { return (int) $value; } return $status; } // ── Action handler ──────────────────────────────────────────────────────── public function handle_actions(): void { if ( ! isset( $_GET['arshid6social_verify_action'], $_GET['request_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification return; } if ( ! current_user_can( 'arshid6social_manage_members' ) ) { return; } check_admin_referer( 'arshid6social_verify_action_' . absint( $_GET['request_id'] ) ); // phpcs:ignore WordPress.Security.NonceVerification $action = sanitize_key( $_GET['arshid6social_verify_action'] ); // phpcs:ignore WordPress.Security.NonceVerification $request_id = absint( $_GET['request_id'] ); // phpcs:ignore WordPress.Security.NonceVerification $verification = ARSHID6SOCIAL()->component( 'verification' ); if ( ! $verification ) { return; } switch ( $action ) { case 'approve': $type = sanitize_key( $_GET['type'] ?? 'general' ); // phpcs:ignore WordPress.Security.NonceVerification $verification->approve_request( $request_id, $type ); $msg = 'approved'; break; case 'reject': $reason = sanitize_text_field( wp_unslash( $_GET['reason'] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification $verification->reject_request( $request_id, $reason ); $msg = 'rejected'; break; case 'more_info': $message = sanitize_textarea_field( wp_unslash( $_GET['message'] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification $verification->request_more_info( $request_id, $message ); $msg = 'more_info'; break; case 'revoke': global $wpdb; $req = $wpdb->get_row( $wpdb->prepare( // phpcs:ignore WordPress.DB.DirectDatabaseQuery "SELECT user_id FROM {$wpdb->prefix}arshid6social_verification_requests WHERE id = %d", $request_id ) ); if ( $req ) { $verification->revoke( (int) $req->user_id ); $wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->prefix . 'arshid6social_verification_requests', array( 'status' => 'revoked', 'reviewer_id' => get_current_user_id(), 'decided_at' => current_time( 'mysql' ), ), array( 'id' => $request_id ), array( '%s', '%d', '%s' ), array( '%d' ) ); } $msg = 'revoked'; break; default: return; } $redirect_status = match ( $msg ) { 'approved' => 'approved', 'revoked' => 'revoked', default => 'pending', }; wp_safe_redirect( admin_url( 'admin.php?page=arshid6social-verification&status=' . $redirect_status . '&arshid6social_msg=' . $msg ) ); exit; } // ── Render ──────────────────────────────────────────────────────────────── public function render(): void { global $wpdb; // ── Screen Options values ───────────────────────────────────────────── $per_page = (int) get_user_option( 'arshid6social_verification_per_page' ); if ( $per_page < 1 ) { $per_page = 20; } $screen = get_current_screen(); $hidden_columns = $screen ? get_hidden_columns( $screen ) : array(); $col_class = fn( string $col ) => in_array( $col, $hidden_columns, true ) ? ' hidden' : ''; // phpcs:disable WordPress.Security.NonceVerification $status = sanitize_key( $_GET['status'] ?? 'pending' ); $paged = max( 1, absint( $_GET['paged'] ?? 1 ) ); // phpcs:enable $offset = ( $paged - 1 ) * $per_page; $rows = $wpdb->get_results( $wpdb->prepare( // phpcs:ignore WordPress.DB.DirectDatabaseQuery "SELECT r.*, u.user_login, u.display_name, u.user_email FROM {$wpdb->prefix}arshid6social_verification_requests r JOIN {$wpdb->users} u ON u.ID = r.user_id WHERE r.status = %s ORDER BY r.created_at DESC LIMIT %d OFFSET %d", $status, $per_page, $offset ) ) ?: array(); $total = (int) $wpdb->get_var( $wpdb->prepare( // phpcs:ignore WordPress.DB.DirectDatabaseQuery "SELECT COUNT(*) FROM {$wpdb->prefix}arshid6social_verification_requests WHERE status = %s", $status ) ); $total_pages = (int) ceil( $total / $per_page ); // ── Tab counts ──────────────────────────────────────────────────────── $tab_counts = array(); foreach ( array( 'pending', 'approved', 'rejected', 'revoked' ) as $s ) { $tab_counts[ $s ] = (int) $wpdb->get_var( $wpdb->prepare( // phpcs:ignore WordPress.DB.DirectDatabaseQuery "SELECT COUNT(*) FROM {$wpdb->prefix}arshid6social_verification_requests WHERE status = %s", $s ) ); } // ── Flash messages ──────────────────────────────────────────────────── if ( isset( $_GET['arshid6social_msg'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification $messages = array( 'approved' => __( 'Request approved and badge granted.', '6arshid-social-community' ), 'rejected' => __( 'Request rejected.', '6arshid-social-community' ), 'more_info' => __( 'More info requested from user.', '6arshid-social-community' ), 'revoked' => __( 'Verification badge revoked.', '6arshid-social-community' ), ); $msg_key = sanitize_key( $_GET['arshid6social_msg'] ); // phpcs:ignore WordPress.Security.NonceVerification if ( isset( $messages[ $msg_key ] ) ) { echo '

' . esc_html( $messages[ $msg_key ] ) . '

'; } } ?>


1 ) : ?> add_query_arg( 'paged', '%#%', admin_url( 'admin.php?page=arshid6social-verification&status=' . $status ) ), 'format' => '', 'current' => $paged, 'total' => $total_pages, 'prev_text' => '«', 'next_text' => '»', ) ) ); ?>

component( 'verification' ) ? ARSHID6SOCIAL()->component( 'verification' )->get_types() : array(); $type_label = $types_conf[ $row->type ]['label'] ?? $row->type; $fields = json_decode( $row->fields_json ?? '{}', true ); $doc_paths = json_decode( $row->document_paths ?? '[]', true ); ?>
display_name ); ?>
user_email ); ?>
$path ) : ?>
—
status ) : ?> status ) : ?> status ) : ?> status ) : ?>
1 ) : ?>
add_query_arg( 'paged', '%#%', admin_url( 'admin.php?page=arshid6social-verification&status=' . $status ) ), 'format' => '', 'current' => $paged, 'total' => $total_pages, 'prev_text' => '«', 'next_text' => '»', ) ) ); ?>