Skip to content

Commit e67eec7

Browse files
committed
chore: fix type case issue with id's of multisite
1 parent c5287e9 commit e67eec7

File tree

5 files changed

+37
-12
lines changed

5 files changed

+37
-12
lines changed

assets/src/components/MultiSites.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ const MultiSites = ( { setBrandSites, brandSites, setNotice } ) => {
173173
{ /* create multi select checkbox list of sites excluding current site */ }
174174
{ sites?.length > 0 ? (
175175
<div style={ { maxHeight: '400px', overflowY: 'auto', padding: '4px 4px' } }>
176-
{ sites?.filter( ( site ) => site.id !== CURRENT_SITE_ID )
177-
.filter( ( site ) => ! brandSites?.some( ( brandSite ) => brandSite.id === site.id ) )
176+
{ sites?.filter( ( site ) => String( site.id ) !== CURRENT_SITE_ID &&
177+
! brandSites?.some( ( brandSite ) => String( brandSite.id ) === String( site.id ) ) )
178178
.map( ( site ) => (
179179
<CheckboxControl
180180
key={ site.id }
@@ -188,8 +188,7 @@ const MultiSites = ( { setBrandSites, brandSites, setNotice } ) => {
188188
<p>{ __( 'No other sites available in this multisite network.', 'onedesign' ) }</p>
189189
) }
190190

191-
{ sites?.length > 0 && sites?.filter( ( site ) => site.id !== CURRENT_SITE_ID )
192-
.filter( ( site ) => ! brandSites?.some( ( brandSite ) => brandSite.id === site.id ) ).length === 0 && (
191+
{ sites?.length > 0 && sites?.filter( ( site ) => String( site.id ) !== CURRENT_SITE_ID && ! brandSites?.some( ( brandSite ) => String( brandSite.id ) === String( site.id ) ) ).length === 0 && (
193192
<p>{ __( 'All sites in this multisite network have already been added as brand sites.', 'onedesign' ) }</p>
194193
) }
195194

assets/src/js/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const PER_PAGE = 9;
2727
const MULTISITES = settings?.multisites || [];
2828
const IS_MULTISITE = settings?.isMultisite || false;
2929
const IS_GOVERNING_SITE_SELECTED = settings?.isGoverningSiteSelected || false;
30-
const CURRENT_SITE_ID = settings?.currentSiteId || '';
30+
const CURRENT_SITE_ID = String( settings?.currentSiteId ) || '';
3131

3232
export {
3333
API_NAMESPACE,

inc/classes/class-multisite.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,19 @@ public function sync_api_key_to_governing_site( string $secret_key, int $blog_id
110110

111111
// go to governing site and update shared_sites option secret_key of blog_id site.
112112
if ( $governing_site_id && $secret_key ) {
113-
switch_to_blog( $governing_site_id );
113+
if ( ! switch_to_blog( (int) $governing_site_id ) ) {
114+
return;
115+
}
114116
$shared_sites = get_option( Constants::ONEDESIGN_SHARED_SITES, array() );
115117
foreach ( $shared_sites as &$site ) {
116118
if ( (int) $site['id'] === (int) $blog_id ) {
117119
$site['api_key'] = $secret_key;
118120
break;
119121
}
120122
}
123+
121124
update_option( Constants::ONEDESIGN_SHARED_SITES, $shared_sites, false );
125+
122126
restore_current_blog();
123127
}
124128
}

inc/classes/rest/class-multisite.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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,

languages/onedesign.pot

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ msgstr ""
99
"MIME-Version: 1.0\n"
1010
"Content-Type: text/plain; charset=UTF-8\n"
1111
"Content-Transfer-Encoding: 8bit\n"
12-
"POT-Creation-Date: 2025-10-24T12:25:13+00:00\n"
12+
"POT-Creation-Date: 2025-10-24T12:43:01+00:00\n"
1313
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1414
"X-Generator: WP-CLI 2.12.0\n"
1515

@@ -265,18 +265,22 @@ msgid "Governing site removed successfully."
265265
msgstr ""
266266

267267
#: inc/classes/rest/class-multisite.php:152
268-
#: inc/classes/rest/class-multisite.php:207
268+
#: inc/classes/rest/class-multisite.php:213
269269
msgid "Invalid site info provided."
270270
msgstr ""
271271

272272
#: inc/classes/rest/class-multisite.php:163
273273
msgid "Failed to update governing site."
274274
msgstr ""
275275

276-
#: inc/classes/rest/class-multisite.php:218
276+
#: inc/classes/rest/class-multisite.php:224
277277
msgid "No governing site set. Please set a governing site first."
278278
msgstr ""
279279

280+
#: inc/classes/rest/class-multisite.php:261
281+
msgid "Failed to switch to governing site blog."
282+
msgstr ""
283+
280284
#: inc/classes/rest/class-patterns.php:236
281285
#: inc/classes/rest/class-patterns.php:359
282286
#: inc/classes/rest/class-patterns.php:569

0 commit comments

Comments
 (0)