diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index a8dda6a..998bddf 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -16,6 +16,15 @@ jobs: password: ${{ secrets.CI_TOKEN }} fetch-depth: 0 # Important: Fetch all history for commit messages + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.0' + tools: composer + + - name: Install Composer dependencies + run: composer install --no-dev --prefer-dist --optimize-autoloader --no-interaction + - name: Get version id: get_version run: | diff --git a/includes/class-twp-twilio-api.php b/includes/class-twp-twilio-api.php index 9b7f647..9059817 100644 --- a/includes/class-twp-twilio-api.php +++ b/includes/class-twp-twilio-api.php @@ -39,28 +39,31 @@ class TWP_Twilio_API { /** * Initialize Twilio SDK client + * + * Loader priority: + * 1. Internal bundled vendor/autoload.php (shipped with release zip — primary) + * 2. External wp-content/twilio-sdk/autoload.php (legacy/manual install fallback) */ private function init_sdk_client() { - // Check for SDK autoloader - external location first (survives plugin updates) $autoloader_path = null; - // Priority 1: External SDK location (recommended) - $external_autoloader = TWP_EXTERNAL_SDK_DIR . 'autoload.php'; - if (file_exists($external_autoloader)) { - $autoloader_path = $external_autoloader; + // Priority 1: Internal bundled vendor (shipped via release zip) + $internal_autoloader = TWP_PLUGIN_DIR . 'vendor/autoload.php'; + if (file_exists($internal_autoloader)) { + $autoloader_path = $internal_autoloader; } - // Priority 2: Internal vendor directory (fallback) + // Priority 2: External legacy SDK location if (!$autoloader_path) { - $internal_autoloader = TWP_PLUGIN_DIR . 'vendor/autoload.php'; - if (file_exists($internal_autoloader)) { - $autoloader_path = $internal_autoloader; + $external_autoloader = TWP_EXTERNAL_SDK_DIR . 'autoload.php'; + if (file_exists($external_autoloader)) { + $autoloader_path = $external_autoloader; } } if (!$autoloader_path) { - error_log('TWP Plugin: Autoloader not found. Checked: ' . $external_autoloader . ' and ' . TWP_PLUGIN_DIR . 'vendor/autoload.php'); - throw new Exception('Twilio SDK not found. Please run: ./install-twilio-sdk-external.sh'); + error_log('TWP Plugin: Autoloader not found. Checked: ' . TWP_PLUGIN_DIR . 'vendor/autoload.php and ' . TWP_EXTERNAL_SDK_DIR . 'autoload.php'); + throw new Exception('Twilio SDK not found. Reinstall or update the plugin (release zips bundle the SDK), or run ./install-twilio-sdk-external.sh as a fallback.'); } // Load the autoloader diff --git a/includes/class-twp-webhooks.php b/includes/class-twp-webhooks.php index 4e11c3a..1c6d03f 100644 --- a/includes/class-twp-webhooks.php +++ b/includes/class-twp-webhooks.php @@ -9,21 +9,21 @@ class TWP_Webhooks { */ public function __construct() { // Load Twilio SDK if not already loaded - // Check external location first (survives plugin updates), then internal + // Priority: bundled vendor/ first (shipped via release zip), external legacy path as fallback if (!class_exists('\Twilio\Rest\Client')) { $autoloader_path = null; - // Priority 1: External SDK location - $external_autoloader = dirname(dirname(plugin_dir_path(dirname(__FILE__)))) . '/twilio-sdk/autoload.php'; - if (file_exists($external_autoloader)) { - $autoloader_path = $external_autoloader; + // Priority 1: Internal bundled vendor directory + $internal_autoloader = plugin_dir_path(dirname(__FILE__)) . 'vendor/autoload.php'; + if (file_exists($internal_autoloader)) { + $autoloader_path = $internal_autoloader; } - // Priority 2: Internal vendor directory + // Priority 2: External legacy SDK location if (!$autoloader_path) { - $internal_autoloader = plugin_dir_path(dirname(__FILE__)) . 'vendor/autoload.php'; - if (file_exists($internal_autoloader)) { - $autoloader_path = $internal_autoloader; + $external_autoloader = dirname(dirname(plugin_dir_path(dirname(__FILE__)))) . '/twilio-sdk/autoload.php'; + if (file_exists($external_autoloader)) { + $autoloader_path = $external_autoloader; } } diff --git a/install-aws-sdk-external.sh b/install-aws-sdk-external.sh new file mode 100755 index 0000000..efa0b9b --- /dev/null +++ b/install-aws-sdk-external.sh @@ -0,0 +1,121 @@ +#!/bin/bash + +# Script to install AWS SDK for PHP to an external location +# This prevents SDK from being deleted when WordPress updates the plugin +# +# Location: wp-content/aws-sdk/ (outside plugin folder) +# +# Uses the official single-file PHAR distribution from aws/aws-sdk-php releases. +# The PHAR ships its own composer-generated autoloader, so no PSR-4 wiring needed. + +echo "Installing AWS SDK for PHP (latest) 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 + +# 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/aws-sdk/ +WP_CONTENT_DIR="$(dirname "$(dirname "$SCRIPT_DIR")")" +SDK_DIR="$WP_CONTENT_DIR/aws-sdk" + +echo "Plugin directory: $SCRIPT_DIR" +echo "SDK will be installed to: $SDK_DIR" + +# Create SDK directory +mkdir -p "$SDK_DIR" + +# Download the latest PHAR release +echo "Downloading AWS SDK PHAR from GitHub..." +TEMP_DIR=$(mktemp -d) +cd "$TEMP_DIR" + +if ! curl -L https://github.com/aws/aws-sdk-php/releases/latest/download/aws.phar -o aws.phar; then + echo "ERROR: Failed to download AWS SDK PHAR" + echo "Please check your internet connection and try again" + rm -rf "$TEMP_DIR" + exit 1 +fi + +# Verify the download is non-empty (PHAR is roughly 12 MB) +if [ ! -s "$TEMP_DIR/aws.phar" ]; then + echo "ERROR: Downloaded AWS SDK PHAR is empty or missing" + rm -rf "$TEMP_DIR" + exit 1 +fi + +# Remove existing SDK if it exists +if [ -f "$SDK_DIR/aws.phar" ]; then + echo "Removing existing AWS SDK installation..." + rm -f "$SDK_DIR/aws.phar" +fi + +# Move the PHAR into place +echo "Installing SDK files..." +if ! mv "$TEMP_DIR/aws.phar" "$SDK_DIR/aws.phar"; then + echo "ERROR: Failed to move AWS SDK PHAR into place" + rm -rf "$TEMP_DIR" + exit 1 +fi + +# Create the autoloader shim +cat > "$SDK_DIR/autoload.php" << 'EOF' +
The Twilio PHP SDK is required for this plugin to work.
-Recommended: Install SDK to external location (survives plugin updates):
+Recommended: Reinstall or update the plugin. Plugin updates now bundle the SDK (the release zip ships a pre-built vendor/ directory), so a fresh install or update is the simplest fix.
Legacy / manual install: If you can't update the plugin, you can install the SDK to the external location instead:
chmod +x install-twilio-sdk-external.sh && ./install-twilio-sdk-external.sh
- Alternative: Install SDK inside plugin folder:
-chmod +x install-twilio-sdk.sh && ./install-twilio-sdk.sh
Plugin path:
-External SDK path:
+Bundled vendor path:
+External SDK fallback path:
+You have selected AWS SNS as your SMS provider, but the AWS PHP SDK is not available.
+Recommended: Update the plugin to a release-bundled version — newer release zips bundle the AWS SDK alongside the Twilio SDK in vendor/.
Legacy / manual install: Install the AWS SDK to the external location:
+chmod +x install-aws-sdk-external.sh && ./install-aws-sdk-external.sh
+ External AWS SDK path:
+If you don't need AWS SNS, switch the SMS provider back to Twilio under the plugin settings.
The plugin was updated and the Twilio SDK needs to be reinstalled.
-To prevent this in the future, install the SDK to the external location:
+The plugin was updated, but no Twilio SDK could be found.
+Plugin release zips normally bundle the SDK in vendor/, so this usually means the release was built without dependencies, or the upload was incomplete. Try downloading the release zip again and reinstalling.
Manual install fallback:
cd && ./install-twilio-sdk-external.sh
- The external SDK at survives plugin updates.
Bundled vendor path:
+External SDK fallback path: