@@ -155,6 +155,16 @@ public function assign_brand_site_on_new_site_creation( \WP_Site $new_site ): vo
155155 }
156156 }
157157
158+ /**
159+ * Update site details in governing site table on option changes.
160+ *
161+ * @param string $option_name The name of the updated option.
162+ * @param mixed $old_value The old value of the option.
163+ * @param mixed $new_value The new value of the option.
164+ *
165+ * @return void
166+ */
167+
158168 /**
159169 * Update site details in governing site table on option changes.
160170 *
@@ -173,15 +183,30 @@ public function update_site_details_in_governing_site_table( string $option_name
173183 return ;
174184 }
175185
176- $ relevant_options = array ( 'blogname ' , 'siteurl ' , 'home ' );
177- $ current_site_id = get_current_blog_id ();
186+ $ relevant_options = array ( 'blogname ' , 'siteurl ' , 'home ' , 'site_icon ' );
178187
188+ $ current_site_id = get_current_blog_id ();
189+
190+ // For site_icon: Fetch details in CHILD site context BEFORE switching.
191+ $ logo_url = '' ;
192+ $ logo_id = 0 ;
179193 if ( in_array ( $ option_name , $ relevant_options , true ) ) {
194+ if ( 'site_icon ' === $ option_name ) {
195+ if ( ! empty ( $ new_value ) && is_numeric ( $ new_value ) && (int ) $ new_value > 0 ) {
196+ $ attachment = get_post ( (int ) $ new_value );
197+ if ( $ attachment && 'attachment ' === $ attachment ->post_type ) {
198+ $ logo_url = wp_get_attachment_url ( (int ) $ new_value );
199+ $ logo_id = (int ) $ new_value ;
200+ }
201+ }
202+ }
203+
204+ // Now switch to governing site.
180205 if ( ! switch_to_blog ( (int ) $ governing_site_id ) ) {
181206 return ;
182207 }
183208
184- // get shared sites from governing site.
209+ // Get shared sites from governing site.
185210 $ shared_sites = get_option ( Constants::ONEDESIGN_SHARED_SITES , array () );
186211
187212 foreach ( $ shared_sites as &$ site ) {
@@ -190,15 +215,18 @@ public function update_site_details_in_governing_site_table( string $option_name
190215 $ site ['name ' ] = sanitize_text_field ( $ new_value );
191216 } elseif ( in_array ( $ option_name , array ( 'siteurl ' , 'home ' ), true ) ) {
192217 $ site ['url ' ] = esc_url_raw ( $ new_value );
218+ } elseif ( 'site_icon ' === $ option_name ) {
219+ $ site ['logo ' ] = $ logo_url ;
220+ $ site ['logo_id ' ] = $ logo_id ;
193221 }
194222 break ;
195223 }
196224 }
197225
198- // save the updated shared_sites option.
226+ // Save the updated shared_sites option.
199227 update_option ( Constants::ONEDESIGN_SHARED_SITES , $ shared_sites , false );
200228
201- // restore blog.
229+ // Restore blog.
202230 restore_current_blog ();
203231 }
204232 }
0 commit comments