VOOZH about

URL: https://deepwiki.com/Automattic/BuddyPress-VIP-Go/6-development-guide

⇱ Development Guide | Automattic/BuddyPress-VIP-Go | DeepWiki


Loading...
Menu

Development Guide

This guide provides an introduction to developing for the BuddyPress VIP Go plugin, including common pitfalls, workflow overview, and essential tooling. The plugin bridges BuddyPress functionality with WordPress VIP Go's distributed file system, requiring careful consideration of platform-specific constraints.

For detailed setup instructions, see Local Development Setup. For information about the testing infrastructure, see Testing Infrastructure. For code quality requirements and standards enforcement, see Code Quality and Standards.

Purpose and Scope

This guide is designed for developers who need to:

  • Understand the plugin's architectural constraints and design decisions
  • Avoid common pitfalls when working with VIP Go file operations
  • Set up a local development environment with required dependencies
  • Run tests and code quality checks using Composer scripts
  • Contribute code changes that meet WordPress VIP standards

The plugin requires PHP 8.2+ and follows WordPress VIP coding standards. Development workflows are managed through Composer scripts and GitHub Actions for continuous integration.

Sources: README.md1-62 composer.json21-23

Common Pitfalls and Warnings

Before beginning development, developers must understand these critical constraints to avoid breaking media functionality on VIP Go sites:

VIP Go File System Constraints

ConstraintImplicationWhat to Avoid
No direct file system accessStandard PHP file functions fail on VIP FHSfopen(), file_get_contents(), is_dir(), opendir() on upload paths
No flock() supportFile locking operations are not availableChunked upload assembly directly on VIP FHS
Distributed storageFiles are not on local diskAssumptions about file paths being readable via PHP
CDN-based deliveryAll files served through CDN layerDirect file serving or path-based access

Key Rule: Do not assume standard WordPress file system behavior. VIP Go uses a different storage backend, and this plugin exists specifically to handle those differences.

Sources: AGENTS.md69-78 README.md11-22

Critical Code Areas

The following areas require special attention when making changes:

1. files.php - Intentionally Monolithic

The files.php1-999 file (~31KB) is intentionally large because it contains cohesive file-handling logic for the VIP Go environment. The logic is tightly coupled to VIP Go's file system API.

⚠️ Do not refactor or split files.php without understanding VIP Go file system constraints. The monolithic structure ensures all VIP file operations remain centralized and maintainable.

2. Media Upload Operations

Changes to upload handling in files.php can break media uploads on production VIP Go sites. All upload operations must:

  • Use wp_handle_upload() or wp_handle_sideload() (WordPress VIP approved functions)
  • Store metadata in WordPress database tables (vipbp-avatars, vipbp-group-avatars, vipbp-user-cover, vipbp-group-cover)
  • Generate VIP FHS URLs with dynamic transformation parameters
  • Never create multiple physical file sizes (rely on CDN transformations)

3. BuddyPress Dependency

The plugin hooks into BuddyPress initialization via the bp_loaded action in buddypress-vip-go.php17-33 Test environments must have BuddyPress installed and active before this plugin activates, or integration tests will fail.

4. Environment Detection

The plugin only loads its integration layer when VIP Go environment markers are detected in buddypress-vip-go.php23-27:

  • class_exists( 'A8C_Files' )
  • defined( 'FILES_CLIENT_SITE_ID' )
  • defined( 'FILES_ACCESS_TOKEN' )

Changes to this detection logic affect whether the plugin activates on VIP Go sites.

Sources: AGENTS.md64-78 files.php1-999 buddypress-vip-go.php1-35

Development Workflow Pitfalls

PitfallWhy It HappensHow to Avoid
CI rejects code with standard violationsVIP enforces strict PHPCS rulesRun composer cs before committing
Integration tests fail in wp-envwp-env not running or BuddyPress not installedRun npx wp-env start and verify BuddyPress is active
Unit tests pass but integration tests failDifferent test environments (BrainMonkey vs real WordPress)Run both test suites: composer test:unit and composer test:integration
Changes break media on VIP GoLocal environment doesn't replicate VIP FHS behaviorReview System Architecture and test on VIP Go staging environment

Sources: AGENTS.md69-78 composer.json52-54

Architectural Constraints

