VOOZH about

URL: https://deepwiki.com/Automattic/BuddyPress-VIP-Go/3-media-operations

⇱ Media Operations | Automattic/BuddyPress-VIP-Go | DeepWiki


Loading...
Menu

Media Operations

Purpose and Scope

This document provides an overview of how the BuddyPress VIP Go plugin handles media operations for avatars, cover images, and videos. It explains the core principles that differentiate this plugin's approach from standard BuddyPress media handling, introduces the major media types supported, and maps the high-level workflows to specific code functions.

For detailed information about specific media operations, see:

For information about how the plugin integrates with VIP's file hosting infrastructure, see VIP File Hosting Service Integration. For metadata storage details, see Metadata Storage Architecture.

Core Principles

The plugin implements three fundamental principles that distinguish it from standard BuddyPress media handling:

Metadata-Driven Storage

Instead of storing multiple pre-generated image sizes on the filesystem, the plugin stores only the original uploaded file in VIP FHS and saves transformation metadata in the WordPress database. For avatars, this includes crop coordinates (crop_x, crop_y, crop_w, crop_h) and UI width constraints. For cover images, only the URL is stored since they use a fixed crop pattern.

Dynamic Transformations

Image transformations (cropping, resizing) are performed on-demand by VIP's file hosting service via Photon-like query parameters. When BuddyPress requests an avatar at a specific size, the plugin constructs a URL with parameters like ?w=150&crop=x,y,w,h&resize=150,150&strip=info that instruct VIP FHS to transform the image dynamically. This eliminates storage overhead and leverages VIP's CDN for caching.

Filesystem Abstraction

The plugin completely bypasses BuddyPress's filesystem scanning operations by intercepting hooks early in the execution flow. It returns empty strings for directory paths files.php16 and provides URLs directly from metadata, preventing opendir() and flock() calls that would fail on VIP's distributed filesystem.

Sources: files.php1-967 README.md24-42

Media Types Overview

The plugin handles four distinct media types, each with different processing requirements:

Media TypeMetadata Key(s)Storage LocationTransformation MethodSpecial Handling
User Avatarsvipbp-avatarsUser MetaDynamic crop + resizeSupports webcam capture
Group Avatarsvipbp-group-avatars
vipbp-default-group-avatar
Group Meta / OptionsDynamic crop + resizeDefault avatar uses options table
User Cover Imagesvipbp-user-coverUser MetaFixed crop patternMiddle 25% vertical crop
Group Cover Imagesvipbp-group-coverGroup MetaFixed crop patternMiddle 25% vertical crop
VideosN/A (BuddyBoss)VIP FHSNoneChunked upload to local temp

Avatar metadata structure:

array(
 'url' => 'https://example.com/uploads/...',
 'crop_x' => 0,
 'crop_y' => 0,
 'crop_w' => 150,
 'crop_h' => 150,
 'ui_width' => 500
)

Cover image metadata structure:

array(
 'url' => 'https://example.com/uploads/...'
)

Sources: files.php32-42 README.md30-36

Hook Integration Architecture

The plugin registers filters on BuddyPress hooks to intercept default media operations. These filters are registered in two phases: early filters (before bp_init priority 8) prevent filesystem operations, while bp_init filters override upload, crop, and deletion handlers.


Sources: files.php11-52

Storage and Retrieval Flow

This diagram illustrates the complete lifecycle of media from upload through storage to retrieval and display, showing how each phase maps to specific functions.


Sources: files.php336-464 files.php679-738 files.php70-256

Function Reference by Operation

This table maps media operations to the specific functions that handle them, providing a quick reference for understanding code flow.

OperationUser AvatarsGroup AvatarsUser CoversGroup CoversVideos
Uploadvipbp_handle_avatar_upload
files.php336-464
vipbp_handle_avatar_upload
files.php336-464
vip_handle_cover_image_upload
files.php562-649
vip_handle_cover_image_upload
files.php562-649
vipbp_filter_chunked_upload_temp_dir
files.php923-925
Webcam Capturevipbp_handle_avatar_capture
files.php476-545
N/AN/AN/AN/A
Cropvipbp_handle_avatar_crop
files.php679-738
vipbp_handle_avatar_crop
files.php679-738
N/A (fixed pattern)N/A (fixed pattern)N/A
URL Generationvipbp_filter_user_avatar_urls
files.php70-89
vipbp_filter_avatar_urls
files.php148-256
vipbp_filter_group_avatar_urls
files.php106-136
vipbp_filter_avatar_urls
files.php148-256
vipbp_filter_get_cover_image
files.php277-324
vipbp_filter_get_cover_image
files.php277-324
N/A
Deletionvipbp_delete_existing_avatar
files.php761-836
vipbp_delete_existing_avatar
files.php761-836
vipbp_delete_cover_image
files.php847-875
vipbp_delete_cover_image
files.php847-875
vipbp_override_remove_temp_directory
files.php886-897
Cache ManagementN/AN/AN/AN/Avipbp_flush_cache_after_video_move
files.php905-907

