VOOZH about

URL: https://deepwiki.com/Automattic/BuddyPress-VIP-Go/2.3-metadata-storage-architecture

⇱ Metadata Storage Architecture | Automattic/BuddyPress-VIP-Go | DeepWiki


Loading...
Menu

Metadata Storage Architecture

Purpose and Scope

This document describes how BuddyPress VIP Go stores media metadata in the WordPress database instead of relying on filesystem directory structures. It covers the metadata keys used, data structures stored, storage locations (user meta, group meta, options), and multisite blog switching logic.

For information about how files are uploaded and stored in VIP File Hosting Service, see VIP File Hosting Service Integration. For information about how this metadata is used to generate dynamic image URLs, see Dynamic Image Processing and URL Generation.

Core Design Principle

The plugin implements a metadata-driven transformation model. Unlike standard WordPress media handling, which pre-generates multiple image sizes and stores them as files, this plugin stores:

  1. One original file in VIP File Hosting Service (FHS)
  2. Transformation metadata in the WordPress database (crop coordinates, UI width)
  3. Dynamic URLs with query parameters for on-demand transformations

This approach eliminates the need for BuddyPress to scan filesystem directories, which is incompatible with VIP Go's distributed file system.

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

Metadata Keys Overview

The plugin uses five distinct metadata keys to store media information:

Metadata KeyStorage LocationObject TypeMedia TypeData Stored
vipbp-avatarsUser MetaUserAvatarurl, crop_x, crop_y, crop_w, crop_h, ui_width
vipbp-user-coverUser MetaUserCover Imageurl only
vipbp-group-avatarsGroup MetaGroupAvatarurl, crop_x, crop_y, crop_w, crop_h, ui_width
vipbp-group-coverGroup MetaGroupCover Imageurl only
vipbp-default-group-avatarOptions TableGlobalDefault Avatarurl, crop_x, crop_y, crop_w, crop_h, ui_width

Sources: files.php81-82 files.php117-120 files.php289-295 files.php402-434 files.php518-529 files.php610-627 README.md32-36

Metadata Storage by Media Type

Avatar Metadata Structure

Avatars store comprehensive metadata because users can crop them to different coordinates:


Field Purposes:

  • url - Points to original uploaded file in VIP FHS
  • crop_x, crop_y, crop_w, crop_h - User-selected crop coordinates from cropper UI
  • ui_width - Width of the upload interface when image was uploaded (prevents upscaling mobile uploads)

Initial Values on Upload: files.php402-413 files.php416-434 files.php518-529

  • Crop values default to full avatar dimensions: bp_core_avatar_full_width() and bp_core_avatar_full_height()
  • Crop position defaults to (0, 0)
  • ui_width set to $crop_image_width (clamped to available UI width)

Updated Values on Crop: files.php679-738

  • Only crop coordinates updated: crop_x, crop_y, crop_w, crop_h
  • URL and ui_width remain unchanged

Sources: files.php402-434 files.php518-529 files.php679-738 files.php221-244

Cover Image Metadata Structure

Cover images use minimal metadata because they have a fixed crop pattern:


Why Only URL?

Cover images always crop the middle 25% of the image vertically (files.php307), so crop coordinates don't need to be stored. The cropping is applied dynamically via query parameters when the image is retrieved.

Sources: files.php277-323 files.php562-648 files.php610-627 README.md33-35

Storage Locations and Functions

User Metadata Storage


User Avatar Functions:

User Cover Functions:

Sources: files.php70-89 files.php336-464 files.php476-545 files.php679-738 files.php761-836 files.php847-875

Group Metadata Storage


Group Avatar Functions:

Group Cover Functions:

Sources: files.php106-136 files.php415-435 files.php619-626 files.php708-731 files.php813-821 files.php860-862

Default Group Avatar (Options Table)

The default group avatar (used when item_id=0) requires special handling because it doesn't belong to any specific group:


Why Options Instead of Group Meta?

Group metadata functions require a valid group ID. Since the default group avatar doesn't belong to a specific group, it's stored in the options table instead.

Functions:

Fallback Logic: files.php122-126

If a group has no specific avatar, the system falls back to the default group avatar.

Sources: files.php114-127 files.php425-427 files.php710-711 files.php726-728 files.php815-817 files.php927-966

Multisite Blog Switching

All metadata is stored on the root blog in multisite installations to centralize management and avoid data fragmentation across network sites.

Blog Switching Pattern


Implementation in Functions

Every function that reads or writes metadata follows this pattern:

$switched = false;

if ( ! bp_is_root_blog() ) {
 switch_to_blog( bp_get_root_blog_id() );
 $switched = true;
}

// Perform metadata operations

if ( $switched ) {
 restore_current_blog();
}

Functions Using This Pattern:

