| | 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 | */ |
| | 82 | function 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 | |