From f092156fa75e837f0cd6cd9485ffe8cb1d324895 Mon Sep 17 00:00:00 2001 From: David Stone Date: Mon, 6 Apr 2026 20:50:15 -0600 Subject: [PATCH] fix: template selection blocked when product uses default (allow all) mode get_available_site_templates() returned [] for MODE_DEFAULT, causing the validation rule to block all templates with 'not available for this product'. Return false for MODE_DEFAULT to signal no restriction, matching the is_array() gate in the Site_Template validation rule. Guard is_template_available() against the false return to avoid a PHP warning. --- inc/limitations/class-limit-site-templates.php | 11 +++++++++-- inc/limits/class-site-template-limits.php | 5 +++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/inc/limitations/class-limit-site-templates.php b/inc/limitations/class-limit-site-templates.php index 8fafb34bf..123897b8f 100644 --- a/inc/limitations/class-limit-site-templates.php +++ b/inc/limitations/class-limit-site-templates.php @@ -205,6 +205,14 @@ public function get_all_templates(): array { */ public function get_available_site_templates() { + /* + * MODE_DEFAULT means "allow all templates" — no restriction. + * Return false so callers that check is_array() treat this as unrestricted. + */ + if (self::MODE_DEFAULT === $this->mode) { + return false; + } + $limits = $this->get_limit(); if ( ! $limits) { @@ -219,8 +227,7 @@ public function get_available_site_templates() { $site_settings = (object) $site_settings; if (self::BEHAVIOR_AVAILABLE === $site_settings->behavior || - self::BEHAVIOR_PRE_SELECTED === $site_settings->behavior || - self::MODE_DEFAULT === $this->mode) { + self::BEHAVIOR_PRE_SELECTED === $site_settings->behavior) { // Convert to integer to match type used in validation (absint) $available[] = absint($site_id); } diff --git a/inc/limits/class-site-template-limits.php b/inc/limits/class-site-template-limits.php index a9214adba..cca0b13e5 100644 --- a/inc/limits/class-site-template-limits.php +++ b/inc/limits/class-site-template-limits.php @@ -220,6 +220,11 @@ protected function is_template_available( $products, $template_id ) { } else { $available_templates = $limits->site_templates->get_available_site_templates(); + // false means no restriction (MODE_DEFAULT) — all templates are available. + if ( false === $available_templates ) { + return true; + } + return in_array( $template_id, $available_templates, true ); } }