Files
WooNooW/includes/Branding.php
dwindown 64cfa39b75 fix: Image upload, remove WP login branding, implement dark mode
## 1. Fix Image Upload 

**Issue:** Image upload failing due to missing nonce

**Fix:**
- Better nonce detection (wpApiSettings, WooNooW, meta tag)
- Added credentials: 'same-origin'
- Better error handling with error messages
- Clarified image size recommendations (not strict requirements)

**Changes:**
- Logo: "Recommended size: 200x60px (or similar ratio)"
- Icon: "Recommended: 32x32px or larger square image"

---

## 2. Remove WordPress Login Page Branding 

**Issue:** Misunderstood - implemented WP login branding instead of SPA login

**Fix:**
- Removed all WordPress login page customization
- Removed login_enqueue_scripts hook
- Removed login_headerurl filter
- Removed login_headertext filter
- Removed customize_login_page() method
- Removed login_logo_url() method
- Removed login_logo_title() method

**Note:** WooNooW uses standalone SPA login, not WordPress login page

---

## 3. Implement Dark/Light Mode 

### Components Created:

**ThemeProvider.tsx:**
- Theme context (light, dark, system)
- Automatic system theme detection
- localStorage persistence (woonoow_theme)
- Applies .light or .dark class to <html>
- Listens for system theme changes

**ThemeToggle.tsx:**
- Dropdown menu with 3 options:
  - ☀️ Light
  - 🌙 Dark
  - 🖥️ System
- Shows current selection with checkmark
- Icon changes based on actual theme

### Integration:
- Wrapped App with ThemeProvider in main.tsx
- Added ThemeToggle to header (before fullscreen button)
- Uses existing dark mode CSS variables (already configured)

### Features:
-  Light mode
-  Dark mode
-  System preference (auto)
-  Persists in localStorage
-  Smooth transitions
-  Icon updates dynamically

### CSS:
- Already configured: darkMode: ["class"] in tailwind.config.js
- Dark mode variables already defined in index.css
- No additional CSS needed

---

## Result

 Image upload fixed with better error handling
 WordPress login branding removed (not needed)
 Dark/Light mode fully functional
 Theme toggle in header
 System preference support
 Persists across sessions

**Ready to test!**
2025-11-10 23:18:56 +07:00

82 lines
2.1 KiB
PHP

<?php
/**
* Branding Handler
*
* Handles logo, favicon, colors, and login page customization.
*
* @package WooNooW
*/
namespace WooNooW;
class Branding {
/**
* Initialize branding
*/
public static function init() {
// Apply colors to admin
add_action('admin_head', [__CLASS__, 'inject_colors']);
// Apply favicon
add_action('wp_head', [__CLASS__, 'inject_favicon']);
add_action('admin_head', [__CLASS__, 'inject_favicon']);
// Note: Login page branding removed - WooNooW uses standalone SPA login
}
/**
* Inject brand colors as CSS variables
*/
public static function inject_colors() {
$primary = get_option('woonoow_primary_color', '#3b82f6');
$accent = get_option('woonoow_accent_color', '#10b981');
$error = get_option('woonoow_error_color', '#ef4444');
?>
<style id="woonoow-brand-colors">
:root {
--woonoow-primary: <?php echo esc_attr($primary); ?>;
--woonoow-accent: <?php echo esc_attr($accent); ?>;
--woonoow-error: <?php echo esc_attr($error); ?>;
}
</style>
<?php
}
/**
* Inject favicon
*/
public static function inject_favicon() {
$icon = get_option('woonoow_store_icon', '');
if (!empty($icon)) {
?>
<link rel="icon" type="image/png" href="<?php echo esc_url($icon); ?>" />
<link rel="apple-touch-icon" href="<?php echo esc_url($icon); ?>" />
<?php
}
}
/**
* Get logo URL or fallback to text
*
* @return array ['type' => 'image'|'text', 'value' => string]
*/
public static function get_logo() {
$logo = get_option('woonoow_store_logo', '');
if (!empty($logo)) {
return [
'type' => 'image',
'value' => $logo,
];
}
return [
'type' => 'text',
'value' => get_option('blogname', 'WooNooW'),
];
}
}