Skip to content

feat: add Network Admin plugin action links - #513

Merged
josephfusco merged 5 commits into
WordPress:mainfrom
bernalalexis-try:feat/485-network-plugin-action-links
Sep 23, 2026
Merged

josephfusco merged 5 commits into
WordPress:mainfrom
bernalalexis-try:feat/485-network-plugin-action-links

Conversation

@bernalalexis-try

Copy link
Copy Markdown
Contributor

Fixes #485

A network-activated install is listed on the Network Admin Plugins screen, which fires network_admin_plugin_action_links_{$plugin_file} rather than plugin_action_links_{$plugin_file}, so it showed no presence-api links at all.

wp_presence_network_plugin_action_links() mirrors the single-site function and is registered for this plugin's file inside an is_multisite() guard, the same way the plugin's other Network Admin hooks are. It prepends a View Online Users link to network/users.php?presence_status=online and a Settings link to network/settings.php, reusing the single-site labels so they share translations.

One deviation from the task list: the online users URL is built with wp_nonce_url( ..., 'presence_online_filter' ). wp_presence_filter_network_online_users() returns the query unchanged unless that nonce verifies, so the bare URL from the issue would have listed every user. This matches how wp_presence_network_users_views() builds the same link.

The same applies to the existing single-site link: wp_presence_plugin_action_links() points at users.php?presence_status=online without a nonce, while includes/user-list.php requires one, so today it opens the unfiltered Users list. I left it alone as out of scope here; happy to follow up separately.

Testing

  • New tests/test-network-plugin-action-links.php (@group ms-required), modelled on tests/test-plugin-action-links.php: one test per link asserting href and label, the filter registration, and that the filter output matches the direct call. It also asserts that the online users link carries a nonce that wp_verify_nonce() accepts for presence_online_filter.
  • php -l on both files.
  • I could not run the PHPUnit suite, PHPCS or PHPStan locally: my environment cannot reach Packagist and has no database for the WordPress test suite. I ran the new function, extracted verbatim from presence-api.php, under a minimal harness with stand-ins for network_admin_url, wp_nonce_url, esc_url and esc_html__: link order, preserved keys, both hrefs and labels, the nonce, and escaped ampersands all check out. CI covers the real suite.
  • Not yet checked by hand in wp-env.
Use of AI Tools

AI assistance: Yes
Tool(s): Claude
Model(s): Claude Opus 5
Used for: Implementation, tests and this description, reviewed by me before submitting.

A network-activated install is listed on the Network Admin Plugins screen,
which fires network_admin_plugin_action_links_{$plugin_file} rather than
the single-site filter, so it showed no presence-api links at all.

Register that filter on multisite with a View Online Users link to the
network Users list and a Settings link to Network Settings. The online
users URL carries the presence_online_filter nonce, as the network Users
view builds it, because the filter ignores a request without one.

Fixes #485
@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @bernalalexis-try.

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

Core Committers: Use this line as a base for the props when committing in SVN:

Props iamchitti, joefusco.

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

@github-actions github-actions Bot added the Needs WP.org Link Author hasn't linked a WordPress.org account yet — confirm before merging so props credit correctly label Sep 21, 2026
@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

🛝 WordPress Playgrounds

Built from 89854c8

5 users 40 users
Single site Launch single site, 5 users Launch single site, 40 users
Multisite Launch multisite, 5 users Launch multisite, 40 users

@josephfusco

Copy link
Copy Markdown
Collaborator

@bernalalexis-try nice first contribution.

To receive proper credit, please link your WordPress.org account. Leave a comment here once that's done and a maintainer will be able to merge this in.

@josephfusco

Copy link
Copy Markdown
Collaborator

@group ms-required is documentation in this suite, nothing reads it, so the class ran on single site and the two registration tests failed against the is_multisite() guard. The network suites skip with an explicit markTestSkipped() in set_up() (tests/class-wp-presence-network-unittestcase.php:41).