Understanding why the plugin is structured as it is helps avoid introducing bugs:

Design Principle: Metadata-Driven Transformations


Design Rationale: VIP Go's distributed file system makes pre-generating multiple image sizes inefficient and complex. Instead, the plugin stores only the original file and transformation metadata, relying on VIP FHS's Photon-like CDN to perform transformations on-demand.

Code Implementation:

  • Metadata storage: files.php86-129 (avatar metadata functions)
  • URL generation: files.php295-354 (avatar URL filters)
  • Dynamic parameters: ?w=150&crop={x},{y},{w},{h}&resize=150,150&strip=info

Sources: README.md24-41 files.php1-999

Design Principle: Hook Priority Orchestration

The plugin must register certain filters before BuddyPress initializes to prevent filesystem errors:


Critical Hooks:

  • bp_core_avatar_folder_dir - Must return empty string before BuddyPress attempts opendir() files.php230-232
  • bp_avatar_history_dir - Must disable avatar history to prevent filesystem access files.php233-235
  • bp_core_pre_avatar_handle_upload - Must override upload handler before BuddyPress processes uploads files.php102-117

Sources: buddypress-vip-go.php17-33 files.php55-83

Design Principle: Temporary Directory Workaround

BuddyBoss video uploads require flock() for chunked assembly, which VIP FHS doesn't support. The solution uses a two-stage upload:


Code Implementation:

Sources: files.php424-469 README.md43-46

Development Requirements

The plugin has specific technical requirements that must be met before development can begin:

RequirementVersionPurposeInstallation
PHP8.2+Minimum runtime versionSystem package manager
Composer2.xDependency and script managementgetcomposer.org
wp-envLatestLocal WordPress environmentnpm install -g @wordpress/env
Node.js16+Required by wp-envnodejs.org
DockerLatestBackend for wp-envdocker.com
BuddyPressLatestRequired plugin dependencyInstalled via wp-env

Note: BuddyPress must be installed and active in the test environment for integration tests to run successfully.

Sources: composer.json21-23 AGENTS.md72-74

Development Toolchain Architecture

The following diagram shows how the development tools interact and what they validate:


Purpose: This diagram illustrates the development toolchain flow from code changes through local validation and CI/CD checks. All code changes must pass PHP syntax validation, VIP coding standards, compatibility checks, and automated tests before being merged.

Sources: composer.json44-67 .claude/CLAUDE.md17-21

Essential Composer Scripts

The plugin provides a comprehensive set of Composer scripts for development tasks. These scripts are the primary interface for local development workflows:


Purpose: This diagram maps the available Composer scripts and their relationships. The scripts are organized by function: code quality validation, testing, coverage analysis, and internationalization.

Sources: composer.json44-67

Core Commands Reference

CommandPurposeOutputWhen to Use
composer lintValidates PHP syntax across all filesTerminal output with syntax errorsBefore committing (catches parse errors)
composer csChecks code against VIP standardsList of coding standard violationsBefore committing (required by CI)
composer cs-fixAuto-fixes coding standard violationsModified files and remaining issuesAfter composer cs finds issues
composer test:unitRuns unit tests (BrainMonkey mocks)PHPUnit test resultsTesting isolated logic without WordPress
composer test:integrationRuns integration tests with WordPressPHPUnit test results with WP contextTesting WordPress-dependent behavior
composer test:integration-msRuns multisite integration testsPHPUnit test results in multisite modeTesting multisite-specific functionality
composer coverageGenerates HTML coverage report./build/coverage-html/ directoryAnalyzing test coverage locally
composer i18nGenerates translation template./languages/buddypress-vip-go.potPreparing translations

Critical: CI will reject commits that fail composer cs. Always run code standards checks before pushing.

Sources: composer.json44-67 AGENTS.md69-78

Standard Development Workflow

The recommended workflow ensures code quality and prevents CI failures:


Workflow Notes:

  • Integration tests require wp-env start to be running
  • BuddyPress must be installed in the wp-env environment
  • The cs-fix command can auto-fix most standard violations, but some require manual fixes
  • CI runs the same checks as local commands, so passing locally should pass in CI

Sources: composer.json44-67 AGENTS.md69-78

Quick Start Commands

For a typical development session, run this sequence:


Common Issues:

