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_activity_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' => __( 'Activity items per page', '6arshid-social-community' ), 'default' => 20, 'option' => 'arshid6social_activity_per_page', ) ); } /** @return array */ public function get_columns(): array { return array( 'author' => __( 'Author', '6arshid-social-community' ), 'type' => __( 'Type', '6arshid-social-community' ), 'component' => __( 'Component', '6arshid-social-community' ), 'content' => __( 'Content', '6arshid-social-community' ), 'flags' => __( 'Flags', '6arshid-social-community' ), 'date' => __( 'Date', '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_activity_per_page' === $option ) { return (int) $value; } return $status; } // ── Action handler ──────────────────────────────────────────────────────── public function handle_actions(): void { if ( ! isset( $_GET['page'] ) || 'arshid6social-activity' !== $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification return; } if ( ! current_user_can( 'arshid6social_manage_settings' ) ) { return; } // Single-row action. if ( ! empty( $_GET['action'] ) && ! empty( $_GET['activity_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification $action = sanitize_key( wp_unslash( $_GET['action'] ) ); // phpcs:ignore WordPress.Security.NonceVerification $activity_id = absint( $_GET['activity_id'] ); // phpcs:ignore WordPress.Security.NonceVerification if ( ! check_admin_referer( 'arshid6social_act_' . $action . '_' . $activity_id ) ) { wp_die( esc_html__( 'Security check failed.', '6arshid-social-community' ) ); } $this->process_single_action( $action, $activity_id ); wp_safe_redirect( remove_query_arg( array( 'action', 'activity_id', '_wpnonce' ) ) ); exit; } // Bulk action. if ( ! empty( $_POST['action'] ) && ! empty( $_POST['activity_ids'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification if ( ! check_admin_referer( 'arshid6social_act_bulk', '_wpnonce_bulk' ) ) { wp_die( esc_html__( 'Security check failed.', '6arshid-social-community' ) ); } $action = sanitize_key( wp_unslash( $_POST['action'] ) ); // phpcs:ignore WordPress.Security.NonceVerification $activity_ids = array_map( 'absint', (array) $_POST['activity_ids'] ); // phpcs:ignore WordPress.Security.NonceVerification foreach ( $activity_ids as $id ) { $this->process_single_action( $action, $id ); } wp_safe_redirect( remove_query_arg( array( 'action', 'activity_ids', '_wpnonce_bulk' ) ) ); exit; } } // ── Render ──────────────────────────────────────────────────────────────── public function render(): void { if ( ! current_user_can( 'arshid6social_manage_settings' ) ) { wp_die( esc_html__( 'You do not have permission to access this page.', '6arshid-social-community' ) ); } global $wpdb; // ── Screen Options values ───────────────────────────────────────────── $per_page = (int) get_user_option( 'arshid6social_activity_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' : ''; // ── Request params ──────────────────────────────────────────────────── $search = isset( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification $tab = isset( $_GET['status'] ) ? sanitize_key( wp_unslash( $_GET['status'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification $paged = isset( $_GET['paged'] ) ? max( 1, absint( $_GET['paged'] ) ) : 1; // phpcs:ignore WordPress.Security.NonceVerification // ── Build WHERE ─────────────────────────────────────────────────────── $where = 'WHERE 1=1'; $params = array(); if ( 'spam' === $tab ) { $where .= ' AND a.is_spam = 1'; } elseif ( 'hidden' === $tab ) { $where .= ' AND a.hide_sitewide = 1 AND a.is_spam = 0'; } else { $where .= ' AND a.is_spam = 0'; } if ( $search ) { $where .= ' AND (a.content LIKE %s OR u.display_name LIKE %s OR u.user_email LIKE %s)'; $like = '%' . $wpdb->esc_like( $search ) . '%'; $params[] = $like; $params[] = $like; $params[] = $like; } // ── Count per tab ───────────────────────────────────────────────────── // phpcs:ignore WordPress.DB.DirectDatabaseQuery $all_count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}arshid6social_activity WHERE is_spam = 0" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery $spam_count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}arshid6social_activity WHERE is_spam = 1" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery $hidden_count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}arshid6social_activity WHERE hide_sitewide = 1 AND is_spam = 0" ); // ── Total for pagination ────────────────────────────────────────────── // phpcs:ignore WordPress.DB.DirectDatabaseQuery,WordPress.DB.PreparedSQL.InterpolatedNotPrepared,PluginCheck.Security.DirectDB.UnescapedDBParameter,WordPress.DB.PreparedSQLPlaceholders $total = (int) $wpdb->get_var( $wpdb->prepare( // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQLPlaceholders "SELECT COUNT(*) FROM {$wpdb->prefix}arshid6social_activity a LEFT JOIN {$wpdb->users} u ON u.ID = a.user_id $where", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,PluginCheck.Security.DirectDB.UnescapedDBParameter,WordPress.DB.PreparedSQLPlaceholders -- placeholders supplied via dynamic $where + spread $params. ...$params ) ); $total_pages = (int) ceil( $total / $per_page ); $offset = ( $paged - 1 ) * $per_page; // ── Fetch rows ──────────────────────────────────────────────────────── $select = "SELECT a.id, a.user_id, a.component, a.type, a.content, a.action, a.date_recorded, a.hide_sitewide, a.is_spam, a.privacy, u.display_name AS author_name, u.user_email AS author_email FROM {$wpdb->prefix}arshid6social_activity a LEFT JOIN {$wpdb->users} u ON u.ID = a.user_id $where ORDER BY a.date_recorded DESC LIMIT %d OFFSET %d"; $row_params = array_merge( $params, array( $per_page, $offset ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery,WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQLPlaceholders,WordPress.DB.PreparedSQL.InterpolatedNotPrepared,PluginCheck.Security.DirectDB.UnescapedDBParameter,WordPress.DB.PreparedSQLPlaceholders $items = $wpdb->get_results( $wpdb->prepare( $select, ...$row_params ) ); $current_url = admin_url( 'admin.php?page=arshid6social-activity' ); ?>


