@@ -167,8 +167,13 @@ public function set_multisite_governing_site( \WP_REST_Request $request ): WP_RE
167167
168168 // set all existing sites site-type as brand-site and current site as governing-site.
169169 $ multisite_info = Utils::get_all_multisites_info ();
170+
170171 foreach ( $ multisite_info as $ site ) {
171- switch_to_blog ( $ site ['id ' ] );
172+
173+ if ( ! switch_to_blog ( (int ) $ site ['id ' ] ) ) {
174+ continue ;
175+ }
176+
172177 if ( intval ( $ site ['id ' ] ) === intval ( $ governing_site_id ) ) {
173178 update_option ( Constants::ONEDESIGN_SITE_TYPE , 'governing-site ' , false );
174179 delete_option ( Constants::ONEDESIGN_GOVERNING_SITE_URL );
@@ -179,6 +184,7 @@ public function set_multisite_governing_site( \WP_REST_Request $request ): WP_RE
179184 delete_option ( Constants::ONEDESIGN_GOVERNING_SITE_URL );
180185 delete_option ( Constants::ONEDESIGN_SHARED_SITES );
181186 }
187+
182188 restore_current_blog ();
183189 }
184190
@@ -227,7 +233,9 @@ public function add_multisite_sites( \WP_REST_Request $request ): WP_REST_Respon
227233 foreach ( $ site_ids as $ site_id ) {
228234
229235 // switch to each site and update option of onedesign_site_type as brand-site.
230- switch_to_blog ( $ site_id );
236+ if ( ! switch_to_blog ( (int ) $ site_id ) ) {
237+ continue ;
238+ }
231239
232240 $ shared_sites [] = array (
233241 'id ' => $ site_id ,
@@ -247,8 +255,16 @@ public function add_multisite_sites( \WP_REST_Request $request ): WP_REST_Respon
247255 }
248256
249257 // update shared sites in governing site.
250- switch_to_blog ( $ governing_site_id );
258+ if ( ! switch_to_blog ( (int ) $ governing_site_id ) ) {
259+ return new WP_Error (
260+ sprintf ( 'failed_to_switch_blog_%d ' , $ governing_site_id ),
261+ __ ( 'Failed to switch to governing site blog. ' , 'onedesign ' ),
262+ array ( 'status ' => 500 )
263+ );
264+ }
265+
251266 update_option ( Constants::ONEDESIGN_SHARED_SITES , $ shared_sites , false );
267+
252268 restore_current_blog ();
253269
254270 return new WP_REST_Response (
@@ -265,7 +281,9 @@ public function add_multisite_sites( \WP_REST_Request $request ): WP_REST_Respon
265281 * @return WP_REST_Response
266282 */
267283 public function get_all_multisite_sites (): WP_REST_Response {
284+
268285 $ all_multisites = Utils::get_all_multisites_info ();
286+
269287 return new WP_REST_Response (
270288 array (
271289 'success ' => true ,
0 commit comments