The MU forums have moved to

Please add this function - current_blog_id() ... (3 posts)

  1. MartyThornley
    Posted 14 years ago #

    Or something like that. That info is set on every page and yet is ridiculously difficlut (or hidden) as to how to go about this.

    I have seen it mentioned to use:

    global $blog_id;
    echo $blog_id;

    The problem is that calling this in the wrong place screws up that global variable. For instance, i tried using it in a function sent to 'init' and it messed things up.

    Just the fact that is a very generic term (my first choice when I was defining a blog id) makes it super easy for a theme or plugin to mess things up.

    You can use:

    global $wpdb;
    $current_blog_id = $wpdb->blogid;

    This is better, but still awkward.

    Or, it appears it is also stored in the actual $GLOBALS like so...

    $current_blog_id = $GLOBALS['blog_id'];

    Most of the time, $blog_id is just being set by $GLOBALS['blog_id'] or $wpdb->id; anyway.

    But the definition all of these id's seem to just loop around on each other in the code. At times $GLOBALS is set by $blog_id, at times the other way around. At times, $current_blog->id is set by $blog_id, some times the reverse.

    Obviously it is all working, but it should be easier to figure out the id of the blog we are currently on.

    I searched the entire code base of mu and the beta 3.0 and that wording 'current_blog_id' is not used anywhere.

    function current_blog_id() {
        global $wpdb;
        return $wpdb->blogid;

    Would save a lot of headaches. :)

  2. tdjcbe
    Posted 14 years ago #

    Wouldn't get_current_site() work? (It's early and my mind is numb. I can;t handle code this morning)

    edit: I thought it was get_current_blog?

    redit: Never mind. I just found your other thread. You can make suggestions here:

    Login information is the same as here in the forums. Development on wpmu has pretty much ended and merged into regular wp.

  3. MartyThornley
    Posted 14 years ago #

    Good idea. I posted a new ticket in trac.


About this Topic

  • Started 14 years ago by MartyThornley
  • Latest reply from MartyThornley