feat: add Network Admin plugin action links - #513
josephfusco merged 5 commits into
Conversation
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
|
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 Unlinked AccountsThe 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: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
🛝 WordPress PlaygroundsBuilt from 89854c8
|
|
@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. |
|
Added that to your branch. Single site skips all ten now, multisite runs them green. |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
| 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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
|
@josephfusco thanks for the fix and the explanation, I didn't know |
|
@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. |
|
@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.
|
|
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 |

Fixes #485
A network-activated install is listed on the Network Admin Plugins screen, which fires
network_admin_plugin_action_links_{$plugin_file}rather thanplugin_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 anis_multisite()guard, the same way the plugin's other Network Admin hooks are. It prepends a View Online Users link tonetwork/users.php?presence_status=onlineand a Settings link tonetwork/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 howwp_presence_network_users_views()builds the same link.The same applies to the existing single-site link:
wp_presence_plugin_action_links()points atusers.php?presence_status=onlinewithout a nonce, whileincludes/user-list.phprequires one, so today it opens the unfiltered Users list. I left it alone as out of scope here; happy to follow up separately.Testing
tests/test-network-plugin-action-links.php(@group ms-required), modelled ontests/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 thatwp_verify_nonce()accepts forpresence_online_filter.php -lon both files.presence-api.php, under a minimal harness with stand-ins fornetwork_admin_url,wp_nonce_url,esc_urlandesc_html__: link order, preserved keys, both hrefs and labels, the nonce, and escaped ampersands all check out. CI covers the real suite.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.