hooks(); } return self::$instance; } private function __construct() {} /** @var Admin_Pages|null */ private ?Admin_Pages $admin_pages = null; private function hooks(): void { add_action( 'admin_menu', array( $this, 'register_menus' ) ); add_action( 'admin_init', array( $this, 'register_settings' ) ); add_action( 'admin_init', array( $this, 'maybe_create_pages' ) ); add_action( 'admin_notices', array( $this, 'maybe_show_setup_notice' ) ); add_filter( 'plugin_action_links_' . ARSHID6SOCIAL_PLUGIN_BASENAME, array( $this, 'plugin_action_links' ) ); add_filter( 'set_screen_option_arshid6social_payouts_per_page', array( $this, 'save_monetization_per_page' ), 10, 3 ); add_filter( 'set_screen_option_arshid6social_tx_per_page', array( $this, 'save_monetization_per_page' ), 10, 3 ); add_filter( 'set-screen-option', array( $this, 'save_monetization_per_page_legacy' ), 10, 3 ); // Instantiate sub-admin classes. Admin_Settings::instance(); Admin_Members::instance(); Admin_Moderation::instance(); Admin_Notifications::instance(); Admin_Marketplace::instance(); Admin_Activity::instance(); Admin_Verification::instance(); Admin_Page_Icons::instance(); Admin_Ads::instance(); Sample_Data::instance(); $this->admin_pages = new Admin_Pages(); } /** * Registers the admin menu tree. */ public function register_menus(): void { add_menu_page( __( '6Arshid Social Community', '6arshid-social-community' ), __( '6Arshid Social', '6arshid-social-community' ), 'arshid6social_manage_settings', 'arshid6social-dashboard', array( $this, 'render_dashboard' ), 'dashicons-groups', 30 ); add_submenu_page( 'arshid6social-dashboard', __( 'Dashboard', '6arshid-social-community' ), __( 'Dashboard', '6arshid-social-community' ), 'arshid6social_manage_settings', 'arshid6social-dashboard', array( $this, 'render_dashboard' ) ); $activity_hook = add_submenu_page( 'arshid6social-dashboard', __( 'Activity Items', '6arshid-social-community' ), __( 'Activity Items', '6arshid-social-community' ), 'arshid6social_manage_settings', 'arshid6social-activity', array( Admin_Activity::instance(), 'render' ) ); if ( $activity_hook ) { add_action( 'load-' . $activity_hook, array( Admin_Activity::instance(), 'setup_screen_options' ) ); } $members_hook = add_submenu_page( 'arshid6social-dashboard', __( 'Members', '6arshid-social-community' ), __( 'Members', '6arshid-social-community' ), 'arshid6social_manage_members', 'arshid6social-members', array( Admin_Members::instance(), 'render' ) ); if ( $members_hook ) { add_action( 'load-' . $members_hook, array( Admin_Members::instance(), 'setup_screen_options' ) ); } $moderation_hook = add_submenu_page( 'arshid6social-dashboard', __( 'Reports & Moderation', '6arshid-social-community' ), __( 'Moderation', '6arshid-social-community' ), 'arshid6social_manage_reports', 'arshid6social-moderation', array( Admin_Moderation::instance(), 'render' ) ); if ( $moderation_hook ) { add_action( 'load-' . $moderation_hook, array( Admin_Moderation::instance(), 'setup_screen_options' ) ); } if ( get_option( 'arshid6social_verification_enabled', false ) ) { $verification_hook = add_submenu_page( 'arshid6social-dashboard', __( 'Verification Queue', '6arshid-social-community' ), __( 'Verification', '6arshid-social-community' ), 'arshid6social_manage_members', 'arshid6social-verification', array( Admin_Verification::instance(), 'render' ) ); if ( $verification_hook ) { add_action( 'load-' . $verification_hook, array( Admin_Verification::instance(), 'setup_screen_options' ) ); } } add_submenu_page( 'arshid6social-dashboard', __( 'Pages & Shortcodes', '6arshid-social-community' ), __( 'Pages & Shortcodes', '6arshid-social-community' ), 'arshid6social_manage_settings', 'arshid6social-pages', array( $this->admin_pages, 'render' ) ); add_submenu_page( 'arshid6social-dashboard', __( 'Notifications', '6arshid-social-community' ), __( 'Notifications', '6arshid-social-community' ), 'arshid6social_manage_settings', 'arshid6social-notifications', array( Admin_Notifications::instance(), 'render' ) ); $mkt_hook = add_submenu_page( 'arshid6social-dashboard', __( 'Products Archive', '6arshid-social-community' ), __( 'Products Archive', '6arshid-social-community' ), 'arshid6social_manage_settings', 'arshid6social-marketplace', array( Admin_Marketplace::instance(), 'render' ) ); if ( $mkt_hook ) { add_action( 'load-' . $mkt_hook, array( Admin_Marketplace::instance(), 'setup_screen_options' ) ); } add_submenu_page( 'arshid6social-dashboard', __( 'Ads Manager', '6arshid-social-community' ), __( 'Ads Manager', '6arshid-social-community' ), 'arshid6social_manage_settings', 'arshid6social-ads', array( Admin_Ads::instance(), 'render' ) ); $monetization_hook = add_submenu_page( 'arshid6social-dashboard', __( 'Monetization', '6arshid-social-community' ), __( 'Monetization', '6arshid-social-community' ), 'arshid6social_manage_settings', 'arshid6social-monetization', array( $this, 'render_monetization' ) ); if ( $monetization_hook ) { add_action( 'load-' . $monetization_hook, array( $this, 'setup_monetization_screen_options' ) ); } add_submenu_page( 'arshid6social-dashboard', __( 'Settings', '6arshid-social-community' ), __( 'Settings', '6arshid-social-community' ), 'arshid6social_manage_settings', 'arshid6social-settings', array( Admin_Settings::instance(), 'render' ) ); } /** * Registers all plugin settings with the Settings API. */ public function register_settings(): void { Admin_Settings::instance()->register(); } /** * Renders the dashboard overview page. */ public function render_dashboard(): void { if ( ! current_user_can( 'arshid6social_manage_settings' ) ) { wp_die( esc_html__( 'You do not have permission to access this page.', '6arshid-social-community' ) ); } $stats = $this->get_dashboard_stats(); echo '
'; echo '

' . esc_html__( '6Arshid Social Community Dashboard', '6arshid-social-community' ) . '

'; $card_defs = array( array( 'label' => __( 'Activity Items', '6arshid-social-community' ), 'count' => $stats['activity'], 'icon' => 'dashicons-format-status', 'url' => admin_url( 'admin.php?page=arshid6social-activity' ), ), array( 'label' => __( 'Groups', '6arshid-social-community' ), 'count' => $stats['groups'], 'icon' => 'dashicons-groups', 'url' => admin_url( 'admin.php?page=arshid6social-moderation' ), ), array( 'label' => __( 'Members', '6arshid-social-community' ), 'count' => $stats['members'], 'icon' => 'dashicons-admin-users', 'url' => admin_url( 'admin.php?page=arshid6social-members' ), ), array( 'label' => __( 'Pending Reports', '6arshid-social-community' ), 'count' => $stats['reports'], 'icon' => 'dashicons-flag', 'url' => admin_url( 'admin.php?page=arshid6social-moderation' ), ), array( 'label' => __( 'Products Archive', '6arshid-social-community' ), 'count' => $stats['products'], 'icon' => 'dashicons-store', 'url' => admin_url( 'admin.php?page=arshid6social-marketplace' ), ), ); if ( get_option( 'arshid6social_verification_enabled', false ) ) { $card_defs[] = array( 'label' => __( 'Pending Verifications', '6arshid-social-community' ), 'count' => $stats['verifications'], 'icon' => 'dashicons-yes-alt', 'url' => admin_url( 'admin.php?page=arshid6social-verification' ), ); } usort( $card_defs, fn( $a, $b ) => strcmp( $a['label'], $b['label'] ) ); $cards = ''; foreach ( $card_defs as $card ) { $inner = sprintf( '%2$s

%3$s

', esc_attr( $card['icon'] ), esc_html( number_format_i18n( $card['count'] ) ), esc_html( $card['label'] ) ); if ( $card['url'] ) { $cards .= '
' . $inner . '
'; } else { $cards .= '
' . $inner . '
'; } } echo '
' . $cards . '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo '
'; } /** * Fetches quick stats for the dashboard overview. * * @return array */ private function get_dashboard_stats(): array { global $wpdb; $stats = array( 'members' => (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->users}" ), // phpcs:ignore WordPress.DB 'activity' => (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}arshid6social_activity WHERE is_spam = 0" ), // phpcs:ignore WordPress.DB 'groups' => (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}arshid6social_groups" ), // phpcs:ignore WordPress.DB 'reports' => (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}arshid6social_reports WHERE status = %s", 'pending' ) ), // phpcs:ignore WordPress.DB 'products' => (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}arshid6social_listings" ), // phpcs:ignore WordPress.DB ); if ( get_option( 'arshid6social_verification_enabled', false ) ) { $stats['verifications'] = (int) $wpdb->get_var( $wpdb->prepare( // phpcs:ignore WordPress.DB "SELECT COUNT(*) FROM {$wpdb->prefix}arshid6social_verification_requests WHERE status = %s", 'pending' ) ); } return $stats; } /** * Shows notices: setup wizard prompt and missing pages warning. */ public function maybe_show_setup_notice(): void { if ( ! current_user_can( 'arshid6social_manage_settings' ) ) { return; } if ( get_transient( 'arshid6social_setup_redirect' ) ) { delete_transient( 'arshid6social_setup_redirect' ); printf( '

%s %s

', esc_html__( 'Welcome to 6Arshid Social Community!', '6arshid-social-community' ), esc_url( admin_url( 'index.php?page=arshid6social-setup' ) ), esc_html__( 'Run the setup wizard →', '6arshid-social-community' ) ); } // Warn if required pages are missing. $page_options = array( 'arshid6social_page_members', 'arshid6social_page_activity', 'arshid6social_page_groups', 'arshid6social_page_messages' ); $missing = array(); foreach ( $page_options as $opt ) { $page_id = (int) get_option( $opt, 0 ); if ( ! $page_id || 'publish' !== get_post_status( $page_id ) ) { $missing[] = $opt; } } if ( $missing ) { printf( '

%s %s

', esc_html__( '6Arshid Social Community: Some required pages are missing.', '6arshid-social-community' ), esc_url( admin_url( 'admin.php?page=arshid6social-pages&arshid6social_create_pages=1&_wpnonce=' . wp_create_nonce( 'arshid6social_create_pages' ) ) ), esc_html__( 'Click here to create them automatically →', '6arshid-social-community' ) ); } } /** * Adds quick links under the plugin name on the Plugins page. * * @param string[] $links Default plugin action links. * @return string[] */ public function plugin_action_links( array $links ): array { $links['settings'] = sprintf( '%s', esc_url( admin_url( 'admin.php?page=arshid6social-settings' ) ), esc_html__( 'Settings', '6arshid-social-community' ) ); $links['pages'] = sprintf( '%s', esc_url( admin_url( 'admin.php?page=arshid6social-pages' ) ), esc_html__( 'Pages', '6arshid-social-community' ) ); return $links; } /** * Handles the one-click "create pages" action from the admin notice link. */ public function maybe_create_pages(): void { if ( ! isset( $_GET['arshid6social_create_pages'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification return; } if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'arshid6social_create_pages' ) ) { // phpcs:ignore WordPress.Security.NonceVerification return; } if ( ! current_user_can( 'arshid6social_manage_settings' ) ) { return; } \Arshid6Social\Activator::create_pages(); flush_rewrite_rules(); wp_safe_redirect( admin_url( 'admin.php?page=arshid6social-pages&pages_created=1' ) ); exit; } /** Registers per-page Screen Option for the active Monetization tab. */ public function setup_monetization_screen_options(): void { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'settings'; if ( 'payouts' === $tab ) { add_screen_option( 'per_page', array( 'label' => __( 'IBANs per page', '6arshid-social-community' ), 'default' => 20, 'option' => 'arshid6social_payouts_per_page', ) ); } elseif ( 'transactions' === $tab ) { add_screen_option( 'per_page', array( 'label' => __( 'Transactions per page', '6arshid-social-community' ), 'default' => 25, 'option' => 'arshid6social_tx_per_page', ) ); } } /** Saves monetization per-page screen options (WP 5.4.2+). */ public function save_monetization_per_page( $status, string $option, $value ): int { return (int) $value; } /** Saves monetization per-page screen options (WP < 5.4.2). */ public function save_monetization_per_page_legacy( $status, string $option, $value ) { if ( in_array( $option, array( 'arshid6social_payouts_per_page', 'arshid6social_tx_per_page' ), true ) ) { return (int) $value; } return $status; } /** * Renders the standalone Monetization settings page with tab navigation. */ public function render_monetization(): void { if ( ! current_user_can( 'arshid6social_manage_settings' ) ) { wp_die( esc_html__( 'You do not have permission to access this page.', '6arshid-social-community' ) ); } wp_enqueue_media(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $current_tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'settings'; $tabs = array( 'settings' => __( 'Settings', '6arshid-social-community' ), 'payouts' => __( 'Creator Payouts — IBAN List', '6arshid-social-community' ), 'transactions' => __( 'Financial Transactions', '6arshid-social-community' ), ); echo '
'; echo '

' . esc_html__( 'Monetization', '6arshid-social-community' ) . '

'; echo ''; echo '
'; if ( 'payouts' === $current_tab ) { do_action( 'arshid6social_monetization_payouts_tab' ); } elseif ( 'transactions' === $current_tab ) { $this->render_monetization_transactions_tab(); } else { echo '
'; settings_fields( 'arshid6social_monetization' ); do_action( 'arshid6social_settings_tab_monetization' ); submit_button( __( 'Save Settings', '6arshid-social-community' ) ); echo '
'; } echo '
'; echo '
'; } /** Renders the Financial Transactions tab inside the Monetization page. */ private function render_monetization_transactions_tab(): void { global $wpdb; $table = $wpdb->prefix . 'arshid6social_monetization_transactions'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared,PluginCheck.Security.DirectDB.UnescapedDBParameter if ( $wpdb->get_var( "SHOW TABLES LIKE '{$table}'" ) !== $table ) { echo '

' . esc_html__( 'Transactions table does not exist yet. Enable Monetization and save settings first.', '6arshid-social-community' ) . '

'; return; } // phpcs:disable WordPress.Security.NonceVerification.Recommended $search = isset( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : ''; $filter_type = isset( $_GET['txtype'] ) ? sanitize_key( $_GET['txtype'] ) : ''; $filter_status = isset( $_GET['txstatus'] ) ? sanitize_key( $_GET['txstatus'] ) : ''; $paged = max( 1, isset( $_GET['paged'] ) ? (int) $_GET['paged'] : 1 ); // phpcs:enable WordPress.Security.NonceVerification.Recommended $per_page = (int) get_user_option( 'arshid6social_tx_per_page' ); if ( $per_page < 1 ) { $per_page = 25; } $offset = ( $paged - 1 ) * $per_page; // Build WHERE clauses. $where_parts = array( '1=1' ); $where_vals = array(); if ( '' !== $search ) { $like = '%' . $wpdb->esc_like( $search ) . '%'; $where_parts[] = '( t.gateway_ref LIKE %s OR pu.user_login LIKE %s OR pu.user_email LIKE %s OR pu.display_name LIKE %s OR cu.user_login LIKE %s OR cu.user_email LIKE %s OR cu.display_name LIKE %s )'; array_push( $where_vals, $like, $like, $like, $like, $like, $like, $like ); } if ( '' !== $filter_type ) { $where_parts[] = 't.type = %s'; $where_vals[] = $filter_type; } if ( '' !== $filter_status ) { $where_parts[] = 't.status = %s'; $where_vals[] = $filter_status; } $where_sql = implode( ' AND ', $where_parts ); $join_sql = "LEFT JOIN {$wpdb->users} pu ON pu.ID = t.payer_id LEFT JOIN {$wpdb->users} cu ON cu.ID = t.creator_id"; // Count total matching rows. // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared,PluginCheck.Security.DirectDB.UnescapedDBParameter $count_sql = "SELECT COUNT(*) FROM {$table} t {$join_sql} WHERE {$where_sql}"; $total = (int) ( empty( $where_vals ) ? $wpdb->get_var( $count_sql ) // phpcs:ignore PluginCheck.Security.DirectDB.UnescapedDBParameter,WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.NotPrepared : $wpdb->get_var( $wpdb->prepare( $count_sql, ...$where_vals ) ) ); // phpcs:ignore PluginCheck.Security.DirectDB.UnescapedDBParameter,WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.NotPrepared // Fetch page rows. // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared,PluginCheck.Security.DirectDB.UnescapedDBParameter $rows_sql = "SELECT t.*, pu.display_name AS payer_name, pu.user_email AS payer_email, cu.display_name AS creator_name, cu.user_email AS creator_email FROM {$table} t {$join_sql} WHERE {$where_sql} ORDER BY t.id DESC LIMIT %d OFFSET %d"; $fetch_vals = array_merge( $where_vals, array( $per_page, $offset ) ); // phpcs:ignore PluginCheck.Security.DirectDB.UnescapedDBParameter,WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.NotPrepared $rows = $wpdb->get_results( $wpdb->prepare( $rows_sql, ...$fetch_vals ) ); $total_pages = (int) ceil( $total / $per_page ); $base_url = add_query_arg( array_filter( array( 'page' => 'arshid6social-monetization', 'tab' => 'transactions', 's' => $search ?: null, 'txtype' => $filter_type ?: null, 'txstatus' => $filter_status ?: null, ) ), admin_url( 'admin.php' ) ); $type_colors = array( 'subscription' => '#2563eb', 'ppv' => '#7c3aed', 'payout' => '#d97706', 'refund' => '#dc2626', ); $status_colors = array( 'completed' => '#16a34a', 'pending' => '#d97706', 'failed' => '#dc2626', 'refunded' => '#6b7280', ); ?>

'padding:4px 12px;' ) ); ?>

type ] ?? '#374151'; $status_color = $status_colors[ $tx->status ] ?? '#374151'; ?>
#
id; ?> type ); ?> payer_name ) : ?> payer_name ); ?>
payer_email ); ?> —
creator_name ) : ?> creator_name ); ?>
creator_email ); ?> —
amount, 2 ) . ' ' . strtoupper( $tx->currency ) ); ?> platform_fee, 2 ) ); ?> status ); ?> gateway_ref ?: '—' ); ?> created_at ) ) ); ?>
1 ) : $pagination_args = array( 'base' => add_query_arg( 'paged', '%#%', $base_url ), 'format' => '', 'current' => $paged, 'total' => $total_pages, 'prev_text' => '«', 'next_text' => '»', ); ?>