Skip to:
Content

BuddyPress.org

Changeset 14072


Ignore:
Timestamp:
11/03/2024 06:58:50 PM (5 months ago)
Author:
espellcaste
Message:

Blogs: blog_id is accepted in the bp_get_blog_avatar, regardless if there is a blog in the current loop.

Props imath.

Closes https://github.com/buddypress/buddypress/pull/398
Fixes #9228

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/bp-blogs-template.php

    r14026 r14072  
    360360     *     @type bool     $html          Default: true.
    361361     * }
    362      * @return string User avatar string.
     362     * @return string|bool User avatar string. False if avatars are turned off.
    363363     */
    364364    function bp_get_blog_avatar( $args = '' ) {
     
    374374        $alt_attribute = __( 'Site icon for the blog', 'buddypress' );
    375375
    376         $has_current_blog = isset( $blogs_template ) && isset( $blogs_template->blog->blog_id );
    377 
    378         if ( false === $has_current_blog && isset( $args['blog_id'] ) && $args['blog_id'] ) {
     376        if ( ! empty( $args['blog_id'] ) ) {
    379377            $blog_id = (int) $args['blog_id'];
    380         } else if ( true === $has_current_blog ) {
     378        } else if ( isset( $blogs_template->blog->blog_id ) ) {
    381379            $blog_id = bp_get_blog_id();
    382380
     
    536534        global $blogs_template;
    537535
     536        $name = '';
     537
     538        if ( ! empty( $blogs_template->blog->name ) ) {
     539            $name = $blogs_template->blog->name;
     540        }
     541
    538542        /**
    539543         * Filters the name of the current blog in the loop.
     
    543547         * @param string $name Name of the current blog in the loop.
    544548         */
    545         return apply_filters( 'bp_get_blog_name', $blogs_template->blog->name );
     549        return apply_filters( 'bp_get_blog_name', $name );
    546550    }
    547551
  • trunk/tests/phpunit/testcases/blogs/template.php

    r14026 r14072  
    444444    }
    445445
     446    /**
     447     * @BP9228
     448     * @group avatar
     449     * @group BP_Blogs_Template
     450     * @group bp_get_blog_avatar
     451     */
     452    public function test_bp_get_blog_default_avatar_inside_blogs_template() {
     453        $this->skipWithoutMultisite();
     454
     455        $b1 = self::factory()->blog->create();
     456        $b2 = self::factory()->blog->create();
     457
     458        // Fake the global
     459        global $blogs_template;
     460
     461        $blogs_template = new stdClass;
     462        $blogs_template->blog = new stdClass;
     463        $blogs_template->blog->blog_id = $b1;
     464
     465        $expected = buddypress()->plugin_url . "bp-core/images/mystery-blog.png";
     466
     467        // Get from global blog_id.
     468        $avatar = bp_get_blog_avatar();
     469        $this->assertTrue( str_contains( $avatar, "blog-{$b1}-avatar" ) );
     470        $this->assertTrue( str_contains( $avatar, $expected ) );
     471
     472        // Get from the blog_id passed in, instead of global.
     473        $avatar = bp_get_blog_avatar( array( 'blog_id' => $b2 ) );
     474        $this->assertTrue( str_contains( $avatar, "blog-{$b2}-avatar" ) );
     475        $this->assertTrue( str_contains( $avatar, $expected ) );
     476
     477        $blogs_template = null;
     478    }
     479
    446480    public function filter_blog_avatar() {
    447481        return BP_TESTS_DIR . 'assets/upside-down.jpg';
Note: See TracChangeset for help on using the changeset viewer.