WordPress Media Copy Functionality
This document describes the mechanisms for copying images and slideshows between WordPress instances in the Aleteia network. The system automatically synchronizes media assets across multiple locales (en, es, fr, it, pt, pl, si, ar) to ensure content consistency.
Architecture Overview
The media copy system consists of two primary entry points (webhooks) that trigger background jobs to process and replicate media across WordPress sites.
Key Components
| Component | Type | Purpose |
|---|---|---|
ScrapeController#do | Webhook | Handles post creation/update events |
WpMediaController#media_added | Webhook | Handles new media uploads |
SchedulePostAttachmentJob | Job | Processes post attachments |
ProcessWordpressPictureJob | Job | Retrieves and stores attachment info |
CopyWordpressPictureJob | Job | Copies master pictures to other sites |
SaveMasterPictureMetadataJob | Job | Saves supplier and author metadata |
WordpressPicture | Model | Stores picture information and relationships |
WordpressAuthor | Model | Stores author information |
WordpressAPI | Service | Interfaces with WordPress XML-RPC and REST APIs |
Webhooks
ScrapeController#do
This webhook is called when a post is created or updated in any WordPress instance. It triggers multiple background jobs including media attachment processing.
Endpoint: POST /scrape
Parameters:
post_url- The URL of the created/updated postID- The WordPress post ID
Behavior:
- Validates the incoming URL (skips staging/frontity URLs)
- Enqueues
FacebookScrapeJobfor social media scraping - Enqueues
SchedulePostAttachmentJobfor attachment processing - Schedules Algolia indexing via
AlgoliaIndexJob
WpMediaController#media_added
This webhook is called when new media is uploaded to WordPress. It uses JWT authentication for security.
Endpoint: POST /wp_media/media_added
Authentication: JWT Bearer token
JWT Payload:
attachment_id- The WordPress attachment IDlocale- The site locale
Behavior:
- Validates JWT token
- Enqueues
ProcessWordpressPictureJobwith immediate copy flag
Background Jobs
ProcessWordpressPictureJob
Retrieves attachment information from WordPress and creates or updates the local WordpressPicture record.
Queue: wordpress_pictures
Parameters:
id- WordPress attachment IDlocale- Site localecheck_copy_flag- Whether to check for immediate copy flag (default: false)
Behavior:
- If
check_copy_flagis true and the attachment doesn't have the "copy now" flag, reschedules for 1 hour later - Retrieves attachment data and custom fields from WordPress API
- Creates or updates
WordpressPicturerecord viafrom_remote - Schedules
SaveMasterPictureMetadataJobfor metadata processing
CopyWordpressPictureJob
Copies a master picture to other WordPress sites. Only master pictures (those without a parent) can be copied.
Queue: wordpress_pictures
Parameters:
picture- TheWordpressPictureinstance to copylocale- Target locale (optional; if nil, copies to all active sites)
Behavior:
- Validates the picture is a master picture
- If no locale specified, schedules individual jobs for each active site
- If locale specified, uploads the image to the target site via WordPress API
- Creates child
WordpressPicturerecord linked to the master
SchedulePostAttachmentJob
Processes post attachments when posts are created or updated.
Queue: default
Parameters:
post_url- The WordPress post URLpost_id- The WordPress post ID
Behavior:
- Extracts locale from URL
- Retrieves post data from WordPress API
- If post has a thumbnail attachment, checks local database
- Schedules
SaveMasterPictureMetadataJobif picture exists
SaveMasterPictureMetadataJob
Retrieves and saves metadata for pictures including supplier information and author data.
Queue: wordpress_pictures
Parameters:
picture_or_start_id- Either aWordpressPictureinstance or a starting ID for batch processing
Behavior:
- For individual pictures: fetches supplier, author, and publication date from WordPress
- For batch processing: iterates through pictures and schedules individual jobs
Data Models
WordpressPicture
Stores information about WordPress media attachments and their relationships across locales.
Key Attributes:
attachment_id- WordPress attachment IDlocale- Site localefile_hash- SHA256 hash of the image contenturl- Image URLtitle,caption,description- Image metadatasupplier- Photo supplier (enum)published- Whether the image is attached to a published postpublished_at- Publication timestamp
Relationships:
parent- Master picture (for copied images)children- Copied pictures in other localeswordpress_author- The author who uploaded the image
Scopes:
master- Pictures without a parent (original uploads)derivatives- Pictures that are copies of master picturespublished- Pictures attached to published postsphoto_team- Pictures uploaded by the photo team
WordpressAuthor
Stores information about WordPress users who upload media.
Key Attributes:
user_id- WordPress user IDlocale- Site localeuser_login- WordPress usernamedisplay_name- Display namephoto_team- Whether the user is part of the photo team
Complete Picture Copy Flow
The following diagram shows the complete flow from a new image upload to its replication across all sites:
Configuration
Environment Variables
| Variable | Description |
|---|---|
WORDPRESS_USERNAME | WordPress API username |
WORDPRESS_PASSWORD | WordPress API password |
WORDPRESS_USE_SSL | Enable SSL for WordPress connections |
Active Sites
The system copies media to all active sites defined in WordpressAPI::ACTIVE_SITES:
ACTIVE_SITES = {
en: 'aleteia.org',
es: 'es.aleteia.org',
fr: 'fr.aleteia.org',
pl: 'pl.aleteia.org',
pt: 'pt.aleteia.org',
si: 'si.aleteia.org',
}
Note: Some sites (ar, it) may be disabled from active synchronization.
Custom Fields
The system uses several WordPress custom fields to track media:
| Field | Constant | Purpose |
|---|---|---|
aleteia_media_copyright | CF_COPYRIGHT | Copyright notice |
aleteia_media_copyright_link | CF_COPYRIGHT_LINK | Link to copyright source |
aleteia_media_source | CF_IMAGE_SUPPLIER | Photo supplier |
aleteia_media_image_source | CF_IMAGE_SOURCE | Tracks copied image origin |
aleteia_media_original_uploader | CF_IMAGE_UPLOADER | Original uploader |
aleteia_media_copy_now | CF_COPY_NOW | Flag for immediate copy |
_wp_attachment_image_alt | CF_ALT_TEXT | Alternative text |
Error Handling
The jobs implement various error handling mechanisms:
- RestClient::NotFound: Picture deleted in WordPress - logged and skipped
- XMLRPC::FaultException (404): Attachment not found - skipped
- RestClient::NotAcceptable: VIP considers file dangerous - skipped
- Duplicate hash: If WordPress modifies the uploaded file hash, a random hash is assigned
Duplicate Detection
The system uses SHA256 file hashes to detect duplicate images:
- Before copying, checks if a picture with the same
file_hashexists in the target locale - If found, skips the copy operation
- If WordPress changes the hash during upload, assigns a random hash to allow storage