Skip to content

enhancement(log): add a network-wide email log for multisite - #109

Open
faisalahammad wants to merge 3 commits into
WordPress:trunkfrom
faisalahammad:enhancement/84-network-log-view
Open

faisalahammad wants to merge 3 commits into
WordPress:trunkfrom
faisalahammad:enhancement/84-network-log-view

Conversation

@faisalahammad

@faisalahammad faisalahammad commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

What?

Closes #84

Adds a network-wide email log for multisite, under Settings > SMTP Log in the network admin.

Why?

Super admins of a multisite network had to open Tools > SMTP on every site to check for failed emails. With more than a dozen sites this is slow, so one place to see all of them is needed.

How?

  • Log_Repository gets get_network_tables(), get_network_items() and count_network(). The log table of each site ({site prefix}smtp_logs) is joined with one UNION ALL query, so sorting, paging and counts run in SQL. Sites without a log table are skipped, and only the first 100 active sites of the current network are read (a notice shows when there are more).
  • Network_Log_Page registers the screen on network_admin_menu with the manage_network_options capability. Network_Log_List_Table extends Log_List_Table and adds a Site column that links to the log of that site, plus the status links and a site filter.
  • A site ID in the URL only narrows the list of active sites of the current network, so it can not reach another network or an archived, deleted or spam site.
  • Provider names come from the provider registry of the network admin. A provider that is registered only in the code of one site shows as its slug for that site.
  • The screen is read-only, and it only shows the same metadata as the site logs (no message body).
  • Tools does not exist in the network admin, so the page is under Settings instead of network/tools.php. The plugin must be network activated for the screen to load.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5.5
Used for: Implementation and tests. I reviewed and tested the result.

Testing Instructions

Needs a multisite network with the plugin network activated.

  1. Send an email from two or more sites (Tools > SMTP > Test tab). Make one fail, for example with a wrong host.
  2. In the network admin, open Settings > SMTP Log.
  3. Check that emails of all sites are listed, newest first, with a Site column that links to the log of that site.
  4. Use the All / Sent / Failed links and the site select, and check the list and counts follow the filter.
  5. Open /wp-admin/network/settings.php?page=smtp-network-log as a site admin who is not a super admin. Access is refused.

Emails were sent with the Test tab only.

Checklist

  • I added or updated tests, and npm run test-php passes locally.
  • composer lint passes.
  • New settings can also be set with a wp-config constant and WP-CLI. No new settings are added.
  • New personal data is covered by the privacy exporter, eraser and policy text. No new data is stored, the screen reads the existing log.
  • No password, API key or token can appear in output, logs or error messages.

I also ran npm run test-php-multisite and composer phpstan, both pass.

Changelog Entry

Added - Multisite: super admins can see the email log of every site in one place, under Settings > SMTP Log in the network admin.

Open WordPress Playground Preview

- Add Settings > SMTP Log to the network admin, for super admins
- Join the log table of every site with one UNION ALL query
- Add a Site column, status links and a site filter
- Skip sites without a log table

Fixes WordPress#84
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @leedxw.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: leedxw.

Co-authored-by: faisalahammad <faisalahammad@git.wordpress.org>
Co-authored-by: masteradhoc <masteradhoc@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Explicit site IDs bypass network and active-site restrictions, allowing users authorized for one network to access another network’s email metadata.

4 open issues
What changed in this PR

Adds a read-only multisite email log under network Settings > SMTP Log, addressing #84 without requiring admins to visit each site.

Changes:

  • Combines site logs with SQL-based pagination, counts and status filtering.
  • Adds a network admin screen with site filtering and links to individual logs.
  • Adds multisite tests and documents network activation and the 100-site limit.
File Description
tests/​phpunit/​tests/​Log_Repository_Tests.php Tests cross-site queries, filtering and pagination.
tests/​phpunit/​tests/​Admin/​Network_Log_Page_Tests.php Tests menu registration, access and rendering.
readme.txt Documents the feature and limitations.
includes/​Plugin_Main.php Registers the multisite screen.
includes/​Log_Repository.php Adds network table discovery and queries.
includes/​Admin/​Network_Log_Page.php Adds the network page and site selector.
includes/​Admin/​Network_Log_List_Table.php Displays combined logs and status links.
includes/​Admin/​Log_List_Table.php Makes status parsing accessible to subclasses.
AGENTS.md Documents the network log architecture.