Sources: files.php23-52

Metadata Keys and Storage Locations

All metadata is stored on the root blog in multisite installations via switch_to_blog(bp_get_root_blog_id()) files.php74-75 This centralization simplifies metadata management across network sites.

Avatar Metadata Keys

vipbp-avatars (User Meta)

  • Purpose: Stores user avatar metadata including original URL and crop coordinates
  • Fields: url, crop_x, crop_y, crop_w, crop_h, ui_width
  • Retrieved in: vipbp_filter_user_avatar_urls() files.php81
  • Updated in: vipbp_handle_avatar_upload() files.php402-413 vipbp_handle_avatar_capture() files.php518-529
  • Deleted in: vipbp_delete_existing_avatar() files.php811

vipbp-group-avatars (Group Meta)

  • Purpose: Stores group avatar metadata including original URL and crop coordinates
  • Fields: url, crop_x, crop_y, crop_w, crop_h, ui_width
  • Retrieved in: vipbp_filter_group_avatar_urls() files.php120
  • Updated in: vipbp_handle_avatar_upload() files.php429-433
  • Deleted in: vipbp_delete_existing_avatar() files.php819-820

vipbp-default-group-avatar (BP Option)

  • Purpose: Stores default group avatar for item_id=0 (stored in options instead of group meta since no group exists)
  • Fields: Same as vipbp-group-avatars
  • Retrieved in: vipbp_filter_group_avatar_urls() files.php117 vipbp_filter_default_group_avatar_option() files.php942
  • Updated in: vipbp_handle_avatar_upload() files.php427
  • Deleted in: vipbp_delete_existing_avatar() files.php816-817

Cover Image Metadata Keys

vipbp-user-cover (User Meta)

  • Purpose: Stores user cover image URL (no crop data; uses fixed pattern)
  • Fields: url
  • Retrieved in: vipbp_filter_get_cover_image() files.php289
  • Updated in: vip_handle_cover_image_upload() files.php611-617
  • Deleted in: vipbp_delete_cover_image() files.php857-858

vipbp-group-cover (Group Meta)

  • Purpose: Stores group cover image URL (no crop data; uses fixed pattern)
  • Fields: url
  • Retrieved in: vipbp_filter_get_cover_image() files.php294
  • Updated in: vip_handle_cover_image_upload() files.php619-626
  • Deleted in: vipbp_delete_cover_image() files.php861-862

Sources: files.php70-875 README.md30-36

Special Cases and Workarounds

Default Group Avatar Handling

When item_id=0 is used for the default group avatar, the plugin stores metadata in the vipbp-default-group-avatar option instead of group meta (since no group exists). This requires special logic in multiple functions:

BuddyBoss opendir() Prevention

BuddyBoss's bb_get_default_custom_upload_group_avatar() function calls bb_get_default_custom_avatar(), which uses opendir() to scan the filesystem. This fails on VIP Go. The plugin prevents this by:

  1. Filtering option_bp-default-custom-group-avatar to return empty when a VIP avatar exists files.php941-946
  2. Filtering bb_get_default_custom_upload_group_avatar to return the stored URL files.php958-965

This two-filter approach bypasses the problematic BuddyBoss code path while still providing the correct avatar URL.

Chunked Video Upload Workaround

BuddyBoss's chunked video upload mechanism requires flock() for file locking during chunk assembly. VIP FHS doesn't support flock(), so the plugin redirects chunked uploads to the local temp directory where file locking works files.php923-925 After assembly completes, BuddyBoss moves the final file to VIP FHS using standard upload mechanisms.

Sources: files.php20-21 files.php115-127 files.php426-427 files.php710-728 files.php815-817 files.php923-925 files.php941-965

Integration with BuddyPress Core

The plugin's filters are designed to short-circuit BuddyPress's default media handling by returning non-null values on pre_ filters. When a pre_ filter returns a non-null value, BuddyPress skips its default processing logic. The plugin's functions return false (for operations that succeeded) or arrays (for cover image uploads) to indicate the operation was handled.


Sources: files.php336-464 files.php679-738 files.php761-836