fix: Remove hardcoded dev mode filters from woonoow.php

🐛 CRITICAL FIX - Root Cause Found!
The plugin had hardcoded dev mode filters that forced EVERYONE into dev mode:
- add_filter('woonoow/admin_is_dev', '__return_true');
- add_filter('woonoow/admin_dev_server', fn() => 'https://woonoow.local:5173');

This caused:
- ✗ SPA trying to load from localhost:5173
- ✗ Loading @react-refresh and main.tsx (dev files)
- ✗ Not loading app.js and app.css (production files)

 Solution:
- Removed hardcoded filters from woonoow.php
- Commented them out with instructions
- Added debug logging to is_dev_mode()
- Updated installation checker to detect this issue

📝 For Developers:
If you need dev mode, add to wp-config.php:
define('WOONOOW_ADMIN_DEV', true);

Or use filter in your development plugin:
add_filter('woonoow/admin_is_dev', '__return_true');

🎯 Result:
- Production mode by default (no config needed)
- Dev mode only when explicitly enabled
- Better UX - plugin works out of the box
This commit is contained in:
dwindown
2025-11-16 13:02:04 +07:00
parent 7a967c3399
commit c1db133ffa
3 changed files with 32 additions and 3 deletions

View File

@@ -125,6 +125,24 @@ header('Content-Type: text/html; charset=utf-8');
} }
?> ?>
<h2>5b. Dev Mode Filter Check (woonoow.php)</h2>
<?php
$main_file = $plugin_dir . '/woonoow.php';
if (file_exists($main_file)) {
$content = file_get_contents($main_file);
$has_dev_filter = strpos($content, "add_filter('woonoow/admin_is_dev', '__return_true')") !== false;
if ($has_dev_filter) {
echo "<div><span class='fail'>✗ FAIL</span> - Hardcoded dev mode filter found in woonoow.php!</div>";
echo "<pre> This forces dev mode ON for everyone.\n";
echo " Remove this line from woonoow.php:\n";
echo " add_filter('woonoow/admin_is_dev', '__return_true');</pre>";
} else {
echo "<div><span class='pass'>✓ PASS</span> - No hardcoded dev mode filters</div>";
}
}
?>
<h2>6. Asset URLs</h2> <h2>6. Asset URLs</h2>
<?php <?php
if (function_exists('plugins_url')) { if (function_exists('plugins_url')) {

View File

@@ -238,8 +238,18 @@ class Assets {
/** /**
* Filter: force dev/prod mode for WooNooW admin assets. * Filter: force dev/prod mode for WooNooW admin assets.
* Return true to use Vite dev server, false to use built assets. * Return true to use Vite dev server, false to use built assets.
*
* IMPORTANT: This filter should NOT be used in production!
* Only use it during development.
*/ */
return (bool) apply_filters('woonoow/admin_is_dev', $const_dev); $filtered = apply_filters('woonoow/admin_is_dev', $const_dev);
// Debug logging (only if WP_DEBUG is enabled)
if (defined('WP_DEBUG') && WP_DEBUG && $filtered !== $const_dev) {
error_log('[WooNooW Assets] Dev mode changed by filter: ' . ($filtered ? 'true' : 'false'));
}
return (bool) $filtered;
} }
/** Dev server URL (filterable) */ /** Dev server URL (filterable) */

View File

@@ -43,5 +43,6 @@ register_activation_hook(__FILE__, function () {
update_option('woocommerce_custom_orders_table_migration_enabled', 'yes'); update_option('woocommerce_custom_orders_table_migration_enabled', 'yes');
}); });
add_filter('woonoow/admin_is_dev', '__return_true'); // Dev mode filters removed - use wp-config.php if needed:
add_filter('woonoow/admin_dev_server', fn() => 'https://woonoow.local:5173'); // add_filter('woonoow/admin_is_dev', '__return_true');
// add_filter('woonoow/admin_dev_server', fn() => 'https://woonoow.local:5173');