From 6f3772e82bdb82e0912b027ce0c9becb3132690c Mon Sep 17 00:00:00 2001 From: David Stone Date: Fri, 27 Nov 2026 11:03:24 -0700 Subject: [PATCH] fix: enforce Allow Template Switching setting on the server --- .../class-template-switching-admin-page.php | 14 ++++++++++++++ inc/ui/class-template-switching-element.php | 11 +++++++++++ 2 files changed, 25 insertions(+) diff --git a/inc/admin-pages/customer-panel/class-template-switching-admin-page.php b/inc/admin-pages/customer-panel/class-template-switching-admin-page.php index 586c0d2af..106181c2b 100644 --- a/inc/admin-pages/customer-panel/class-template-switching-admin-page.php +++ b/inc/admin-pages/customer-panel/class-template-switching-admin-page.php @@ -135,6 +135,20 @@ public function register_scripts(): void { * @return void */ public function page_loaded(): void { + /* + * Enforce the "Allow Template Switching" setting on the page itself, + * not only where the Site Actions link is rendered. + */ + if ( ! wu_get_setting('allow_template_switching', true)) { + wp_die( + esc_html__('Template switching is disabled.', 'ultimate-multisite'), + '', + [ + 'response' => 403, + 'back_link' => true, + ] + ); + } do_action('wu_template_switching_admin_page', null); diff --git a/inc/ui/class-template-switching-element.php b/inc/ui/class-template-switching-element.php index 71a4cd1e3..da4f1ab77 100644 --- a/inc/ui/class-template-switching-element.php +++ b/inc/ui/class-template-switching-element.php @@ -368,6 +368,17 @@ public function switch_template() { return; } + /* + * The "Allow Template Switching" setting must be enforced here, not only + * where the Site Actions link is rendered. Otherwise a customer who + * calls the handler directly can overwrite their site while switching + * is disabled network-wide. + */ + if ( ! wu_get_setting('allow_template_switching', true)) { + wp_send_json_error(new \WP_Error('template_switching_disabled', __('Template switching is disabled.', 'ultimate-multisite'))); + return; + } + $template_id = (int) wu_request('template_id', ''); // false means MODE_DEFAULT (no restriction) — all templates are allowed.