Add SDK persistence and configurable edge location
All checks were successful
Create Release / build (push) Successful in 4s
All checks were successful
Create Release / build (push) Successful in 4s
- Add external SDK installation (wp-content/twilio-sdk/) that survives WordPress plugin updates - Add install-twilio-sdk-external.sh script for external SDK setup - Update SDK loading to check external location first, internal fallback - Add post-update detection hook to warn if SDK was deleted - Add configurable Twilio Edge Location setting (default: roaming) - Fix US calls failing due to hardcoded Sydney edge location Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
158
install-twilio-sdk-external.sh
Executable file
158
install-twilio-sdk-external.sh
Executable file
@@ -0,0 +1,158 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script to install Twilio PHP SDK to an external location
|
||||
# This prevents SDK from being deleted when WordPress updates the plugin
|
||||
#
|
||||
# Location: wp-content/twilio-sdk/ (outside plugin folder)
|
||||
|
||||
echo "Installing Twilio PHP SDK v8.7.0 to external location..."
|
||||
echo "This will install the SDK outside the plugin folder to survive plugin updates."
|
||||
|
||||
# Check if we can download files
|
||||
if ! command -v curl &> /dev/null; then
|
||||
echo "ERROR: curl is required to download the SDK"
|
||||
echo "Please install curl and try again"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v tar &> /dev/null; then
|
||||
echo "ERROR: tar is required to extract the SDK"
|
||||
echo "Please install tar and try again"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the script directory (plugin directory)
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
# Calculate wp-content directory (two levels up from plugin)
|
||||
# Plugin is at: wp-content/plugins/twilio-wp-plugin/
|
||||
# We want: wp-content/twilio-sdk/
|
||||
WP_CONTENT_DIR="$(dirname "$(dirname "$SCRIPT_DIR")")"
|
||||
SDK_DIR="$WP_CONTENT_DIR/twilio-sdk"
|
||||
|
||||
echo "Plugin directory: $SCRIPT_DIR"
|
||||
echo "SDK will be installed to: $SDK_DIR"
|
||||
|
||||
# Create SDK directory
|
||||
mkdir -p "$SDK_DIR/twilio/sdk"
|
||||
|
||||
# Download the latest release (8.7.0)
|
||||
echo "Downloading Twilio SDK from GitHub..."
|
||||
TEMP_DIR=$(mktemp -d)
|
||||
cd "$TEMP_DIR"
|
||||
|
||||
if ! curl -L https://github.com/twilio/twilio-php/archive/refs/tags/8.7.0.tar.gz -o twilio-sdk.tar.gz; then
|
||||
echo "ERROR: Failed to download Twilio SDK"
|
||||
echo "Please check your internet connection and try again"
|
||||
rm -rf "$TEMP_DIR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract the archive
|
||||
echo "Extracting SDK files..."
|
||||
if ! tar -xzf twilio-sdk.tar.gz; then
|
||||
echo "ERROR: Failed to extract SDK files"
|
||||
rm -rf "$TEMP_DIR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the extracted directory exists
|
||||
if [ ! -d "twilio-php-8.7.0/src" ]; then
|
||||
echo "ERROR: Extracted SDK directory structure is unexpected"
|
||||
rm -rf "$TEMP_DIR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Remove existing SDK if it exists
|
||||
if [ -d "$SDK_DIR/twilio/sdk" ]; then
|
||||
echo "Removing existing SDK installation..."
|
||||
rm -rf "$SDK_DIR/twilio/sdk"
|
||||
mkdir -p "$SDK_DIR/twilio/sdk"
|
||||
fi
|
||||
|
||||
# Move the entire src directory to be the sdk
|
||||
echo "Installing SDK files..."
|
||||
if ! mv twilio-php-8.7.0/src/* "$SDK_DIR/twilio/sdk/"; then
|
||||
echo "ERROR: Failed to move SDK files"
|
||||
rm -rf "$TEMP_DIR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create a comprehensive autoloader
|
||||
cat > "$SDK_DIR/autoload.php" << 'EOF'
|
||||
<?php
|
||||
/**
|
||||
* Twilio SDK v8.7.0 Autoloader (External Installation)
|
||||
* This file loads the Twilio PHP SDK classes
|
||||
*
|
||||
* Location: wp-content/twilio-sdk/autoload.php
|
||||
* This location survives WordPress plugin updates
|
||||
*/
|
||||
|
||||
// Prevent multiple registrations
|
||||
if (!defined('TWILIO_AUTOLOADER_REGISTERED')) {
|
||||
define('TWILIO_AUTOLOADER_REGISTERED', true);
|
||||
|
||||
// Register the autoloader
|
||||
spl_autoload_register(function ($class) {
|
||||
// Only handle Twilio classes
|
||||
if (strpos($class, 'Twilio\\') !== 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Convert class name to file path
|
||||
$relative_class = substr($class, 7); // Remove 'Twilio\'
|
||||
$file = __DIR__ . '/twilio/sdk/' . str_replace('\\', '/', $relative_class) . '.php';
|
||||
|
||||
if (file_exists($file)) {
|
||||
require_once $file;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
// Try to load the SDK's own autoloader if it exists
|
||||
$sdk_autoloader = __DIR__ . '/twilio/sdk/autoload.php';
|
||||
if (file_exists($sdk_autoloader)) {
|
||||
require_once $sdk_autoloader;
|
||||
}
|
||||
|
||||
// Load essential Twilio classes manually to ensure they're available
|
||||
$essential_classes = [
|
||||
__DIR__ . '/twilio/sdk/Rest/Client.php',
|
||||
__DIR__ . '/twilio/sdk/TwiML/VoiceResponse.php',
|
||||
__DIR__ . '/twilio/sdk/Exceptions/TwilioException.php',
|
||||
__DIR__ . '/twilio/sdk/Security/RequestValidator.php'
|
||||
];
|
||||
|
||||
foreach ($essential_classes as $class_file) {
|
||||
if (file_exists($class_file)) {
|
||||
require_once $class_file;
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# Clean up temp directory
|
||||
cd "$SCRIPT_DIR"
|
||||
rm -rf "$TEMP_DIR"
|
||||
|
||||
# Verify installation
|
||||
echo ""
|
||||
echo "Verifying installation..."
|
||||
if [ -f "$SDK_DIR/autoload.php" ] && [ -d "$SDK_DIR/twilio/sdk" ]; then
|
||||
echo "=============================================="
|
||||
echo "Twilio SDK v8.7.0 installed successfully!"
|
||||
echo "=============================================="
|
||||
echo ""
|
||||
echo "Installation location: $SDK_DIR"
|
||||
echo ""
|
||||
echo "This SDK is installed OUTSIDE the plugin folder,"
|
||||
echo "so it will NOT be deleted when WordPress updates the plugin."
|
||||
echo ""
|
||||
echo "The plugin will automatically detect this external SDK."
|
||||
else
|
||||
echo "Installation failed - files not found"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user