Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/11/2020 01:33:08 PM (4 years ago)
Author:
imath
Message:

BP Blogs: improve Site Icons / Blavatar synchronization

Make sure BuddyPress tries to synchronize Sites Icons / Blavatars even when it's not network activated.

Add a new BP Repair tool to repair this synchronization. This can be needed when a different site of the network has its site icon updated after the BuddyPress Sites directory already listed this site previously.

Props vapvarun

Fixes #8384

File:
1 edited

Legend:

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

    r12745 r12779  
    550550 */
    551551function bp_blogs_update_option_site_icon( $old_value, $new_value ) {
     552    $blog_id = get_current_blog_id();
     553
    552554    if ( 0 === $new_value ) {
    553         bp_blogs_update_blogmeta( get_current_blog_id(), 'site_icon_url_thumb', 0 );
    554         bp_blogs_update_blogmeta( get_current_blog_id(), 'site_icon_url_full',  0 );
     555        bp_blogs_update_blogmeta( $blog_id, 'site_icon_url_thumb', 0 );
     556        bp_blogs_update_blogmeta( $blog_id, 'site_icon_url_full',  0 );
    555557    } else {
    556558        // Save site icon URL as blogmeta.
    557         bp_blogs_update_blogmeta( get_current_blog_id(), 'site_icon_url_thumb', get_site_icon_url( bp_core_avatar_thumb_width() ) );
    558         bp_blogs_update_blogmeta( get_current_blog_id(), 'site_icon_url_full',  get_site_icon_url( bp_core_avatar_full_width()  ) );
     559        bp_blogs_update_blogmeta( $blog_id, 'site_icon_url_thumb', bp_blogs_get_site_icon_url( $blog_id, bp_core_avatar_thumb_width() ) );
     560        bp_blogs_update_blogmeta( $blog_id, 'site_icon_url_full',  bp_blogs_get_site_icon_url( $blog_id, bp_core_avatar_full_width()  ) );
    559561    }
    560562}
     
    15641566    return wpmu_validate_blog_signup( $blog_name, $blog_title, $user );
    15651567}
     1568
     1569/**
     1570 * Gets the site icon URL even when BuddyPress is not network activated.
     1571 *
     1572 * @since 7.0.0
     1573 *
     1574 * @param integer $blog_id The ID of the blog to get the site icon URL for.
     1575 * @param integer $size    The size of the site icon.
     1576 * @return string          The site icon URL
     1577 */
     1578function bp_blogs_get_site_icon_url( $blog_id = 0, $size = 512 ) {
     1579    if ( is_multisite() && ! bp_is_network_activated() && ! bp_is_root_blog( $blog_id ) ) {
     1580        $switched_blog = false;
     1581        $url           = '';
     1582
     1583        if ( $blog_id && get_current_blog_id() !== (int) $blog_id ) {
     1584            switch_to_blog( $blog_id );
     1585            $switched_blog = true;
     1586        }
     1587
     1588        $site_icon_id = get_option( 'site_icon' );
     1589
     1590        if ( $site_icon_id ) {
     1591            $site_icon_data = wp_get_attachment_metadata( $site_icon_id );
     1592            $sizes          = wp_list_pluck( $site_icon_data['sizes'], 'width' );
     1593
     1594            sort( $sizes );
     1595            $closest = 'full';
     1596
     1597            foreach ( $sizes as $width ) {
     1598                $closest = array( $width, $width );
     1599
     1600                if ( (int) $size < (int) $width ) {
     1601                    break;
     1602                }
     1603            }
     1604
     1605            $url = wp_get_attachment_image_url( $site_icon_id, $closest );
     1606        }
     1607
     1608        if ( $switched_blog ) {
     1609            restore_current_blog();
     1610        }
     1611
     1612        return $url;
     1613    }
     1614
     1615    return get_site_icon_url( $size, '', $blog_id );
     1616}
Note: See TracChangeset for help on using the changeset viewer.