ErrorCauseSolution
composer test:integration fails with "BuddyPress not found"BuddyPress not installed in wp-envInstall BuddyPress via wp-env: wp-env run cli wp plugin install buddypress --activate
composer cs finds violations after composer cs-fixSome violations require manual fixesReview PHPCS output and fix manually
Integration tests fail locally but pass in CIDifferent wp-env or BuddyPress versionsMatch CI versions: WordPress 6.6, PHP 8.2 (see .github/workflows/integration.yml)

Sources: composer.json44-67 AGENTS.md69-78

Development Dependencies

The plugin uses several key development dependencies that enforce code quality and enable testing:

PackagePurposeVersion
automattic/vipwpcsWordPress VIP coding standards^3
php-parallel-lint/php-parallel-lintParallel PHP syntax checking^1.0
phpcompatibility/phpcompatibility-wpPHP version compatibility^2.1
phpunit/phpunitUnit and integration testing^9.6
yoast/wp-test-utilsWordPress test utilities^1.2

These dependencies are automatically installed via composer install and should not be committed to the repository (they are excluded via .distignore).

Sources: composer.json25-30

Code Organization and Key Files

The plugin follows a flat file structure focused on the core integration layer:


Key File Responsibilities:

FileLinesPurposeEntry Points
buddypress-vip-go.php~35Bootstrap, environment detection, conditional loadingvip_init_buddypress_media()
files.php~999All VIP FHS integration, hook registration, media operations30+ filter/action callbacks
tests/Unit/VariousUnit tests with BrainMonkey mocksExtends YoastTestCase
tests/Integration/VariousIntegration tests with real WordPressExtends WPIntegration\TestCase

Critical Functions in files.php:

  • vipbp_handle_avatar_upload() - Avatar upload handler files.php102-117
  • vip_handle_cover_image_upload() - Cover image upload handler files.php140-158
  • vipbp_get_user_avatar_metadata() - Retrieve avatar metadata files.php86-103
  • vipbp_default_avatar_user() - Generate avatar URLs with dynamic params files.php295-354
  • vipbp_filter_chunked_upload_temp_dir() - Video upload temp dir workaround files.php424-436

Sources: buddypress-vip-go.php1-35 files.php1-999 composer.json1-68

Autoloader Configuration

The plugin uses PSR-4 autoloading for development code, specifically the test namespace:


This configuration maps the Automattic\BuddyPressVIPGo\Tests namespace to the tests/ directory, enabling automatic loading of test helper classes and utilities.

Sources: composer.json32-36

Contribution Prerequisites

Before contributing code, developers must:

1. Understand VIP Go Platform Constraints

Review the following pages to understand why the code is structured as it is:

Critical Understanding: This plugin exists because VIP Go's distributed file system does not support standard PHP filesystem operations. Do not introduce code that assumes local filesystem access.

2. Set Up Required Tools

ToolMinimum VersionVerification Command
PHP8.2php -v
Composer2.0composer --version
Node.js16node --version
Docker20.10docker --version

3. Review Code Quality Requirements

Read Code Quality and Standards for:

  • PHPCS configuration in .phpcs.xml.dist
  • WordPress VIP coding standards (WordPress-VIP-Go ruleset)
  • PHP 8.2+ compatibility requirements
  • Internationalization requirements (buddypress-vip-go text domain)

4. Understand Testing Requirements

Read Testing Infrastructure for:

  • When to write unit tests vs integration tests
  • How to use YoastTestCase for unit tests (BrainMonkey)
  • How to use WPIntegration\TestCase for integration tests (real WordPress)
  • How to run tests locally and in CI

5. Study the Core Integration Layer

Before modifying files.php understand:

  • Hook registration timing (why some hooks must fire before bp_init priority 8)
  • Metadata storage structure (vipbp-avatars, vipbp-group-avatars, etc.)
  • Dynamic URL generation with query parameters
  • The chunked video upload workaround for flock() incompatibility

Plugin Maturity: The plugin is classified as "Tier 3" in the internal audit, indicating it needs ongoing modernization. Improvements to testing and documentation are welcome, but changes should be incremental and thoroughly tested.

Sources: AGENTS.md64-78 README.md1-62

Next Steps

For detailed information about specific aspects of development:

Sources: composer.json1-68 .claude/CLAUDE.md1-26