163 lines
4.8 KiB
Markdown
163 lines
4.8 KiB
Markdown
# 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
|
|
|
|
1. Go to: https://github.com/googleapis/google-api-php-client/releases
|
|
2. Download the latest release (e.g., `google-api-php-client-2.15.0.zip`)
|
|
3. 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:
|
|
|
|
```bash
|
|
# 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:
|
|
|
|
```bash
|
|
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:
|
|
|
|
1. `vendor/google/apiclient/src/Google/Client.php`
|
|
2. `vendor/google/apiclient-services/src/Google/Service/ShoppingContent.php`
|
|
3. `vendor/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):
|
|
|
|
1. **Include the vendor directory** in your plugin ZIP
|
|
2. Users simply upload and activate - no Composer needed
|
|
3. 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:
|
|
|
|
```bash
|
|
#!/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:
|
|
|
|
1. Check that `vendor/google/apiclient/src/Google/Client.php` exists
|
|
2. Verify file permissions (should be readable by web server)
|
|
3. Check that the autoloader is being loaded (check plugin main file)
|
|
|
|
### Class not found errors
|
|
|
|
If you get "Class 'Google_Service_ShoppingContent' not found":
|
|
|
|
1. Ensure `vendor/google/apiclient-services/` exists
|
|
2. Check that Shopping Content service is included in apiclient-services
|
|
3. 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:
|
|
|
|
1. Install full Google API Client
|
|
2. 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.
|