Review effort: Balanced

Comment thread includes/Log_Repository.php Resolved
Comment thread includes/Admin/Network_Log_Page.php Resolved
Comment thread includes/Admin/Network_Log_Page.php Resolved
Comment thread includes/Log_Repository.php Resolved
@masteradhoc

Copy link
Copy Markdown
Collaborator

Hey @faisalahammad

  • Each page load reads every log row on the network. get_network_items() wraps the UNION ALL in a derived table and then runs ORDER BY … LIMIT 20. MySQL has to build the full union of all 100 tables and sort it just to show 20 rows. With 30-day retention and some busy sites, that's easily hundreds of thousands of rows per page view.
    A) Fix: add ORDER BY created_at DESC, id DESC LIMIT (offset + per_page) inside each branch of the union, so each site's created_at index is used, then sort the small result outside.
    B)Counts: count_network() has the same problem. Adding up per-table counts (SELECT (SELECT COUNT() FROM t1 …) + (SELECT COUNT() FROM t2 …)) uses the status index instead.

  • The page runs far too many queries. On every load, get_network_tables() runs a SHOW COLUMNS per site, up to 100 queries. It runs twice: once in the list table constructor, and again in render_site_filter(). On top of that, count_network() runs 3 times for the status links plus once for paging, and each run is a union over every table. Fetching the tables once, and reusing the count for the current status, would cut most of this.

  • Check the timing against the DataViews move (Move the email log to DataViews (same features as today) #112). This adds a second WP_List_Table screen just as Epic: E-Mail Log Enhancements #48 / Move the email log to DataViews (same features as today) #112 is replacing the log table with DataViews and a REST endpoint. Either Move the email log to DataViews (same features as today) #112 also takes over the network log, or this one waits for Move the email log to DataViews (same features as today) #112

Nits:

  • The status filter method is duplicated. get_current_status() was made protected in Log_List_Table, then copied unchanged into the child class. Drop the copy. Likewise, making the parent's $repository protected would remove the extra $network_repository.
  • The 100-site cap is silent. Larger networks just lose sites from the list and the filter. Show a notice when the network has more than 100 sites, or make the cap filterable. The // shortcut: comment should also read like a normal comment.
  • The ?site= parameter skips the site checks. A site ID in the URL bypasses the cap and the archived / spam / deleted rules. It's harmless for super admins, but inconsistent with the dropdown.
  • Site names load slowly. get_blog_option() switches to each site, for every row and for up to 100 dropdown options. get_site( $id )->blogname uses the site-details cache instead.
  • The readme overstates a requirement. It says the plugin "must be network activated", but the network admin also loads plugins that are active on the main site. Either check for network activation, or soften the wording.
  • Some provider names may show as slugs. A provider registered only in one site's theme or plugin isn't in the network admin's provider registry, so that site's rows will show the raw slug. That's acceptable, but worth a line in the PR description.

@masteradhoc masteradhoc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@faisalahammad could you check the comments below and let us know when we can retest the PR?

- Narrow ?site= from the active site list of the current network
- Discover site tables once, keep the full site list in the select
- Keep the status when the site filter is used
- Count per site and limit rows per site before sorting
- Convert text columns so sites with different collations combine
- Show a notice when the network has more than 100 sites
- Reuse the parent status method and repository, soften readme

Addresses PR feedback.

Refs WordPress#109
@faisalahammad

Copy link
Copy Markdown
Contributor Author

Thanks @masteradhoc. Pushed fixes:

  • Queries: each site now returns only its newest rows (ORDER BY created_at DESC, id DESC LIMIT offset + per page) before the final sort. Counts are one COUNT(*) per site, added together. Table discovery runs once, and each status count runs once per page load.
  • Nits: removed the duplicated status method and the extra repository property. The ?site= ID only narrows the list of active sites. Site names use get_site(). The 100-site cap now shows a notice, and the comment is plain. The readme now says the plugin must be active in the network admin (network activated or active on the main site). Provider slugs for site-only providers are noted in the PR description.
  • Also fixed: sites whose log tables use different collations could return an empty list, so the text columns are converted to utf8mb4.
  • Move the email log to DataViews (same features as today) #112: I am not sure about the timing. Do you prefer to wait for Move the email log to DataViews (same features as today) #112 and have it take over the network log, or merge this first? I can adjust either way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consolidated log view for multisite admins

3 participants