Skip to:
Content

BuddyPress.org

Changeset 9960


Ignore:
Timestamp:
06/22/2015 02:14:25 PM (9 years ago)
Author:
boonebgorges
Message:

Introduce 'title' argument for bp_get_blog_avatar().

This changeset also changes the default value of the 'title' attribute of blog
avatars to the display name of the site admin. The previous value was the site
admin's email address, which could introduce privacy concerns.

Props lenasterg.
Fixes #6519.

Location:
trunk
Files:
2 edited

Legend:

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

    r9959 r9960  
    524524     * admin. Filter 'bp_get_blog_avatar_' . $blog_id to customize.
    525525     *
     526     * @since BuddyPress (2.4.0) Introduced `$title` argument.
     527     *
    526528     * @see bp_core_fetch_avatar() For a description of arguments and
    527529     *      return values.
     
    533535     *     @type string   $alt     Default: 'Profile picture of site author [user name]'.
    534536     *     @type string   $class   Default: 'avatar'.
     537     *     @type string   $title   Default: 'Profile picture of site author [user name]'.
    535538     *     @type string   $type    Default: 'full'.
    536539     *     @type int|bool $width   Default: false.
     
    550553        }
    551554
     555        $author_displayname = bp_core_get_user_displayname( $blogs_template->blog->admin_user_id );
     556
    552557        // Parse the arguments
    553558        $r = bp_parse_args( $args, array(
     
    556561            'height'  => false,
    557562            'class'   => 'avatar',
     563            'title'   => sprintf( __( 'Profile picture of site author %s', 'buddypress' ), esc_attr( $author_displayname ) ),
    558564            'id'      => false,
    559             'alt'     => sprintf( __( 'Profile picture of site author %s', 'buddypress' ), bp_core_get_user_displayname( $blogs_template->blog->admin_user_id ) ),
     565            'alt'     => sprintf( __( 'Profile picture of site author %s', 'buddypress' ), esc_attr( $author_displayname ) ),
    560566            'no_grav' => true,
    561567        ) );
     
    564570        $avatar = bp_core_fetch_avatar( array(
    565571            'item_id'    => $blogs_template->blog->admin_user_id,
    566             'title'      => $blogs_template->blog->admin_user_email,
     572            'title'      => $r['title'],
    567573            //'avatar_dir' => 'blog-avatars',
    568574            //'object'     => 'blog',
  • trunk/tests/phpunit/testcases/blogs/template.php

    r9819 r9960  
    367367        $_REQUEST = $request;
    368368    }
     369
     370    /**
     371     * @ticket BP6519
     372     */
     373    public function test_bp_blog_get_avatar_should_respect_title_parameter() {
     374        global $blogs_template;
     375
     376        if ( isset( $blogs_template ) ) {
     377            $_blogs_template = $blogs_template;
     378        }
     379
     380        $user = $this->factory->user->create_and_get();
     381
     382        $blogs_template = new stdClass;
     383        $blogs_template->blog = new stdClass;
     384        $blogs_template->blog->blog_id = get_current_blog_id();
     385        $blogs_template->blog->admin_user_id = $user->ID;
     386        $blogs_template->blog->admin_user_email = $user->user_email;
     387
     388        $actual = bp_get_blog_avatar( array(
     389            'title' => 'Foo',
     390        ) );
     391
     392        if ( isset( $_blogs_template ) ) {
     393            $blogs_template = $_blogs_template;
     394        } else {
     395            unset( $blogs_template );
     396        }
     397
     398        $this->assertContains( 'title="Foo"', $actual );
     399    }
     400
     401    /**
     402     * @ticket BP6519
     403     */
     404    public function test_bp_blog_get_avatar_title_attribute_should_default_to_user_displayname() {
     405        global $blogs_template;
     406
     407        if ( isset( $blogs_template ) ) {
     408            $_blogs_template = $blogs_template;
     409        }
     410
     411        $user = $this->factory->user->create_and_get();
     412
     413        $blogs_template = new stdClass;
     414        $blogs_template->blog = new stdClass;
     415        $blogs_template->blog->blog_id = get_current_blog_id();
     416        $blogs_template->blog->admin_user_id = $user->ID;
     417        $blogs_template->blog->admin_user_email = $user->user_email;
     418
     419        $actual = bp_get_blog_avatar();
     420
     421        if ( isset( $_blogs_template ) ) {
     422            $blogs_template = $_blogs_template;
     423        } else {
     424            unset( $blogs_template );
     425        }
     426
     427        $this->assertContains( 'title="Profile picture of site author ' . bp_core_get_user_displayname( $user->ID ) . '"', $actual );
     428    }
    369429}
Note: See TracChangeset for help on using the changeset viewer.