Skip to content

Commit 3d5ef9a

Browse files
committed
Housekeeping.
1 parent 678fbbf commit 3d5ef9a

File tree

3 files changed

+62
-30
lines changed

3 files changed

+62
-30
lines changed

class-super-admin-performance-boost.php

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
<?php
2+
/**
3+
* Super Admin Performance Boost.
4+
*
5+
* @package Super_Admin_Performance_Boost
6+
* @author Per Soderlind
7+
* @since 1.0.0
8+
*/
29

310
declare( strict_types = 1 );
411

12+
/**
13+
* Super Admin Performance Boost.
14+
*/
515
class Super_Admin_Performance_Boost {
616

17+
/**
18+
* Constructor.
19+
*/
720
public function __construct() {
821
add_filter( 'pre_get_blogs_of_user', [ $this, 'super_admin_get_blogs_of_user' ], 9, 3 );
922
add_filter( 'wp_list_table_class_name', [ $this, 'super_admin_wp_list_table_class_name' ], 10, 2 );
@@ -32,7 +45,7 @@ public function filter_wpmu_users_columns( array $users_columns ) : array {
3245
}
3346

3447
/**
35-
* For the Super Admin, use a custom list table classes
48+
* For the Super Admin, use a custom list table class.
3649
*
3750
* @param string $class_name The list table class to use.
3851
* @param array $args An array containing _get_list_table() arguments.
@@ -49,16 +62,16 @@ public function super_admin_wp_list_table_class_name( string $class_name, array
4962
return $class_name;
5063
}
5164

52-
/**
53-
* For the superadmin, speed up the loading of the get_blogs_of_user() function.
54-
*
55-
* Stores the blogname, siteurl, home, and post_count in the wp_blogmeta table.
56-
*
57-
* @param null|object[] $sites An array of site objects of which the user is a member.
58-
* @param int $user_id User ID.
59-
* @param bool $all Whether the returned array should contain all sites, including those marked 'deleted', 'archived', or 'spam'. Default false.
60-
* @return null|object[] An array of site objects of which the user is a member.
61-
*/
65+
/**
66+
* For the superadmin, speed up the loading of the get_blogs_of_user() function.
67+
*
68+
* Stores the blogname, siteurl, home, and post_count in the wp_blogmeta table.
69+
*
70+
* @param null|object[] $sites An array of site objects of which the user is a member.
71+
* @param int $user_id User ID.
72+
* @param bool $all Whether the returned array should contain all sites, including those marked 'deleted', 'archived', or 'spam'. Default false.
73+
* @return null|object[] An array of site objects of which the user is a member.
74+
*/
6275
public function super_admin_get_blogs_of_user( ?array $sites, int $user_id, bool $all ) : ?array {
6376

6477
if ( ! \is_super_admin() ) {
@@ -126,7 +139,12 @@ public function super_admin_get_blogs_of_user( ?array $sites, int $user_id, bool
126139
}
127140

128141

129-
142+
/**
143+
* Get the admin URL for a given blog ID.
144+
*
145+
* @param int $blog_id The blog ID.
146+
* @return string The admin URL.
147+
*/
130148
public static function get_admin_url( int $blog_id ) : string {
131149
$admin_url = get_site_meta( $blog_id, 'siteurl', true );
132150
if ( false === $admin_url ) {
@@ -136,6 +154,12 @@ public static function get_admin_url( int $blog_id ) : string {
136154
return $admin_url;
137155
}
138156

157+
/**
158+
* Get the home URL for a given blog ID.
159+
*
160+
* @param int $blog_id The blog ID.
161+
* @return string The home URL.
162+
*/
139163
public static function get_home_url( int $blog_id ) : string {
140164
$home_url = get_site_meta( $blog_id, 'home', true );
141165
if ( false === $home_url ) {

class-super-admin-sites-list-table.php

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<?php
2+
/**
3+
* Super Admin Performance Boost. Modify the list of sites in the network admin.
4+
*
5+
* @package Super_Admin_Performance_Boost
6+
*/
27

38
if ( ! class_exists( 'WP_List_Table' ) ) {
49
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
@@ -7,14 +12,14 @@
712
require_once ABSPATH . 'wp-admin/includes/class-wp-ms-sites-list-table.php';
813
}
914

10-
/**
11-
* For the Super Admin, display a list of all sites on the network using
12-
* bespoke get_admin_url() and get_home_url().
13-
*
14-
* @since 1.0.0
15-
*
16-
* @see WP_MS_Sites_List_Table
17-
*/
15+
/**
16+
* For the Super Admin, display a list of all sites on the network using
17+
* bespoke get_admin_url() and get_home_url().
18+
*
19+
* @since 1.0.0
20+
*
21+
* @see WP_MS_Sites_List_Table
22+
*/
1823
class Super_Admin_Sites_List_Table extends WP_MS_Sites_List_Table {
1924

2025
/**
@@ -27,11 +32,14 @@ public function __construct() {
2732
}
2833

2934
/**
30-
* Prepares the list of items for displaying.
31-
*
32-
* @since 1.0.0
35+
* Generates and displays row action links. (Copied from WP_MS_Sites_List_Table).
36+
* Modified to use Super_Admin_Performance_Boost::get_admin_url() and Super_Admin_Performance_Boost::get_home_url().
3337
*
34-
* @global wpdb $wpdb WordPress database abstraction object.
38+
* @param array $item Site being acted upon.
39+
* @param string $column_name Current column name.
40+
* @param string $primary Primary column name.
41+
* @return string Row actions output for sites in Multisite, or an empty string
42+
* if the current column is not the primary column.
3543
*/
3644
protected function handle_row_actions( $item, $column_name, $primary ) {
3745
if ( $primary !== $column_name ) {
@@ -58,20 +66,20 @@ protected function handle_row_actions( $item, $column_name, $primary ) {
5866

5967
$actions['edit'] = '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a>';
6068
$actions['backend'] = "<a href='" . esc_url( Super_Admin_Performance_Boost::get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a>';
61-
if ( get_network()->site_id != $blog['blog_id'] ) {
62-
if ( '1' == $blog['deleted'] ) {
69+
if ( get_network()->site_id !== $blog['blog_id'] ) {
70+
if ( '1' === $blog['deleted'] ) {
6371
$actions['activate'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=activateblog&amp;id=' . $blog['blog_id'] ), 'activateblog_' . $blog['blog_id'] ) ) . '">' . __( 'Activate' ) . '</a>';
6472
} else {
6573
$actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=deactivateblog&amp;id=' . $blog['blog_id'] ), 'deactivateblog_' . $blog['blog_id'] ) ) . '">' . __( 'Deactivate' ) . '</a>';
6674
}
6775

68-
if ( '1' == $blog['archived'] ) {
76+
if ( '1' === $blog['archived'] ) {
6977
$actions['unarchive'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=unarchiveblog&amp;id=' . $blog['blog_id'] ), 'unarchiveblog_' . $blog['blog_id'] ) ) . '">' . __( 'Unarchive' ) . '</a>';
7078
} else {
7179
$actions['archive'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=archiveblog&amp;id=' . $blog['blog_id'] ), 'archiveblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Archive', 'verb; site' ) . '</a>';
7280
}
7381

74-
if ( '1' == $blog['spam'] ) {
82+
if ( '1' === $blog['spam'] ) {
7583
$actions['unspam'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=unspamblog&amp;id=' . $blog['blog_id'] ), 'unspamblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Not Spam', 'site' ) . '</a>';
7684
} else {
7785
$actions['spam'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=spamblog&amp;id=' . $blog['blog_id'] ), 'spamblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Spam', 'site' ) . '</a>';

super-admin-performance-boost.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Plugin URI: https://github.com/soderlind/super-admin-performance
1313
* GitHub Plugin URI: https://github.com/soderlind/super-admin-performance
1414
* Description: Try to aviod using switch_to_blog() and restore_current_blog() when possible.
15-
* Version: 1.0.0
15+
* Version: 1.0.1
1616
* Author: Per Soderlind
1717
* Author URI: https://soderlind.no
1818
* Network: true
@@ -34,4 +34,4 @@
3434
if ( ! class_exists( 'Super_Admin_Performance_Boost' ) ) {
3535
require_once __DIR__ . '/class-super-admin-performance-boost.php';
3636
}
37-
// new Super_Admin_Performance_Boost();
37+
new Super_Admin_Performance_Boost();

0 commit comments

Comments
 (0)