RSS Parsing Details – How Dynamic Post Handles RSS Feeds (v7.5)
Here is a complete, step-by-step explanation of exactly how the plugin parses RSS feeds inside the process_rss_feeds() method.
1. High-Level Overview
- The RSS parser runs whenever you click “Refresh Counts & RSS Now” or during the monthly auto-pull on the 2nd of the month.
- It processes up to 5 RSS feeds you configured in Blog Settings.
- Only current-month articles are imported (no old archive spam).
- Every feed is processed independently with its own settings (enable/disable, frequency, limit, post status, image handling, category mapping).
2. Step-by-Step Parsing Process
- Safety Lock (Prevents Overlapping Runs)
- Checks for a transient called dp_rss_processing_lock.
- If it exists → exits immediately (prevents double-processing).
- If not → sets the lock for 5 minutes (300 seconds).
- Load All RSS Settings
- Reads the 8 option arrays:
- dynamic_post_rss_feeds
- dynamic_post_rss_enabled
- dynamic_post_rss_frequency
- dynamic_post_rss_limit
- dynamic_post_rss_post_status
- dynamic_post_rss_save_to_media
- dynamic_post_rss_category_map
- dynamic_post_rss_last_import
- Loop Through Each Feed (1 to 5)
- Skips empty URLs and disabled feeds ($enabled !== 1).
- Fetch the RSS Feed
- Uses wp_remote_get($feed_url, array('timeout' => 15)).
- If error → calls circuit breaker and skips to next feed.
- Parse the XML
- Converts the response body with simplexml_load_string($body).
- Loops through every <item> in $xml->channel->item.
- Date Filtering (Current-Month Only)
- Parses the item’s <pubDate>.
- Skips any article not from the current month and year.
- For Weekly feeds: also skips articles older than 7 days (time() - $pubDate > 604800).
- Image Extraction
- Looks inside the <description> for the first <img> tag.
- Uses regex: preg_match('/<img[^>]+src=["\']([^"\']+)["\']/', $description, $matches).
- Stores the image URL (or empty string if none found).
- Respect Per-Feed Limit
- Counts processed items for this feed.
- Stops at the user-selected limit (default 5) with if ($items_processed >= $max_articles) break;.
- Category Mapping
- If user chose “Auto”: parses domain name (e.g. bloomberg.com → category “Bloomberg”).
- If user selected a category: uses that exact slug.
- Dynamic Post categories are excluded from the dropdown (per your spec).
- Create or Update Post
- Builds $post_data array with title, content, status, author, category, and date.
- Checks for duplicate by title + date using get_posts().
- If exists → wp_update_post().
- If new → wp_insert_post().
- Image Handling
- If “Save to Media Library” is ON → calls generate_featured_image_by_url() and sets _thumbnail_id.
- If OFF → hot-links with _thumbnail_ext_url meta.
- Update Last Import Timestamp
- Records for that specific feed: “Apr 11, 2026 12:39 AM (3 new posts)”.
- Cleanup
- Deletes the processing lock.
- Updates global dynamic_post_last_import timestamp.
3. Key Technical Details
- HTTP Request: wp_remote_get() with 15-second timeout (native WordPress, better than curl).
- XML Parser: simplexml_load_string() – fast and simple.
- Date Handling: Uses strtotime() + date('M') and date('Y') for current-month filter.
- Duplicate Protection: Title + date check prevents duplicate posts.
- Circuit Breaker: Any fetch failure calls handle_api_failure() (same as main API).
- No Endless Loops: Lock + per-feed limit + current-month filter ensure safety.
4. How RSS Integrates with the Rest of the Plugin
- Runs alongside (not instead of) the Dynamicontent.net API.
- RSS posts are normal WordPress posts → full shortcode support, view counters, JSON-LD schema, Yoast hooks.
- No disclaimer is added to RSS posts (only API articles get it).
- Category counts (API | Blog | Reads Now | Reads All) include RSS posts.
- All safety features (circuit breaker, transients) are shared.
Article ID: 131, Created: 4/10/2026 at 11:40 PM, Modified: 4/10/2026 at 11:40 PM