FunctionLines
vipbp_filter_user_avatar_urlsfiles.php71-86
vipbp_filter_group_avatar_urlsfiles.php108-133
vipbp_filter_avatar_urlsfiles.php150-253
vipbp_filter_get_cover_imagefiles.php282-321
vipbp_handle_avatar_uploadfiles.php338-461
vipbp_handle_avatar_capturefiles.php483-542
vip_handle_cover_image_uploadfiles.php564-646
vipbp_handle_avatar_cropfiles.php688-736
vipbp_delete_existing_avatarfiles.php765-833
vipbp_delete_cover_imagefiles.php851-873

Sources: files.php71-86 files.php108-133 files.php150-253 files.php282-321 files.php338-461 files.php483-542 files.php564-646 files.php688-736 files.php765-833 files.php851-873

Metadata Lifecycle

Avatar Upload and Crop Lifecycle


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

Cover Image Lifecycle


Sources: files.php562-648 files.php847-875

Code Entity Reference

Functions That Write Metadata

FunctionMetadata Key(s)Storage FunctionLines
vipbp_handle_avatar_uploadvipbp-avatars, vipbp-group-avatars, vipbp-default-group-avatarupdate_user_meta, groups_update_groupmeta, bp_update_optionfiles.php336-464
vipbp_handle_avatar_capturevipbp-avatarsupdate_user_metafiles.php476-545
vip_handle_cover_image_uploadvipbp-user-cover, vipbp-group-coverupdate_user_meta, groups_update_groupmetafiles.php562-648
vipbp_handle_avatar_cropvipbp-avatars, vipbp-group-avatars, vipbp-default-group-avatarupdate_user_meta, groups_update_groupmeta, bp_update_optionfiles.php679-738

Functions That Read Metadata

FunctionMetadata Key(s)Storage FunctionLines
vipbp_filter_user_avatar_urlsvipbp-avatarsget_user_metafiles.php70-89
vipbp_filter_group_avatar_urlsvipbp-group-avatars, vipbp-default-group-avatargroups_get_groupmeta, bp_get_optionfiles.php106-136
vipbp_filter_avatar_urls(receives meta from above)N/Afiles.php148-256
vipbp_filter_get_cover_imagevipbp-user-cover, vipbp-group-coverget_user_meta, groups_get_groupmetafiles.php277-323
vipbp_filter_default_group_avatar_optionvipbp-default-group-avatarbp_get_optionfiles.php941-946
vipbp_filter_bb_default_group_avatarvipbp-default-group-avatarbp_get_optionfiles.php958-965

Functions That Delete Metadata

FunctionMetadata Key(s)Storage FunctionLines
vipbp_delete_existing_avatarvipbp-avatars, vipbp-group-avatars, vipbp-default-group-avatardelete_user_meta, groups_delete_groupmeta, bp_delete_optionfiles.php761-836
vipbp_delete_cover_imagevipbp-user-cover, vipbp-group-coverdelete_user_meta, groups_delete_groupmetafiles.php847-875

Sources: files.php1-967

Data Validation and Error Handling

Empty Metadata Checks

Functions validate metadata before use:

Avatar URL Retrieval: files.php163-214

  • If $meta is empty or $meta['url'] is empty, return Gravatar fallback
  • Prevents broken images when no avatar uploaded

Crop Operation Validation: files.php697-703 files.php716-722

  • Don't update crop values if $meta['url'] is empty
  • Prevents storing crop coordinates for failed uploads

Deletion Safety: files.php824-829 files.php865-868

  • Only call wp_delete_file() if $meta exists
  • Prevents errors when deleting non-existent files

Group Avatar Fallback

files.php122-126

If a group has no specific avatar, fall back to default group avatar:


Sources: files.php163-214 files.php697-703 files.php716-722 files.php824-829 files.php865-868 files.php122-126

BuddyBoss-Specific Metadata Handling

BuddyBoss adds additional default group avatar functionality that requires special metadata handling to avoid opendir() filesystem calls:


Implementation Details:

  1. Option Filter: files.php20 files.php941-946

    • Filters option_bp-default-custom-group-avatar
    • Returns empty string if VIP metadata exists
    • This prevents BuddyBoss from calling bb_get_default_custom_avatar()
  2. Avatar URL Filter: files.php21 files.php958-965

    • Filters bb_get_default_custom_upload_group_avatar
    • Provides actual avatar URL from vipbp-default-group-avatar metadata

Sources: files.php20-21 files.php927-966

Summary

The metadata storage architecture enables BuddyPress media functionality on VIP Go by:

  1. Avoiding filesystem operations - All media information stored in database
  2. Enabling dynamic transformations - Crop coordinates stored, not pre-generated images
  3. Centralizing data - All metadata on root blog in multisite
  4. Maintaining compatibility - Special handling for default group avatars and BuddyBoss

This design trades storage for compute, leveraging VIP FHS's dynamic image manipulation capabilities to reduce database and file storage requirements.

Sources: files.php1-967 README.md1-62