How kreatifsayfa/wordpress-twitter-auto-shared works
Project type and purpose
• This is a WordPress plugin (“TurkNews Twitter Auto”) whose job is to detect new posts on a WordPress site and automatically share them on Twitter with customizable templates, hashtags and media attachments.
File structure
• Top‐level plugin file: turknews-twitter-auto.php (bootstrap & hook registrations)
• includes/ directory—each file is a class representing a distinct feature or subsystem:
• class-twitter-api.php (abstracts Twitter REST calls)
• class-tweet-retweeter.php (orchestrates tweet creation & dispatch)
• class-scheduler.php (uses WP Cron to schedule posting)
• class-error-manager.php (central error logging & retry logic)
• class-analytics.php (collects & reports usage metrics)
• class-ab-testing.php (A/B tests of tweet templates)
• class-content-optimizer.php (applies template tokens, category hashtags, image inclusion)
• class-engagement.php (handles replies/likes tracking)
• class-multi-account.php (supports multiple Twitter credentials)
• class-smart-features.php (e.g. link shortening, smart scheduling)
Extract architectural hints from README
• Hooks into WordPress publish‐post event (new post → automatic tweet)
• Settings stored in WP admin (encrypted tokens in DB)
• SSL‐secured API calls, rate‐limiting checks
• Debug mode, admin UI
Main components
a. WordPress Core (event dispatcher, cron engine, options & metadata database)
b. Plugin Layer, subdivided into:
• Admin/UI Module (Settings page, input of auth & CSRF tokens, toggle switches)
• Scheduler Module (class-scheduler.php; WP Cron hooks)
• Tweet Orchestration Layer:
– Content Optimizer (templates, hashtags, featured image)
– A/B Testing Engine
– Multi-Account Selector
– Smart Features (link shortener, scheduling heuristics)
• Twitter API Adapter (REST client over SSL)
• Error Manager & Analytics (logging, retry, metrics)
c. External Service: Twitter REST API
Relationships & data flow
1. Admin user sets credentials & templates → stored in WP options table
2. A new post is published → WordPress “publish_post” hook triggers Scheduler
3. Scheduler invokes Tweet Orchestration Layer
4. Content Optimizer + A/B Testing + Multi-Account + Smart Features prepare the final tweet payload
5. Twitter API Adapter sends request over HTTPS → receives response
6. Error Manager handles failures, enqueues retries, logs to Analytics
7. Analytics Engine records success/failure, engagement data
8. (Optional) Engagement Module polls Twitter API for metrics on posted tweets
Architectural patterns & design principles
• Hook‐based plugin bootstrap (inversion of control via WP hooks)
• Modular single‐responsibility classes (each class does one thing)
• Layered approach: UI → scheduling → business logic → external API
• Dependency injection (classes depend on an HTTP client or WP database abstraction)
• Retry/circuit‐breaker pattern in Error Manager
• Cron‐driven asynchronous processing
Elements
• WordPress Core (event dispatcher, cron, DB)
• Plugin bootstrap file (initial hook registrations)
• Admin Settings UI
• Scheduler module
• Business logic components (optimizer, ab-testing, multi-account, smart-features)
• Twitter API adapter
• Error Manager & Analytics
• WP database (options/encrypted tokens)
• Twitter API (external)
Detail vs. over‐segmentation
• How settings flow into modules at runtime
• Full end‐to‐end flow from “new post published” to “tweet delivered and logged”
• Don’t omit retry logic or analytics, even if they run in the background