Fix button roundtrip in editor, alignment persistence, and test email rendering

This commit is contained in:
Dwindi Ramadhana
2026-01-17 13:10:50 +07:00
parent 0e9ace902d
commit 6d2136d3b5
61 changed files with 8287 additions and 866 deletions

View File

@@ -166,7 +166,14 @@ class TemplateOverride
'top'
);
} else {
// Rewrite /slug/anything to serve the SPA page
// Rewrite /slug to serve the SPA page (base URL)
add_rewrite_rule(
'^' . preg_quote($spa_slug, '/') . '/?$',
'index.php?page_id=' . $spa_page_id,
'top'
);
// Rewrite /slug/anything to serve the SPA page with path
// React Router handles the path after that
add_rewrite_rule(
'^' . preg_quote($spa_slug, '/') . '/(.*)$',
@@ -306,8 +313,30 @@ class TemplateOverride
wp_redirect($build_route('my-account'), 302);
exit;
}
// Redirect structural pages with WooNooW sections to SPA
if (is_singular('page') && $post) {
// Skip the SPA page itself and frontpage
if ($post->ID == $spa_page_id || $post->ID == $frontpage_id) {
return;
}
// Check if page has WooNooW structure
$structure = get_post_meta($post->ID, '_wn_page_structure', true);
if (!empty($structure) && !empty($structure['sections'])) {
// Redirect to SPA with page slug route
$page_slug = $post->post_name;
wp_redirect($build_route($page_slug), 302);
exit;
}
}
}
/**
* Serve SPA template directly for frontpage SPA routes
* When SPA page is set as WordPress frontpage, intercept known routes
* and serve the SPA template directly (bypasses WooCommerce templates)
*/
/**
* Serve SPA template directly for frontpage SPA routes
* When SPA page is set as WordPress frontpage, intercept known routes
@@ -331,8 +360,19 @@ class TemplateOverride
return; // SPA is not frontpage, let normal routing handle it
}
// Get the current request path
// Get the current request path relative to site root
$request_uri = $_SERVER['REQUEST_URI'] ?? '/';
$home_path = parse_url(home_url(), PHP_URL_PATH);
// Normalize request URI for subdirectory installs
if ($home_path && $home_path !== '/') {
$home_path = rtrim($home_path, '/');
if (strpos($request_uri, $home_path) === 0) {
$request_uri = substr($request_uri, strlen($home_path));
if (empty($request_uri)) $request_uri = '/';
}
}
$path = parse_url($request_uri, PHP_URL_PATH);
$path = '/' . trim($path, '/');
@@ -365,6 +405,27 @@ class TemplateOverride
}
}
// Check for structural pages with WooNooW sections
if (!$should_serve_spa && !empty($path) && $path !== '/') {
// Try to find a page by slug matching the path
$slug = trim($path, '/');
// Handle nested slugs (get the last part as the page slug)
if (strpos($slug, '/') !== false) {
$slug_parts = explode('/', $slug);
$slug = end($slug_parts);
}
$page = get_page_by_path($slug);
if ($page) {
// Check if this page has WooNooW structure
$structure = get_post_meta($page->ID, '_wn_page_structure', true);
if (!empty($structure) && !empty($structure['sections'])) {
$should_serve_spa = true;
}
}
}
// Not a SPA route
if (!$should_serve_spa) {
return;
@@ -396,8 +457,8 @@ class TemplateOverride
*/
public static function disable_canonical_redirect($redirect_url, $requested_url)
{
$settings = get_option('woonoow_customer_spa_settings', []);
$mode = isset($settings['mode']) ? $settings['mode'] : 'disabled';
$settings = get_option('woonoow_appearance_settings', []);
$mode = isset($settings['general']['spa_mode']) ? $settings['general']['spa_mode'] : 'disabled';
// Only disable redirects in full SPA mode
if ($mode !== 'full') {
@@ -405,6 +466,7 @@ class TemplateOverride
}
// Check if this is a SPA route
// We include /product/ and standard endpoints
$spa_routes = ['/product/', '/cart', '/checkout', '/my-account'];
foreach ($spa_routes as $route) {
@@ -733,6 +795,20 @@ class TemplateOverride
*/
public static function serve_ssr_content($page_id, $type = 'page', $post_obj = null)
{
// Generate cache key
$cache_id = $post_obj ? $post_obj->ID : $page_id;
$cache_key = "wn_ssr_{$type}_{$cache_id}";
// Check cache TTL (default 1 hour, filterable)
$cache_ttl = apply_filters('woonoow_ssr_cache_ttl', HOUR_IN_SECONDS);
// Try to get cached content
$cached = get_transient($cache_key);
if ($cached !== false) {
echo $cached;
exit;
}
// Get page structure
if ($type === 'page') {
$structure = get_post_meta($page_id, '_wn_page_structure', true);
@@ -783,7 +859,8 @@ class TemplateOverride
wp_trim_words(wp_strip_all_tags($post_obj->post_content), 30);
}
// Output SSR HTML
// Output SSR HTML - start output buffering for caching
ob_start();
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
@@ -825,6 +902,14 @@ class TemplateOverride
</body>
</html>
<?php
// Get buffered output
$output = ob_get_clean();
// Cache the output for bots (uses cache TTL from filter)
set_transient($cache_key, $output, $cache_ttl);
// Output and exit
echo $output;
exit;
}