PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.0.0
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.0.0
1.1.10 1.1.9 1.1.8 1.1.7 1.1.6 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.1 1.0.0 0.9.8 0.9.7 0.9.6 0.9.4 0.9.5 0.9.3 0.9.2 0.9.1 0.9.0 0.8.9 0.8.8 0.8.7 All 34 releases
desktop-mode / includes / my-wordpress / users-list-footprint.php

users-list-footprint.php in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 1.0.0, at includes/my-wordpress/users-list-footprint.php

86 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * OpenStation — "View activity footprint" row action in the classic
4 * Users list table.
5 *
6 * Adds a hover row action to `wp-admin/users.php` that, inside the
7 * desktop shell's chromeless iframe, opens the user's GitHub-style
8 * activity footprint in the "My WordPress" native window. The link's
9 * `href` is a real profile-edit URL so a no-JS load or a modifier /
10 * middle click degrades to a sensible page; inside the shell the
11 * chromeless bridge (`includes/render/chromeless-bridge.php`)
12 * intercepts the `data-os-footprint` attribute and
13 * postMessages the parent to open the footprint WITHOUT navigating the
14 * Users list away.
15 *
16 * Only rendered on chromeless requests — the one context where the
17 * desktop shell is present to receive the message. In a detached
18 * classic tab (`?desktop_mode_classic=1`) or with OpenStation off the
19 * action is omitted rather than shown as a link that would mislabel the
20 * profile editor as the footprint. When the native Users window opt-in
21 * is on, `users.php` is remapped to that window and never renders this
22 * classic list, so there is no conflict.
23 *
24 * @package OpenStation
25 */
26
27 defined( 'ABSPATH' ) || exit;
28
29 /**
30 * Append the "View activity footprint" action to a Users-table row.
31 *
32 * Hooked on `user_row_actions`. Returns the actions unchanged outside
33 * a chromeless request, for an invalid user object, or when the
34 * `openstation_user_footprint_row_action` filter opts the row out.
35 *
36 * @param string[] $actions Row action links keyed by slug.
37 * @param WP_User $user_object The user the row represents.
38 * @return string[] Filtered row actions.
39 */
40 function openstation_user_footprint_row_action( $actions, $user_object ) {
41 if ( ! openstation_is_chromeless_request() ) {
42 return $actions;
43 }
44
45 if ( ! ( $user_object instanceof WP_User ) || $user_object->ID <= 0 ) {
46 return $actions;
47 }
48
49 $user_id = (int) $user_object->ID;
50
51 /**
52 * Filters whether the "View activity footprint" row action is shown
53 * for a user in the classic Users list table.
54 *
55 * Return false to suppress the action — e.g. to scope it to a role,
56 * or to hide it on the current user's own row. Default true for any
57 * chromeless request that reaches this filter (where the row is
58 * already gated by the `list_users` capability the table requires).
59 *
60 * @param bool $show Whether to show the action. Default true.
61 * @param WP_User $user_object The user the row represents.
62 */
63 if ( ! apply_filters( 'openstation_user_footprint_row_action', true, $user_object ) ) {
64 return $actions;
65 }
66
67 // Graceful fallback target, followed only when JS is off or on a
68 // modifier / middle click: the profile-edit screen for this user
69 // (own profile uses profile.php). Inside the shell the chromeless
70 // bridge preventDefaults the click and opens the footprint instead.
71 $fallback_url = get_current_user_id() === $user_id
72 ? admin_url( 'profile.php' )
73 : add_query_arg( 'user_id', $user_id, admin_url( 'user-edit.php' ) );
74
75 $actions['os-footprint'] = sprintf(
76 '<a href="%1$s" data-os-footprint="%2$d" data-os-footprint-name="%3$s">%4$s</a>',
77 esc_url( $fallback_url ),
78 $user_id,
79 esc_attr( $user_object->display_name ),
80 esc_html__( 'View activity footprint', 'desktop-mode' )
81 );
82
83 return $actions;
84 }
85 add_filter( 'user_row_actions', 'openstation_user_footprint_row_action', 10, 2 );
86