Skip to content

Commit 35611d2

Browse files
authored
Merge pull request #353 from Ultimate-Multisite/fix/template-validation-type-mismatch-351
Fix template validation type mismatch causing "template not available" error
2 parents 70af026 + 717112f commit 35611d2

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

inc/limitations/class-limit-site-templates.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ public function get_available_site_templates() {
221221
if (self::BEHAVIOR_AVAILABLE === $site_settings->behavior ||
222222
self::BEHAVIOR_PRE_SELECTED === $site_settings->behavior ||
223223
self::MODE_DEFAULT === $this->mode) {
224-
$available[] = $site_id;
224+
// Convert to integer to match type used in validation (absint)
225+
$available[] = absint($site_id);
225226
}
226227
}
227228

@@ -248,7 +249,8 @@ public function get_pre_selected_site_template() {
248249
$site_settings = (object) $site_settings;
249250

250251
if (self::BEHAVIOR_PRE_SELECTED === $site_settings->behavior) {
251-
$pre_selected_site_template = $site_id;
252+
// Convert to integer to match type used in validation (absint)
253+
$pre_selected_site_template = absint($site_id);
252254
}
253255
}
254256

tests/WP_Ultimo/Objects/Limitations_Test.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,4 +910,42 @@ public function test_checkout_plan_plus_addon_preserves_templates(): void {
910910
// Disk space should be additive
911911
$this->assertEquals(600, $limits->disk_space->get_limit(), 'Disk space should be summed');
912912
}
913+
914+
/**
915+
* Test that get_available_site_templates returns integers, not strings.
916+
*
917+
* Regression test for issue #351: When template IDs are stored as string keys
918+
* in the limit array, they must be converted to integers for proper comparison
919+
* in the Site_Template validation rule.
920+
*/
921+
public function test_available_site_templates_returns_integers(): void {
922+
923+
$limitations = new Limitations([
924+
'site_templates' => [
925+
'enabled' => true,
926+
'mode' => 'choose_available_templates',
927+
'limit' => [
928+
'123' => ['behavior' => 'available'],
929+
'456' => ['behavior' => 'pre_selected'],
930+
'789' => ['behavior' => 'not_available'],
931+
],
932+
],
933+
]);
934+
935+
$available = $limitations->site_templates->get_available_site_templates();
936+
937+
// Should return integers, not strings
938+
$this->assertContains(123, $available, 'Template 123 should be in available array as integer');
939+
$this->assertContains(456, $available, 'Template 456 should be in available array as integer');
940+
$this->assertNotContains(789, $available, 'Template 789 should not be available');
941+
942+
// Verify strict type checking
943+
foreach ($available as $template_id) {
944+
$this->assertIsInt($template_id, 'All template IDs should be integers');
945+
}
946+
947+
// Verify in_array works with strict comparison
948+
$this->assertTrue(in_array(123, $available, true), 'in_array with strict=true should find integer 123');
949+
$this->assertTrue(in_array(456, $available, true), 'in_array with strict=true should find integer 456');
950+
}
913951
}

0 commit comments

Comments
 (0)