get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}arshid6social_notifications" ); // phpcs:ignore $unread_notifs = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}arshid6social_notifications WHERE is_new = 1" ); // phpcs:ignore $users_count = (int) $wpdb->get_var( "SELECT COUNT(DISTINCT user_id) FROM {$wpdb->prefix}arshid6social_notifications WHERE is_new = 1" ); // phpcs:ignore // Per-type counts. $type_counts = $wpdb->get_results( // phpcs:ignore "SELECT component_action, COUNT(*) as cnt FROM {$wpdb->prefix}arshid6social_notifications GROUP BY component_action ORDER BY cnt DESC", ARRAY_A ) ?: array(); // Global enabled types (stored as comma-separated or JSON option). $disabled_types = get_option( 'arshid6social_disabled_notification_types', array() ); if ( ! is_array( $disabled_types ) ) { $disabled_types = array(); } $all_types = \Arshid6Social\Components\Notifications\Notifications::TYPES; // Recent 50 notifications for the log. $recent = $wpdb->get_results( // phpcs:ignore "SELECT n.*, u.display_name as recipient_name, s.display_name as sender_name FROM {$wpdb->prefix}arshid6social_notifications n LEFT JOIN {$wpdb->users} u ON u.ID = n.user_id LEFT JOIN {$wpdb->users} s ON s.ID = n.item_id ORDER BY n.date_notified DESC LIMIT 50" ) ?: array(); $nonce = wp_create_nonce( 'arshid6social_admin_notif_nonce' ); ?>

🔴

$info ) : $count = $counts_by_type[ $action ] ?? 0; $enabled = ! in_array( $action, $disabled_types, true ); ?>

component_action ] ?? array( 'label' => $notif->component_action, 'icon' => '🔔', 'color' => '#6b7280' ); ?>
recipient_name ?: '—' ); ?> sender_name ?: '—' ); ?> is_new ) : ?> date_notified ) ) ); ?>
c.value); const body = new FormData(); body.append("action", "arshid6social_admin_save_notif_settings"); body.append("nonce", nonce); body.append("enabled_types", JSON.stringify(checked)); const res = await fetch(ajaxurl, {method:"POST", body}).then(r => r.json()); if (res.success) { const msg = document.getElementById("arshid6social-admin-types-saved"); msg.style.display = "inline"; setTimeout(() => { msg.style.display = "none"; }, 2500); } }); // Select-all. document.getElementById("arshid6social-log-select-all")?.addEventListener("change", function() { document.querySelectorAll(".arshid6social-log-cb").forEach(cb => cb.checked = this.checked); updateBulkBtn(); }); document.addEventListener("change", e => { if (e.target.classList.contains("arshid6social-log-cb")) updateBulkBtn(); }); function updateBulkBtn() { const any = [...document.querySelectorAll(".arshid6social-log-cb")].some(c => c.checked); document.getElementById("arshid6social-admin-delete-selected").disabled = !any; } async function deleteNotifRows(ids) { const body = new FormData(); body.append("action", "arshid6social_admin_delete_notifications"); body.append("nonce", nonce); ids.forEach(id => body.append("ids[]", id)); return fetch(ajaxurl, {method:"POST", body}).then(r => r.json()); } // Delete individual. document.addEventListener("click", async function(e) { const btn = e.target.closest(".arshid6social-admin-del-notif"); if (!btn) return; if (!confirm(' . wp_json_encode( __( 'Delete this notification?', '6arshid-social-community' ) ) . ')) return; const id = btn.dataset.id; const res = await deleteNotifRows([id]); if (res.success) btn.closest("tr").remove(); }); // Delete selected. document.getElementById("arshid6social-admin-delete-selected")?.addEventListener("click", async function() { const ids = [...document.querySelectorAll(".arshid6social-log-cb:checked")].map(c => c.value); if (!ids.length || !confirm(' . wp_json_encode( __( 'Delete selected notifications?', '6arshid-social-community' ) ) . ')) return; const res = await deleteNotifRows(ids); if (res.success) { ids.forEach(id => document.querySelector(`tr[data-id="${id}"]`)?.remove()); updateBulkBtn(); } }); // Delete all. document.getElementById("arshid6social-admin-delete-all")?.addEventListener("click", async function() { if (!confirm(' . wp_json_encode( __( 'Delete ALL notifications? This cannot be undone.', '6arshid-social-community' ) ) . ')) return; const body = new FormData(); body.append("action", "arshid6social_admin_delete_notifications"); body.append("nonce", nonce); body.append("delete_all", "1"); const res = await fetch(ajaxurl, {method:"POST", body}).then(r => r.json()); if (res.success) { document.querySelectorAll("#arshid6social-notif-log tbody tr").forEach(r => r.remove()); document.getElementById("arshid6social-admin-log-msg").style.display = "inline"; document.getElementById("arshid6social-admin-log-msg").textContent = ' . wp_json_encode( __( 'All notifications deleted.', '6arshid-social-community' ) ) . '; } }); })();'; wp_add_inline_script( 'arshid6social-admin', $notif_js ); ?> query( "DELETE FROM {$wpdb->prefix}arshid6social_notifications" ); // phpcs:ignore } else { $ids = array_map( 'absint', (array) ( $_POST['ids'] ?? array() ) ); // phpcs:ignore if ( $ids ) { $placeholders = implode( ',', array_fill( 0, count( $ids ), '%d' ) ); $wpdb->query( $wpdb->prepare( // phpcs:ignore "DELETE FROM {$wpdb->prefix}arshid6social_notifications WHERE id IN ($placeholders)", // phpcs:ignore $ids ) ); } } wp_send_json_success(); } public function ajax_save_settings(): void { if ( ! check_ajax_referer( 'arshid6social_admin_notif_nonce', 'nonce', false ) ) { wp_send_json_error( null, 403 ); } if ( ! current_user_can( 'arshid6social_manage_settings' ) ) { wp_send_json_error( null, 403 ); } $all_types = array_keys( \Arshid6Social\Components\Notifications\Notifications::TYPES ); $enabled_raw = sanitize_text_field( wp_unslash( $_POST['enabled_types'] ?? '[]' ) ); // phpcs:ignore $enabled = json_decode( $enabled_raw, true ) ?: array(); $enabled = array_intersect( $enabled, $all_types ); $disabled = array_values( array_diff( $all_types, $enabled ) ); update_option( 'arshid6social_disabled_notification_types', $disabled ); wp_send_json_success(); } }