Migration & Legacy Interview Questions

Refactoring, Data Migration, and Handling Technical Debt.

Real-world jobs often involve inheriting a mess. These questions test the ability to clean up legacy code and migrate data safely.

1. How do you approach refactoring a legacy "Spaghetti Code" theme?

Answer:

  1. Audit: Understand what the code does. Use tools like PHPCS.
  2. Environment: Set up a local dev environment with debug logging enabled.
  3. Incremental: Don't rewrite everything at once. Pick one template or feature.
  4. Extract Logic: Move logic out of template files (`header.php`, `page.php`) into classes or services.
  5. Templating: Introduce a template engine (like Timber) or at least `get_template_part` to break up huge files.

2. How do you migrate 10,000 posts from an old CMS to WordPress?

Answer:

  • WP-CLI: The most robust way. Write a script that parses the source data (CSV/JSON/XML) and uses `wp_insert_post()` to create content.
  • WP All Import: A powerful plugin for CSV/XML imports if coding a custom script isn't feasible.
  • Direct SQL: Risky. Bypasses hooks and validation. Only for experts who know the schema perfectly.

3. How do you handle URL redirects during a migration?

Answer: Preserving SEO is critical.

  • Map: Create a mapping of Old URL -> New URL.
  • Implementation:
    • Nginx/Apache: Fastest. Handle redirects at the server level.
    • Plugin: "Redirection" or "Safe Redirect Manager" for manageable lists.
  • Regex: Use pattern matching for bulk redirects (e.g., `/blog/2023/*` -> `/news/*`).

4. What is "Search and Replace" in the context of WordPress migration?

Answer: WordPress stores serialized data in the database (arrays/objects converted to strings). Standard text search/replace breaks serialization (because string lengths change).

Solution: Always use `wp search-replace` (WP-CLI) or a serialization-aware tool (like "Better Search Replace" plugin) when changing domains (e.g., `staging.site.com` -> `site.com`).

5. How do you debug a "White Screen of Death" on a legacy site?

Answer:

  1. Enable Debugging: Set `WP_DEBUG`, `WP_DEBUG_LOG`, `WP_DEBUG_DISPLAY` to true in `wp-config.php`.
  2. Check Logs: Look at `wp-content/debug.log` or server error logs.
  3. Deactivate Plugins: Rename `plugins` folder to `plugins_old` to disable all plugins and see if the site loads.
  4. Switch Theme: Switch to a default theme (Twenty Twenty-Four).