Plugin Directory

Changeset 2061216


Ignore:
Timestamp:
04/01/2019 10:15:37 PM (7 years ago)
Author:
flynsarmy
Message:

Remove some redundant database calls

Location:
multisite-admin-bar-switcher/trunk
Files:
3 edited

Legend:

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

    r1230917 r2061216  
    77class MABS_Admin_Bar extends WP_Admin_Bar
    88{
     9    protected $active_blog_for_user_cache = [];
     10
    911    /**
    1012     * This is the same as WP_Admin_Bar's initialize method but
     
    7678     *
    7779     * @param int $user_id The unique ID of the user
    78      * @return object|void The blog object
     80     * @return object|array The blog object
    7981     */
    8082    function mabs_get_active_blog_for_user( $user_id ) {
    81         $cache = get_site_transient('mabs_activeblog_'.$user_id);
    82         if ($cache)
    83             return $cache;
     83        if ($this->active_blog_for_user_cache)
     84            return $this->active_blog_for_user_cache;
    8485
    8586        global $wpdb;
    8687        $blogs = mabs_get_blogs_of_user( $user_id );
    8788        if ( empty( $blogs ) )
    88             return;
     89            return [];
    8990
    9091        if ( !is_multisite() )
    9192        {
    92             $cache = $blogs[$wpdb->blogid];
    93             set_site_transient('mabs_activeblog_'.$user_id, $cache, apply_filters('mabs_cache_duration', 60*60*30));
    94             return $cache;
     93            $this->active_blog_for_user_cache = $blogs[$wpdb->blogid];
     94            set_site_transient('mabs_activeblog_'.$user_id, $this->active_blog_for_user_cache, apply_filters('mabs_cache_duration', 60*60*30));
     95            return $this->active_blog_for_user_cache;
    9596        }
    9697
     
    129130                }
    130131            } else {
    131                 return;
     132                return [];
    132133            }
    133             $cache = $ret;
    134             set_site_transient('mabs_activeblog_'.$user_id, $cache, apply_filters('mabs_cache_duration', 60*60*30));
    135             return $cache;
     134            $this->active_blog_for_user_cache = $ret;
     135
    136136        } else {
    137             $cache = $primary;
    138             set_site_transient('mabs_activeblog_'.$user_id, $cache, apply_filters('mabs_cache_duration', 60*60*30));
    139             return $cache;
     137            $this->active_blog_for_user_cache = $primary;
    140138        }
     139
     140        set_site_transient('mabs_activeblog_'.$user_id, $this->active_blog_for_user_cache, apply_filters('mabs_cache_duration', 60*60*30));
     141        return $this->active_blog_for_user_cache;
    141142    }
    142143}
  • multisite-admin-bar-switcher/trunk/multisite-admin-bar-switcher.php

    r2058613 r2061216  
    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.3.0
     6    Version: 1.3.1
    77    Author: Flyn San
    88    Author URI: http://www.flynsarmy.com/
  • multisite-admin-bar-switcher/trunk/readme.txt

    r2058613 r2061216  
    44Requires at least: 3.2.1
    55Tested up to: 5.1.1
    6 Stable tag: 1.3.0
     6Stable tag: 1.3.1
    77
    88== Description ==
     
    7878
    7979== Changelog ==
     80
     81= 1.3.1 =
     82* Remove some redundant database calls
    8083
    8184= 1.3.0 =
Note: See TracChangeset for help on using the changeset viewer.