Plugin Directory

Changeset 2058613


Ignore:
Timestamp:
03/28/2019 12:56:57 AM (7 years ago)
Author:
flynsarmy
Message:

Cache admin URLs to avoid hitting the DB

Location:
multisite-admin-bar-switcher/trunk
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • multisite-admin-bar-switcher/trunk/multisite-admin-bar-switcher.php

    r1667437 r2058613  
    44    Plugin URI: http://www.flynsarmy.com
    55    Description: Replaces the built in 'My Sites' drop down with a better layed out one
    6     Version: 1.2.6
     6    Version: 1.3.0
    77    Author: Flyn San
    88    Author URI: http://www.flynsarmy.com/
     
    3737});
    3838
    39 add_action( 'add_admin_bar_menus', 'mabs_remove_admin_bar_menus');
    40 function mabs_remove_admin_bar_menus()
    41 {
     39add_action( 'add_admin_bar_menus', function() {
    4240    if ( is_multisite() )
    4341    {
     
    4543        remove_action( 'admin_bar_menu', 'wp_admin_bar_my_sites_menu', 20 );
    4644    }
    47 }
     45});
    4846
    4947function mabs_require_with($partial, $data)
     
    171169    delete_site_transient('mabs_bloglist_'.$user_id);
    172170    delete_site_transient('mabs_is_below_min_'.$user_id);
     171    delete_site_transient('mabs_admin_urls');
    173172    delete_site_transient('mabs_bloglist_network');
    174173}
     
    259258}
    260259
     260function mabs_get_admin_url( $userblog_id )
     261{
     262    $cache = get_site_transient('mabs_admin_urls');
     263
     264    if ( !is_array($cache) )
     265        $cache = [];
     266
     267    if (  !isset($cache[$userblog_id]) )
     268    {
     269        $cache[$userblog_id] = get_admin_url($userblog_id);
     270        set_site_transient('mabs_admin_urls', $cache, apply_filters('mabs_cache_duration', 60*60*30));
     271    }
     272
     273    return $cache[$userblog_id];
     274}
     275
    261276/**
    262277 * Add the blog list under their respective letters
     
    293308        $letter = mb_strtoupper(mb_substr($key, 0, 1));
    294309        $site_parent = "mabs_".$letter."_letter";
    295         $admin_url = !empty($blog->external_site) ? $blog->adminurl : get_admin_url( $blog->userblog_id );
     310        $admin_url = !empty($blog->external_site) ? $blog->adminurl : mabs_get_admin_url( $blog->userblog_id );
    296311
    297312        //Add the site
     
    415430}
    416431
     432/**
     433 * @return array of stdClass
     434 *      (
     435 *          [userblog_id] => 1
     436 *          [blogname] => My Blog
     437 *          [domain] => myblog.localhost.com
     438 *          [path] => /
     439 *          [site_id] => 1
     440 *          [siteurl] => http://myblog.localhost.com
     441 *          [archived] => 0
     442 *          [spam] => 0
     443 *          [deleted] => 0
     444 *      )
     445 */
    417446function mabs_get_blogs_of_network()
    418447{
  • multisite-admin-bar-switcher/trunk/readme.txt

    r1667437 r2058613  
    33Tags: multisite, toolbar, switcher, switch, network, admin, wpmu
    44Requires at least: 3.2.1
    5 Tested up to: 4.6
    6 Stable tag: 1.2.6
     5Tested up to: 5.1.1
     6Stable tag: 1.3.0
    77
    88== Description ==
     
    7878
    7979== Changelog ==
     80
     81= 1.3.0 =
     82* Cache admin URLs to avoid hitting the DB
    8083
    8184= 1.2.6 =
Note: See TracChangeset for help on using the changeset viewer.