Plugin Directory

Changeset 3424794


Ignore:
Timestamp:
12/21/2025 04:27:36 PM (3 months ago)
Author:
axelseaa
Message:

fixes

Location:
multisite-administration-tools/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • multisite-administration-tools/trunk/multisite-administration-tools.php

    r3424416 r3424794  
    44 * Plugin URI:  https://wordpress.org/plugins/multisite-administration-tools/
    55 * Description: Adds information to the network admin sites, plugins and themes pages. Allows you to easily see what theme and plugins are enabled on a site.
    6  * Version:     1.20
     6 * Version:     1.21
    77 * Author:      Aaron Axelsen
    88 * Author URI:  http://aaron.axelsen.us
     
    4848        static $site_ids = null;
    4949
     50        $batch_size = 200;
     51
    5052        if ($site_ids !== null) {
    5153                return $site_ids;
    5254        }
    5355
    54         $site_ids = get_sites([
     56        $site_ids = [];
     57
     58        $args = [
    5559                'fields' => 'ids',
    56                 'number' => 0, // all
    57         ]);
    58 
    59         if (!is_array($site_ids)) {
    60                 $site_ids = [];
     60                'number' => $batch_size,
     61                'offset' => 0,
     62        ];
     63
     64        while (true) {
     65                $batch = get_sites($args);
     66
     67                if (!is_array($batch) || empty($batch)) {
     68                        break;
     69                }
     70
     71                $site_ids = array_merge($site_ids, $batch);
     72
     73                if (count($batch) < $batch_size) {
     74                        break;
     75                }
     76
     77                $args['offset'] += $batch_size;
    6178        }
    6279
    6380        return $site_ids;
     81}
     82
     83/**
     84 * Switch to a blog and ensure we always restore the previous context.
     85 */
     86function msadmintools_with_blog(int $blog_id, callable $callback)
     87{
     88        $switched = switch_to_blog($blog_id);
     89
     90        try {
     91                return $callback();
     92        } finally {
     93                if ($switched) {
     94                        restore_current_blog();
     95                }
     96        }
    6497}
    6598
     
    141174        }
    142175
    143         $columns['msadmintools_viewthemes']  = esc_html__('Current Theme', 'msadmintools');
    144         $columns['msadmintools_viewplugins'] = esc_html__('Current Plugins', 'msadmintools');
     176        $columns['msadmintools_viewthemes']  = esc_html__('Current Theme', 'multisite-administration-tools');
     177        $columns['msadmintools_viewplugins'] = esc_html__('Current Plugins', 'multisite-administration-tools');
    145178
    146179        return $columns;
     
    159192
    160193        if ($column_name === 'msadmintools_viewthemes') {
    161                 switch_to_blog($blog_id);
    162 
    163                 $theme      = wp_get_theme();
    164                 $name       = $theme ? $theme->get('Name') : '';
    165                 $stylesheet = $theme ? $theme->get_stylesheet() : '';
    166                 $template   = $theme ? $theme->get_template() : '';
    167 
    168                 restore_current_blog();
     194                $theme_details = msadmintools_with_blog($blog_id, static function () {
     195                        $theme = wp_get_theme();
     196
     197                        return [
     198                                'name' => $theme ? $theme->get('Name') : '',
     199                                'stylesheet' => $theme ? $theme->get_stylesheet() : '',
     200                                'template' => $theme ? $theme->get_template() : '',
     201                        ];
     202                });
     203
     204                if (!is_array($theme_details)) {
     205                        return;
     206                }
     207
     208                $name       = (string) ($theme_details['name'] ?? '');
     209                $stylesheet = (string) ($theme_details['stylesheet'] ?? '');
     210                $template   = (string) ($theme_details['template'] ?? '');
    169211
    170212                if ($name !== '') {
    171                         echo '<div><strong>' . esc_html__('Name:', 'msadmintools') . '</strong> ' . esc_html($name) . '</div>';
     213                        echo '<div><strong>' . esc_html__('Name:', 'multisite-administration-tools') . '</strong> ' . esc_html($name) . '</div>';
    172214                }
    173215                if ($template !== '') {
    174                         echo '<div><strong>' . esc_html__('Template:', 'msadmintools') . '</strong> ' . esc_html($template) . '</div>';
     216                        echo '<div><strong>' . esc_html__('Template:', 'multisite-administration-tools') . '</strong> ' . esc_html($template) . '</div>';
    175217                }
    176218                if ($stylesheet !== '') {
    177                         echo '<div><strong>' . esc_html__('Stylesheet:', 'msadmintools') . '</strong> ' . esc_html($stylesheet) . '</div>';
     219                        echo '<div><strong>' . esc_html__('Stylesheet:', 'multisite-administration-tools') . '</strong> ' . esc_html($stylesheet) . '</div>';
    178220                }
    179221
     
    188230
    189231                if (empty($active_plugins)) {
    190                         echo '<em>' . esc_html__('None', 'msadmintools') . '</em>';
     232                        echo '<em>' . esc_html__('None', 'multisite-administration-tools') . '</em>';
    191233                        return;
    192234                }
     
    194236                // Use <details> so big lists don’t destroy the Sites table row height.
    195237                echo '<details>';
    196                 echo '<summary>' . esc_html(sprintf(_n('%d plugin', '%d plugins', count($active_plugins), 'msadmintools'), count($active_plugins))) . '</summary>';
     238                echo '<summary>' . esc_html(sprintf(_n('%d plugin', '%d plugins', count($active_plugins), 'multisite-administration-tools'), count($active_plugins))) . '</summary>';
    197239                echo '<div style="margin-top:6px;">';
    198240
     
    228270        }
    229271
    230         $columns['msadmintools_viewsites'] = esc_html__('Sites', 'msadmintools');
     272        $columns['msadmintools_viewsites'] = esc_html__('Sites', 'multisite-administration-tools');
    231273        return $columns;
    232274}
     
    250292        $sites = $theme_to_sites[$stylesheet] ?? [];
    251293        if (empty($sites)) {
    252                 echo '<em>' . esc_html__('None', 'msadmintools') . '</em>';
     294                echo '<em>' . esc_html__('None', 'multisite-administration-tools') . '</em>';
    253295                return;
    254296        }
     
    270312        }
    271313
    272         $columns['msadmintools_viewsites'] = esc_html__('Sites', 'msadmintools');
     314        $columns['msadmintools_viewsites'] = esc_html__('Sites', 'multisite-administration-tools');
    273315        return $columns;
    274316}
     
    292334        $sites = $plugin_to_sites[$plugin_file] ?? [];
    293335        if (empty($sites)) {
    294                 echo '<em>' . esc_html__('None', 'msadmintools') . '</em>';
     336                echo '<em>' . esc_html__('None', 'multisite-administration-tools') . '</em>';
    295337                return;
    296338        }
  • multisite-administration-tools/trunk/readme.txt

    r3424420 r3424794  
    55Tested up to: 6.9
    66Requires PHP: 7.2
    7 Stable tag: 1.20
     7Stable tag: 1.21
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    2727== Changelog ==
    2828
     29= 1.21 =
     30* Harden blog context switching and align translation text domain usage.
     31* Batch site indexing queries to improve performance on large networks.
     32
    2933= 1.20 =
    3034* Compatibility updates for current WordPress multisite Network Admin screens.
     
    4145== Upgrade Notice ==
    4246
     47= 1.21 =
     48Improves multisite safety and performance for Network Admin reporting.
     49
    4350= 1.20 =
    4451Compatibility and performance improvements for multisite Network Admin reporting.
Note: See TracChangeset for help on using the changeset viewer.