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