Added that to your branch. Single site skips all ten now, multisite runs them green.

github-actions Bot added a commit that referenced this pull request Sep 21, 2026
@codecov

codecov Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.80%. Comparing base (263c5e9) to head (26595e8).

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #513      +/-   ##
============================================
+ Coverage     95.79%   95.80%   +0.01%     
  Complexity      255      255              
============================================
  Files            21       21              
  Lines          3066     3078      +12     
============================================
+ Hits           2937     2949      +12     
  Misses          129      129              
Flag Coverage Δ
multisite 95.80% <100.00%> (+0.01%) ⬆️
phpunit 70.92% <0.00%> (-0.28%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@josephfusco josephfusco added the props-bot Manually runs the Props Bot to update the contributor list. label Sep 21, 2026
@github-actions github-actions Bot removed the props-bot Manually runs the Props Bot to update the contributor list. label Sep 21, 2026
Comment thread presence-api.php
Comment on lines +325 to +340
function wp_presence_network_plugin_action_links( $links ) {
$online_users_link = sprintf(
'<a href="%1$s">%2$s</a>',
esc_url( wp_nonce_url( network_admin_url( 'users.php?presence_status=online' ), 'presence_online_filter' ) ),
esc_html__( 'View Online Users', 'presence-api' )
);

$settings_link = sprintf(
'<a href="%1$s">%2$s</a>',
esc_url( network_admin_url( 'settings.php' ) ),
esc_html__( 'Settings', 'presence-api' )
);

array_unshift( $links, $online_users_link, $settings_link );

return $links;

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.

This link is shown without checking current_user_can( wp_presence_network_capability() ), unlike wp_presence_network_users_views(). A user without that capability could see and click "View Online Users," but the page it links to would just silently do nothing for them. Can we add the same check here for consistency?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks. Added the same current_user_can( wp_presence_network_capability() ) gate in 0de2a72: without it only the Settings link is prepended. The tests now run as a super admin, plus two new ones for the withheld link (a subscriber, and the capability filtered to do_not_allow).

Match wp_presence_network_users_views(): the View Online Users link is only added when the current user can wp_presence_network_capability(), so it no longer points users without it at a view they cannot see. The tests now run as a super admin and cover the withheld link, including through the capability filter.
@bernalalexis-try

Copy link
Copy Markdown
Contributor Author

@josephfusco thanks for the fix and the explanation, I didn't know @group ms-required was documentation only here. I pushed 0de2a72 on top for @i-am-chitti's capability check; the new tests sit in the same class, so they skip on single site as well.

github-actions Bot added a commit that referenced this pull request Sep 21, 2026
@bernalalexis-try

Copy link
Copy Markdown
Contributor Author

@josephfusco I don't have a WordPress.org account. Is linking one required for the merge, or can this go in without props? Happy to create one if that's what's needed.

@josephfusco

Copy link
Copy Markdown
Collaborator

@bernalalexis-try No requirement, but it's a one time setup I'd encourage you to do so your contributions show up within that ecosystem.

CleanShot 2026-09-22 at 08 12 44@2x

github-actions Bot added a commit that referenced this pull request Sep 22, 2026
github-actions Bot added a commit that referenced this pull request Sep 23, 2026
@josephfusco josephfusco added the props-bot Manually runs the Props Bot to update the contributor list. label Sep 23, 2026
@github-actions github-actions Bot removed the props-bot Manually runs the Props Bot to update the contributor list. label Sep 23, 2026
@josephfusco

Copy link
Copy Markdown
Collaborator

Thanks for adding this! Merging this, but if you get a WordPress.org account setup and linked, drop a comment here and a maintainer can run props-bot to retroactively get your attribution added.

@josephfusco
josephfusco merged commit 514cd7e into WordPress:main Sep 23, 2026
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs WP.org Link Author hasn't linked a WordPress.org account yet — confirm before merging so props credit correctly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Network Admin row actions for presence-api

3 participants