4.8 KiB
Vendor Library Setup Guide
You have two options to include the Google API Client library:
Option 1: Manual Download (Recommended for Distribution)
This is the easiest method and doesn't require Composer.
Step 1: Download Google API PHP Client
- Go to: https://github.com/googleapis/google-api-php-client/releases
- Download the latest release (e.g.,
google-api-php-client-2.15.0.zip) - Extract the ZIP file
Step 2: Copy to Vendor Directory
Copy the extracted files into your plugin's vendor/ directory following this structure:
vendor/
├── autoload.php (already exists in plugin)
├── google/
│ ├── apiclient/
│ │ ├── src/
│ │ │ └── Google/
│ │ │ ├── Client.php
│ │ │ ├── Service/
│ │ │ └── ... (all Google API files)
│ │ └── ...
│ └── apiclient-services/
│ ├── autoload.php
│ └── src/
│ └── Google/
│ └── Service/
│ └── ShoppingContent/
│ └── ... (Shopping API files)
├── guzzlehttp/
│ ├── guzzle/
│ │ └── src/
│ ├── psr7/
│ │ └── src/
│ └── promises/
│ └── src/
├── psr/
│ ├── http-message/src/
│ ├── http-client/src/
│ ├── cache/src/
│ └── log/Psr/Log/
├── firebase/
│ └── php-jwt/src/
└── monolog/
└── monolog/src/Monolog/
Step 3: Quick Copy Instructions
If you downloaded the Google API Client via Composer once, you can simply copy the entire vendor directory:
# Run composer install once (on your development machine)
composer install
# Then copy the entire vendor directory to your plugin
# The plugin's custom autoloader will handle everything
The vendor directory will be about 10-15 MB, which is perfectly fine for WordPress plugin distribution.
Option 2: Use Composer (For Development)
If you're actively developing the plugin:
cd /path/to/plugin
composer install
This will:
- Download all dependencies
- Generate an optimized autoloader
- Create
vendor/autoload_real.php
The plugin's autoloader (vendor/autoload.php) automatically detects and uses Composer's autoloader if available.
Verifying Installation
After setting up the vendor directory, check that these files exist:
vendor/google/apiclient/src/Google/Client.phpvendor/google/apiclient-services/src/Google/Service/ShoppingContent.phpvendor/guzzlehttp/guzzle/src/Client.php
If these files exist, the plugin will work correctly!
For Plugin Distribution
When distributing your plugin (e.g., to clients or WordPress.org):
- Include the vendor directory in your plugin ZIP
- Users simply upload and activate - no Composer needed
- The custom autoloader handles everything automatically
This is the standard practice for WordPress plugins - most popular plugins include their dependencies rather than requiring Composer.
Simplified Download Script
Want to automate this? Run this in your plugin directory:
#!/bin/bash
# Download and setup Google API Client
# Install via Composer (easiest way to get all dependencies)
composer install --no-dev --optimize-autoloader
# Remove Composer development files (optional)
rm -rf vendor/bin
rm -rf vendor/composer/*.json
echo "Google API Client installed successfully!"
echo "You can now distribute the plugin with the vendor directory included."
File Size Note
The complete vendor directory with Google API Client and dependencies is approximately:
- Uncompressed: 10-15 MB
- ZIP compressed: 2-3 MB
This is acceptable for WordPress plugin distribution and much easier than requiring users to run Composer.
Troubleshooting
"Google API Client library is missing" error
If you see this error in WordPress admin:
- Check that
vendor/google/apiclient/src/Google/Client.phpexists - Verify file permissions (should be readable by web server)
- Check that the autoloader is being loaded (check plugin main file)
Class not found errors
If you get "Class 'Google_Service_ShoppingContent' not found":
- Ensure
vendor/google/apiclient-services/exists - Check that Shopping Content service is included in apiclient-services
- You may need to download the services separately from: https://github.com/googleapis/google-api-php-client-services
Minimal Installation (Advanced)
If you want to reduce file size, you can include only the required services:
- Install full Google API Client
- Keep only these directories:
google/apiclient/google/apiclient-services/src/Google/Service/ShoppingContent/guzzlehttp/(all)psr/(all)firebase/php-jwt/
This reduces the size to ~5 MB while keeping all necessary functionality.