Skip to content

Commit

Permalink
Merge pull request #248 from lloc/dev
Browse files Browse the repository at this point in the history
Blavatar functionality fixed
  • Loading branch information
lloc committed Sep 29, 2023
2 parents 289e798 + 63798ce commit 3b9cfa9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
23 changes: 23 additions & 0 deletions includes/MslsBlog.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,27 @@ public static function description( MslsBlog $a, MslsBlog $b ) {
return self::_cmp( $a->get_description(), $b->get_description() );
}

/**
* @return string
*/
public function get_blavatar(): string {
$blavatar_html = '<div class="blavatar"></div>';
$show_site_icons = apply_filters( 'wp_admin_bar_show_site_icons', true );

switch_to_blog( $this->obj->userblog_id );

if ( true === $show_site_icons && has_site_icon( $this->obj->userblog_id ) ) {
$blavatar_html = sprintf(
'<img class="blavatar" src="%s" srcset="%s 2x" alt="" width="16" height="16"%s />',
esc_url( get_site_icon_url( 16 ) ),
esc_url( get_site_icon_url( 32 ) ),
( wp_lazy_loading_enabled( 'img', 'site_icon_in_toolbar' ) ? ' loading="lazy"' : '' )
);
}

restore_current_blog();

return $blavatar_html;
}

}
6 changes: 4 additions & 2 deletions includes/MslsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,13 @@ public static function get_output() {

/**
* @param $wp_admin_bar
*
* @return void
*/
public static function update_adminbar( \WP_Admin_Bar $wp_admin_bar ) {
public static function update_adminbar( \WP_Admin_Bar $wp_admin_bar ): void {
$blog_collection = MslsBlogCollection::instance();
foreach ( $blog_collection->get_plugin_active_blogs() as $blog ) {
$title = '<div class="blavatar"></div>' . $blog->get_title();
$title = $blog->get_blavatar() . $blog->get_title();

$wp_admin_bar->add_node( [ 'id' => 'blog-' . $blog->userblog_id, 'title' => $title ] );
}
Expand Down

0 comments on commit 3b9cfa9

Please sign in to comment.