-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass-super-admin-users-list-table.php
More file actions
135 lines (116 loc) · 4.4 KB
/
class-super-admin-users-list-table.php
File metadata and controls
135 lines (116 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/**
* Super Admin Performance Boost. Modify the list of users in the network admin.
*
* @package Super_Admin_Performance_Boost
*/
if ( ! class_exists( 'WP_List_Table' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}
if ( ! class_exists( 'WP_MS_Users_List_Table' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-ms-users-list-table.php';
}
/**
* For the Super Admin, If Super Admin, link to the sites.php page. Otherwise display a list to sites on the network using
* bespoke Super_Admin_Performance_Boost::get_home_url().
*
* @since 1.1.0
*
* @see WP_MS_Users_List_Table
*/
class Super_Admin_Users_List_Table extends WP_MS_Users_List_Table {
/**
* If Super Admin, link to the sites.php page.
*
* @since 1.1.0
*
* @param WP_User $user The current WP_User object.
* @param string $classes The list of CSS classes for the column.
* @param string $data The data-attributes for the column.
* @param string $primary The primary column name.
*/
protected function _column_blogs( $user, $classes, $data, $primary ) { // phpcs:ignore
echo '<td class="', esc_attr( $classes ), ' has-row-actions" ', esc_attr( $data ), '>';
if ( is_super_admin( $user->ID ) ) {
echo '<a href="' . esc_url( network_admin_url( 'sites.php' ) ) . '">' . esc_html__( 'Sites' ) . '</a>';
} else {
echo esc_html( $this->column_blogs( $user ) );
echo esc_html( $this->handle_row_actions( $user, 'blogs', $primary ) );
}
echo '</td>';
}
/**
* Handles the sites column output. (Copied from WP_MS_Users_List_Table).
* Modified to use Super_Admin_Performance_Boost::get_home_url().
*
* @since 1.1.0
*
* @param WP_User $user The current WP_User object.
*/
public function column_blogs( $user ) {
$blogs = get_blogs_of_user( $user->ID, true );
if ( ! is_array( $blogs ) ) {
return;
}
foreach ( $blogs as $site ) {
if ( ! can_edit_network( $site->site_id ) ) {
continue;
}
$path = ( '/' === $site->path ) ? '' : $site->path;
$site_classes = [ 'site - ' . $site->site_id ];
/**
* Filters the span class for a site listing on the mulisite user list table.
*
* @since WP 5.2.0
*
* @param string[] $site_classes Array of class names used within the span tag. Default "site-#" with the site's network ID .
* @param int $site_id Site ID .
* @param int $network_id Network ID .
* @param WP_User $user WP_User object .
*/
$site_classes = apply_filters( 'ms_user_list_site_class', $site_classes, $site->userblog_id, $site->site_id, $user );
if ( is_array( $site_classes ) && ! empty( $site_classes ) ) {
$site_classes = array_map( 'sanitize_html_class', array_unique( $site_classes ) );
echo '<span class="' . esc_attr( implode( ' ', $site_classes ) ) . '">';
} else {
echo '<span>';
}
echo '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $site->userblog_id ) ) . '">' . esc_html( str_replace( '.' . get_network()->domain, '', $site->domain . $path ) ) . '</a>';
echo ' <small class="row-actions">';
$actions = [];
$actions['edit'] = '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $site->userblog_id ) ) . '">' . __( 'Edit' ) . '</a>';
$class = '';
if ( 1 === (int) $site->spam ) {
$class .= 'site-spammed ';
}
if ( 1 === (int) $site->mature ) {
$class .= 'site-mature ';
}
if ( 1 === (int) $site->deleted ) {
$class .= 'site-deleted ';
}
if ( 1 === (int) $site->archived ) {
$class .= 'site-archived ';
}
$actions['view'] = '<a class="' . $class . '" href="' . esc_url( Super_Admin_Performance_Boost::get_home_url( $site->userblog_id ) ) . '">' . __( 'View' ) . '</a>';
/**
* Filters the action links displayed next the sites a user belongs to
* in the Network Admin Users list table.
*
* @since WP 3.1.0
*
* @param string[] $actions An array of action links to be displayed. Default 'Edit', 'View'.
* @param int $userblog_id The site ID.
*/
$actions = apply_filters( 'ms_user_list_site_actions', $actions, $site->userblog_id );
$action_count = count( $actions );
$i = 0;
foreach ( $actions as $action => $link ) {
++$i;
$separator = ( $i < $action_count ) ? ' | ' : '';
echo '<span class=', esc_attr( $action ) , '>', wp_kses_post( $link ) , esc_html( $separator ), '</span>';
}
echo '</small></span><br />';
}
}
}