Skip to:
Content

BuddyPress.org

Ticket #1948: 1948.2.patch

File 1948.2.patch, 3.4 KB (added by junsuijin, 16 years ago)

add support for calls to non-existant blog ids

  • bp-core.php

     
    605605 * eg: http://domain.com/ OR https://domain.com
    606606 *
    607607 * @package BuddyPress Core
    608  * @uses get_blog_option() WordPress function to fetch blog meta.
     608 * @global $current_blog WordPress global containing information and settings for the current blog being viewed.
     609 * @uses bp_core_get_home_url() Returns the domain for the root blog with contextual SSL scheme.
    609610 * @return $domain The domain URL for the blog.
    610611 */
    611612function bp_core_get_root_domain() {
    612613        global $current_blog;
    613614
    614615        if ( defined( 'BP_ENABLE_MULTIBLOG' ) )
    615                 $domain = get_blog_option( $current_blog->blog_id, 'siteurl' );
     616                $domain = bp_core_get_home_url( $current_blog->blog_id );
    616617        else
    617                 $domain = get_blog_option( BP_ROOT_BLOG, 'siteurl' );
     618                $domain = bp_core_get_home_url( BP_ROOT_BLOG );
    618619
    619620        return apply_filters( 'bp_core_get_root_domain', $domain );
    620621}
  • bp-core/bp-core-wpabstraction.php

     
    6161        }
    6262}
    6363
     64/**
     65 * Retrieve the home url for a given site.
     66 *
     67 * Returns the 'home' option with the appropriate protocol,  'https' if
     68 * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
     69 * overridden.
     70 *
     71 * @package BuddyPress Core
     72 * @since 1.3
     73 * @global $wpdb WordPress global containing database information.
     74 * @global $current_blog WordPress global containing information and settings for the current blog being viewed.
     75 * @adapted from @package WordPress 3.0.0
     76 *
     77 * @param  int $blog_id   (optional) Blog ID. Defaults to current blog.
     78 * @param  string $path   (optional) Path relative to the home url.
     79 * @param  string $scheme (optional) Scheme to give the home url context. Currently 'http','https'
     80 * @return string Home url link with optional path appended.
     81*/
     82function bp_core_get_home_url( $blog_id = null, $path = '', $scheme = null ) {
     83        if ( function_exists( 'get_home_url' ) )
     84                return get_home_url( $blog_id, $path, $scheme );
     85
     86        // adapted from wp-includes/link-template.php function get_home_url()
     87
     88        $orig_scheme = $scheme;
     89        $scheme      = is_ssl() && !is_admin() ? 'https' : 'http';
     90
     91        if ( empty($blog_id) || !bp_core_is_multisite() )
     92                $home = get_option('home');
     93        else {
     94                /* adapted from wp-includes/ms-blogs.php
     95                        functions get_blog_address_by_id(), get_blog_details() */
     96
     97                global $wpdb;
     98
     99                $bloginfo = $wpdb->get_row( $wpdb->prepare(
     100                        "SELECT * FROM {$wpdb->blogs} WHERE blog_id = %d", (int) $blog_id ) );
     101
     102                if ( !$bloginfo ) {
     103                        global $current_blog;
     104
     105                        $bloginfo = $wpdb->get_row( $wpdb->prepare(
     106                                "SELECT * FROM {$wpdb->blogs} WHERE blog_id = %d",
     107                                        (int) defined( 'BP_ENABLE_MULTIBLOG' ) ?
     108                                                $current_blog->blog_id :
     109                                                BP_ROOT_BLOG ) );
     110                }
     111
     112                $home = untrailingslashit( esc_url(
     113                        'http://' . $bloginfo->domain . $bloginfo->path ) );
     114        }
     115
     116        $url = str_replace( 'http://', "$scheme://", $home );
     117
     118        if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
     119                $url .= '/' . ltrim( $path, '/' );
     120
     121        return apply_filters( 'home_url', $url, $path, $orig_scheme, $blog_id );
     122}
     123
    64124if ( !function_exists( 'get_blogs_of_user' ) ) {
    65125        function get_blogs_of_user() {
    66126                return false;