Migrating from Custom Code
Replace custom PHP/API code with API Mapper
Migrating from Custom Code
If you've been using custom PHP code to fetch API data, API Mapper can simplify your workflow significantly. This guide helps you migrate.
Why Migrate?
| Custom Code | API Mapper |
|---|---|
| Requires PHP knowledge | No coding needed |
| Manual error handling | Built-in error handling |
| No caching (or DIY) | Built-in caching |
| Updates require developer | Update via UI |
| Hard to debug | Visual testing tools |
Common Migration Scenarios
Scenario 1: Custom PHP in Child Theme
Before (functions.php):
After (API Mapper):
- Create a new connection
- Set URL:
https://api.openweathermap.org/data/2.5/weather - Add query parameters:
q=London,appid=YOUR_KEY - Map fields:
main.temp,weather[0].description - Done! No code needed.
Scenario 2: Shortcode-Based API Display
Before:
After (API Mapper + YOOtheme):
- Create API connection in API Mapper
- In YOOtheme, add a Grid element
- Set dynamic content to your API connection
- Map fields to grid items
- Style with YOOtheme's visual editor
Scenario 3: AJAX-Based Data Loading
Before (JavaScript + PHP endpoint):
After (API Mapper):
- Data loads server-side with the page
- No separate AJAX calls needed
- Cached automatically
- Works with YOOtheme's dynamic content system
Step-by-Step Migration
Step 1: Identify Your API Calls
Find all places where you're fetching external data:
wp_remote_get()/wp_remote_post()file_get_contents()curl_exec()- Guzzle HTTP client
- Any third-party API libraries
Step 2: Document Current Configuration
For each API call, note:
- Base URL
- Endpoint path
- Query parameters
- Headers
- Authentication method
- Which fields you use
Step 3: Create API Mapper Connections
For each documented API call:
WordPress
- Go to Settings → API Mapper
- Click Add Connection
- Enter your documented settings
- Map the fields you identified
- Test the connection
Step 4: Update YOOtheme Layouts
Replace custom shortcodes/widgets with YOOtheme elements:
- Edit the page in YOOtheme
- Remove the shortcode/custom element
- Add a Grid, List, or other element
- Enable dynamic content
- Select your API Mapper connection
- Map fields to element properties
Step 5: Test Thoroughly
Before removing old code:
- Verify all data displays correctly
- Check responsive layouts
- Test error scenarios (what if API is down?)
- Verify caching works
- Test on staging first
Step 6: Clean Up Old Code
Once everything works:
- Remove old PHP functions
- Remove old shortcodes
- Remove unused JavaScript
- Keep backups just in case
Handling Edge Cases
Dynamic Parameters
Old code might have:
API Mapper solution:
- Create separate connections per category
- Or wait for dynamic parameters feature (coming soon)
Complex Data Transformations
Old code might have:
API Mapper solution:
- Use JMESPath (Pro/Developer) for filtering and transformation
- Or handle display logic in YOOtheme templates
Multi-API Combinations
Old code might combine multiple APIs:
API Mapper solution:
- Create separate connections for each API
- Display in separate YOOtheme sections
- Or use custom code for complex merging (hybrid approach)
Hybrid Approach
You don't have to migrate everything at once. You can:
- Start with simpler API integrations
- Keep complex custom code temporarily
- Migrate piece by piece
- Use API Mapper for new projects
Need Help?
Was this page helpful?