render_tablenav( 'top', $total, $total_pages, $paged, $tab ); ?> $item->is_spam ? 'unspam' : 'spam', 'activity_id' => $item->id, ), $current_url ), 'arshid6social_act_' . ( $item->is_spam ? 'unspam' : 'spam' ) . '_' . $item->id ); $hide_url = wp_nonce_url( add_query_arg( array( 'action' => $item->hide_sitewide ? 'show' : 'hide', 'activity_id' => $item->id, ), $current_url ), 'arshid6social_act_' . ( $item->hide_sitewide ? 'show' : 'hide' ) . '_' . $item->id ); $delete_url = wp_nonce_url( add_query_arg( array( 'action' => 'delete', 'activity_id' => $item->id, ), $current_url ), 'arshid6social_act_delete_' . $item->id ); $content_plain = wp_strip_all_tags( $item->content ); $content_short = mb_strlen( $content_plain ) > 120 ? mb_substr( $content_plain, 0, 120 ) . '…' : $content_plain; $type_label = ucwords( str_replace( '_', ' ', $item->type ) ); $comp_label = ucwords( str_replace( '_', ' ', $item->component ) ); ?>
author_name ) : ?> user_id, 32 ); ?> author_name ); ?> action ) ); ?> is_spam ) : ?> hide_sitewide ) : ?> is_spam && ! $item->hide_sitewide ) : ?> — date_recorded ) ) ); ?>
render_tablenav( 'bottom', $total, $total_pages, $paged, $tab ); ?>
1 ) : ?> add_query_arg( 'paged', '%#%', $page_url ), 'format' => '', 'current' => $paged, 'total' => $total_pages, 'prev_text' => '«', 'next_text' => '»', ) ) ); ?>

delete( "{$wpdb->prefix}arshid6social_activity_meta", array( 'activity_id' => $activity_id ), array( '%d' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->delete( "{$wpdb->prefix}arshid6social_activity_reactions", array( 'activity_id' => $activity_id ), array( '%d' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->delete( "{$wpdb->prefix}arshid6social_activity_media", array( 'activity_id' => $activity_id ), array( '%d' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->delete( "{$wpdb->prefix}arshid6social_activity", array( 'id' => $activity_id ), array( '%d' ) ); return; } $updates = match ( $action ) { 'spam' => array( 'is_spam' => 1 ), 'unspam' => array( 'is_spam' => 0 ), 'hide' => array( 'hide_sitewide' => 1 ), 'show' => array( 'hide_sitewide' => 0 ), default => null, }; if ( $updates ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->update( "{$wpdb->prefix}arshid6social_activity", $updates, array( 'id' => $activity_id ), array( '%d' ), array( '%d' ) ); } } }