[wp-trac] [WordPress Trac] #58197: $blog_id always returns 0 in get_site_icon_url hook

WordPress Trac noreply at wordpress.org
Thu Apr 27 08:09:10 UTC 2023


#58197: $blog_id always returns 0 in get_site_icon_url hook
--------------------------+------------------------
 Reporter:  revxx14       |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  6.3
Component:  Customize     |     Version:  4.4
 Severity:  normal        |  Resolution:
 Keywords:  needs-patch   |     Focuses:  multisite
--------------------------+------------------------

Comment (by petitphp):

 Hi @revxx14

 Looking at the code for [https://github.com/WordPress/wordpress-
 develop/blob/trunk/src/wp-includes/general-template.php#L951
 get_site_icon_url] function, I think it's the expected behavior. The value
 use by the filter is what was passed as a parameter to the function and
 not the current blog id.

 The default value of `$blog_id` is `0`, which mean "the current blog".

 I'm not sure that I completely understand your condition, but in theory
 you could add a check  to account for that case
 {{{#!php
 <?php
 /**
  * Register favicon
  *
  * @param string $url
  * @param integer $size
  * @param integer $blog_id
  * @return string
  */
 function mytheme_set_site_icon_url(string $url, int $size, int $blog_id):
 string {
     if ( empty( $blog_id ) || get_current_blog_id() === $blog_id) {
         return get_theme_file_uri("assets/media/logo-
 favicon-{$size}x{$size}.svg");
     }

     return $url;
 }
 add_filter("get_site_icon_url", "mytheme_set_site_icon_url", 10, 3);
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58197#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list