Features: - 30+ Custom Skills (cognitive, development, UI/UX, autonomous agents) - RalphLoop autonomous agent integration - Multi-AI consultation (Qwen) - Agent management system with sync capabilities - Custom hooks for session management - MCP servers integration - Plugin marketplace setup - Comprehensive installation script Components: - Skills: always-use-superpowers, ralph, brainstorming, ui-ux-pro-max, etc. - Agents: 100+ agents across engineering, marketing, product, etc. - Hooks: session-start-superpowers, qwen-consult, ralph-auto-trigger - Commands: /brainstorm, /write-plan, /execute-plan - MCP Servers: zai-mcp-server, web-search-prime, web-reader, zread - Binaries: ralphloop wrapper Installation: ./supercharge.sh
8.1 KiB
WordPress Content Encoding Fix - Complete Guide
Overview
This document explains the encoding issue that was affecting WordPress post ID 112 (Superpowers Plugin article) and provides a permanent solution for preventing similar issues in the future.
The Problem
Symptoms
- Literal
\nescape sequences appearing as visible text on the webpage - Content displaying incorrectly across the entire article
- HTML structure broken due to escaped characters
- Poor user experience and unprofessional appearance
Root Cause
The issue was caused by PHP-level string escaping that occurred when content was being inserted into the database. Here's what was happening:
- Content with proper newlines was being escaped by PHP functions
- Actual newline characters (
\n) were converted to literal string"\\n" - These literal strings were stored in the database
- When rendered, the browser displayed the literal
\ninstead of creating line breaks
Why This Kept Happening
- Using string concatenation or PHP variables to build SQL queries
- Functions like
addslashes()ormysqli_real_escape_string()escaping newlines - Not using binary-safe methods for content insertion
- Lack of validation after database updates
The Solution
Permanent Fix Method
Step 1: Create Clean HTML File
Create the HTML content with actual newlines, not escape sequences:
cat > /tmp/cleaned_content.html << 'EOF'
<!-- HERO SECTION -->
<section class="hero-section">
<div class="hero-content">
<h1>Title Here</h1>
</div>
</section>
<!-- NEXT SECTION -->
<div class="content">
<p>Content here...</p>
</div>
EOF
Critical: Use actual newlines in the file, NOT \n escape sequences.
Step 2: Use MySQL LOAD_FILE() Function
Update the WordPress database using binary-safe file loading:
sudo mysql wordpress -e "UPDATE wp_posts SET post_content = LOAD_FILE('/tmp/cleaned_content.html') WHERE ID = 112;"
Why This Works:
LOAD_FILE()reads the file as binary data- Preserves all characters exactly as they appear in the file
- Bypasses PHP escaping entirely
- Maintains proper UTF-8MB encoding
Step 3: Verify the Update
Always verify the update was successful:
sudo mysql wordpress --skip-column-names --raw \
-e "SELECT post_content FROM wp_posts WHERE ID = 112;" \
> /tmp/verify.html
# Check for literal escape sequences (should return 0)
grep -c '\\n' /tmp/verify.html
# View the content to verify
head -50 /tmp/verify.html
Prevention Tools
Automated Safe Update Script
Location: /home/uroma/.claude/skills/ui-ux-pro-max/scripts/wordpress_safe_update.sh
Usage:
./wordpress_safe_update.sh <post_id> <html_file_path>
Features:
- Encoding Validation: Checks file is UTF-8 encoded
- Escape Sequence Detection: Scans for literal
\nsequences - Automatic Backup: Creates timestamped backups before updates
- Update Verification: Confirms successful content insertion
- Error Handling: Provides clear error messages if something fails
Example:
./wordpress_safe_update.sh 112 /tmp/new_article_content.html
Automated Test Suite
Location: /tmp/encoding_test.sh
Usage:
/tmp/encoding_test.sh
Tests Performed:
- Literal escape sequence detection
- HTML structure verification
- Article section presence check
- CSS class preservation validation
- Promo text verification
- Discount code presence check
Database Configuration
Verified Settings
-- Database charset
SHOW VARIABLES LIKE 'character_set_database';
-- Result: utf8mb4
-- Table charset
SHOW CREATE TABLE wp_posts;
-- Should show: CHARSET=utf8mb4
-- Post content field
DESCRIBE wp_posts post_content;
-- Type: longtext, Collation: utf8mb4_unicode_520_ci
Why utf8mb4 Matters
- Supports full Unicode including emojis
- Handles 4-byte characters
- Prevents character corruption
- Industry standard for WordPress
Technical Details
Before vs After Comparison
| Aspect | Before | After |
|---|---|---|
| Content Length | 51,111 chars | 53,256 chars |
| Newline Format | Literal \n strings |
Actual newline chars |
| Storage Method | PHP-escaped strings | Binary data |
| Display | Visible \n text |
Proper HTML rendering |
| Encoding | Corrupted | Proper UTF-8MB |
Content Structure Verified
8 Article Sections:
- HERO SECTION - Plugin Spotlight header
- INTRO SECTION - Overview of Superpowers
- KEY FEATURES - 4 feature cards
- WHY SUPERPOWERS - Benefits grid
- INSTALLATION - Two installation methods
- PRICING COMPARISON - Model comparison table
- PROMO SECTION - Z.AI promotional content
- FINAL CTA - Call to action
CSS Classes Preserved:
- All 50+ CSS classes intact
- CSS variables referenced correctly
- Inline styles preserved
- Responsive design maintained
Best Practices for Future Updates
DO ✅
- Always use LOAD_FILE() for HTML content updates
- Create HTML files with actual newlines (not escape sequences)
- Verify encoding before database insertion
- Test content after updates
- Use the safe update script for all content changes
- Create backups before any update
- Check for escape sequences in source files
DON'T ❌
- Don't use PHP string concatenation for content building
- Don't use addslashes() on HTML content
- Don't escape newlines in source files
- Don't skip verification after updates
- Don't assume encoding is correct without checking
Troubleshooting
If Escape Sequences Appear Again
Diagnosis:
# Export content and check
sudo mysql wordpress --skip-column-names --raw \
-e "SELECT post_content FROM wp_posts WHERE ID = <post_id>;" \
> /tmp/check.html
# Search for escape sequences
grep '\\n' /tmp/check.html
Solution:
- Create cleaned HTML file with proper newlines
- Use LOAD_FILE() to update
- Verify with test suite
If Content Appears Corrupted
Check Encoding:
file -b --mime-encoding /tmp/your_content.html
# Should return: utf-8
Fix Encoding:
iconv -f UTF-8 -t UTF-8 input.html > output.html
If Update Fails
Check File Permissions:
ls -l /tmp/your_content.html
# Should be readable by MySQL user
Check File Path:
# Use absolute path
sudo mysql wordpress -e "SELECT LOAD_FILE('/tmp/content.html');"
Verification Commands
Quick Verification
# Export and check content
sudo mysql wordpress --skip-column-names --raw \
-e "SELECT post_content FROM wp_posts WHERE ID = 112;" \
| head -20
Full Verification
# Run test suite
/tmp/encoding_test.sh
Manual Verification
# Check for escape sequences
sudo mysql wordpress --skip-column-names --raw \
-e "SELECT post_content FROM wp_posts WHERE ID = 112;" \
| grep -c '\\n'
# Should return 0
Conclusion
This encoding issue has been permanently fixed by:
- Using MySQL's LOAD_FILE() function for binary-safe insertion
- Creating automated prevention tools
- Implementing verification procedures
- Documenting best practices
The fix will remain permanent if you:
- Use the provided
wordpress_safe_update.shscript - Create HTML files with actual newlines
- Always verify updates with the test suite
- Follow the best practices outlined above
Files Reference
- Cleaned Content:
/tmp/superpowers_article_cleaned.html - Safe Update Script:
/home/uroma/.claude/skills/ui-ux-pro-max/scripts/wordpress_safe_update.sh - Test Suite:
/tmp/encoding_test.sh - Verification Export:
/tmp/verify_content.html - Technical Report:
/tmp/superpowers_encoding_fix_report.md - Summary Report:
/tmp/superpowers_fix_summary.md
Last Updated: 2026-01-18 WordPress Post ID: 112 Status: ✅ FIXED - VERIFIED Database: wordpress (utf8mb4)