feature/webview-softphone #2

Merged
jknapp merged 4 commits from feature/webview-softphone into main 2026-05-05 16:00:47 +00:00
5 changed files with 233 additions and 50 deletions
Showing only changes of commit ee8e111970 - Show all commits

View File

@@ -16,6 +16,15 @@ jobs:
password: ${{ secrets.CI_TOKEN }} password: ${{ secrets.CI_TOKEN }}
fetch-depth: 0 # Important: Fetch all history for commit messages 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 - name: Get version
id: get_version id: get_version
run: | run: |

View File

@@ -39,28 +39,31 @@ class TWP_Twilio_API {
/** /**
* Initialize Twilio SDK client * 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() { private function init_sdk_client() {
// Check for SDK autoloader - external location first (survives plugin updates)
$autoloader_path = null; $autoloader_path = null;
// Priority 1: External SDK location (recommended) // Priority 1: Internal bundled vendor (shipped via release zip)
$external_autoloader = TWP_EXTERNAL_SDK_DIR . 'autoload.php';
if (file_exists($external_autoloader)) {
$autoloader_path = $external_autoloader;
}
// Priority 2: Internal vendor directory (fallback)
if (!$autoloader_path) {
$internal_autoloader = TWP_PLUGIN_DIR . 'vendor/autoload.php'; $internal_autoloader = TWP_PLUGIN_DIR . 'vendor/autoload.php';
if (file_exists($internal_autoloader)) { if (file_exists($internal_autoloader)) {
$autoloader_path = $internal_autoloader; $autoloader_path = $internal_autoloader;
} }
// Priority 2: External legacy SDK location
if (!$autoloader_path) {
$external_autoloader = TWP_EXTERNAL_SDK_DIR . 'autoload.php';
if (file_exists($external_autoloader)) {
$autoloader_path = $external_autoloader;
}
} }
if (!$autoloader_path) { if (!$autoloader_path) {
error_log('TWP Plugin: Autoloader not found. Checked: ' . $external_autoloader . ' and ' . TWP_PLUGIN_DIR . 'vendor/autoload.php'); 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. Please run: ./install-twilio-sdk-external.sh'); 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 // Load the autoloader

View File

@@ -9,22 +9,22 @@ class TWP_Webhooks {
*/ */
public function __construct() { public function __construct() {
// Load Twilio SDK if not already loaded // 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')) { if (!class_exists('\Twilio\Rest\Client')) {
$autoloader_path = null; $autoloader_path = null;
// Priority 1: External SDK location // Priority 1: Internal bundled vendor directory
$external_autoloader = dirname(dirname(plugin_dir_path(dirname(__FILE__)))) . '/twilio-sdk/autoload.php';
if (file_exists($external_autoloader)) {
$autoloader_path = $external_autoloader;
}
// Priority 2: Internal vendor directory
if (!$autoloader_path) {
$internal_autoloader = plugin_dir_path(dirname(__FILE__)) . 'vendor/autoload.php'; $internal_autoloader = plugin_dir_path(dirname(__FILE__)) . 'vendor/autoload.php';
if (file_exists($internal_autoloader)) { if (file_exists($internal_autoloader)) {
$autoloader_path = $internal_autoloader; $autoloader_path = $internal_autoloader;
} }
// Priority 2: External legacy SDK location
if (!$autoloader_path) {
$external_autoloader = dirname(dirname(plugin_dir_path(dirname(__FILE__)))) . '/twilio-sdk/autoload.php';
if (file_exists($external_autoloader)) {
$autoloader_path = $external_autoloader;
}
} }
if ($autoloader_path) { if ($autoloader_path) {

121
install-aws-sdk-external.sh Executable file
View File

@@ -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'
<?php
/**
* AWS SDK for PHP Autoloader (External Installation)
* This file loads the AWS SDK via its bundled PHAR distribution.
*
* Location: wp-content/aws-sdk/autoload.php
* This location survives WordPress plugin updates.
*
* The aws.phar file is the official single-file build from aws/aws-sdk-php
* and ships with its own composer-generated autoloader, so all we need to
* do is require_once the PHAR itself.
*/
// Prevent multiple registrations
if (!defined('TWP_AWS_AUTOLOADER_REGISTERED')) {
define('TWP_AWS_AUTOLOADER_REGISTERED', true);
// The PHAR contains its own autoloader stub; requiring it registers
// the AWS\, Aws\, GuzzleHttp\, and supporting namespaces.
$aws_phar = __DIR__ . '/aws.phar';
if (file_exists($aws_phar)) {
require_once $aws_phar;
}
}
EOF
# Clean up temp directory
cd "$SCRIPT_DIR"
rm -rf "$TEMP_DIR"
# Verify installation
echo ""
echo "Verifying installation..."
if [ -f "$SDK_DIR/aws.phar" ] && [ -s "$SDK_DIR/aws.phar" ] && [ -f "$SDK_DIR/autoload.php" ]; then
echo "=============================================="
echo "AWS SDK for PHP 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 "Next steps:"
echo " 1. In WP admin, open the Twilio plugin Settings page."
echo " 2. Switch SMS provider to \"Amazon SNS\"."
echo " 3. Enter AWS Access Key, Secret Key, and Region (e.g. us-west-2)."
else
echo "Installation failed - files not found"
exit 1
fi

View File

@@ -20,8 +20,11 @@ define('TWP_DB_VERSION', '1.6.2'); // Track database version separately
define('TWP_PLUGIN_DIR', plugin_dir_path(__FILE__)); define('TWP_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('TWP_PLUGIN_URL', plugin_dir_url(__FILE__)); define('TWP_PLUGIN_URL', plugin_dir_url(__FILE__));
define('TWP_PLUGIN_BASENAME', plugin_basename(__FILE__)); define('TWP_PLUGIN_BASENAME', plugin_basename(__FILE__));
// External SDK location - survives plugin updates (wp-content/twilio-sdk/) // External SDK location - legacy/manual install path (wp-content/twilio-sdk/)
// Bundled vendor/ inside the plugin (shipped via release zip) is now the primary source.
define('TWP_EXTERNAL_SDK_DIR', dirname(dirname(TWP_PLUGIN_DIR)) . '/twilio-sdk/'); define('TWP_EXTERNAL_SDK_DIR', dirname(dirname(TWP_PLUGIN_DIR)) . '/twilio-sdk/');
// External AWS SDK location - installed via install-aws-sdk-external.sh (wp-content/aws-sdk/)
define('TWP_EXTERNAL_AWS_SDK_DIR', dirname(dirname(TWP_PLUGIN_DIR)) . '/aws-sdk/');
/** /**
* Plugin activation hook * Plugin activation hook
@@ -32,47 +35,91 @@ function twp_activate() {
} }
/** /**
* Check if Twilio SDK is installed and show admin notice if not * Check if Twilio (and optionally AWS) SDKs are available, load them, and
* Checks external location first (survives plugin updates), then internal fallback * register admin notices if anything required is missing.
*
* Priority for the Twilio autoloader:
* 1. Internal bundled `vendor/autoload.php` (shipped with release zip — always current)
* 2. External legacy `wp-content/twilio-sdk/autoload.php` (manual install fallback)
*
* Composer's bundled autoloader handles BOTH `Twilio\…` and `Aws\…` via PSR-4. If
* the bundled vendor doesn't supply Aws (e.g. someone installed Twilio-only
* externally), we fall back to `wp-content/aws-sdk/autoload.php`.
*/ */
function twp_check_sdk_installation() { function twp_check_sdk_installation() {
$sdk_installed = false; $twilio_sdk_installed = false;
$aws_sdk_installed = false;
// Priority 1: Check external SDK location (survives plugin updates) // --- Twilio SDK ---
$external_autoloader = TWP_EXTERNAL_SDK_DIR . 'autoload.php'; // Priority 1: Internal bundled vendor (shipped via release zip)
if (file_exists($external_autoloader)) {
require_once $external_autoloader;
$sdk_installed = class_exists('Twilio\Rest\Client');
}
// Priority 2: Fall back to internal vendor directory
if (!$sdk_installed) {
$internal_autoloader = TWP_PLUGIN_DIR . 'vendor/autoload.php'; $internal_autoloader = TWP_PLUGIN_DIR . 'vendor/autoload.php';
if (file_exists($internal_autoloader)) { if (file_exists($internal_autoloader)) {
require_once $internal_autoloader; require_once $internal_autoloader;
$sdk_installed = class_exists('Twilio\Rest\Client'); $twilio_sdk_installed = class_exists('Twilio\Rest\Client');
}
// Priority 2: External legacy location (manual installs)
if (!$twilio_sdk_installed) {
$external_autoloader = TWP_EXTERNAL_SDK_DIR . 'autoload.php';
if (file_exists($external_autoloader)) {
require_once $external_autoloader;
$twilio_sdk_installed = class_exists('Twilio\Rest\Client');
} }
} }
if (!$sdk_installed) { // --- AWS SDK ---
// The bundled composer vendor may already provide it (if shipped with release).
$aws_sdk_installed = class_exists('Aws\Sns\SnsClient');
if (!$aws_sdk_installed) {
$aws_external_autoloader = TWP_EXTERNAL_AWS_SDK_DIR . 'autoload.php';
if (file_exists($aws_external_autoloader)) {
require_once $aws_external_autoloader;
$aws_sdk_installed = class_exists('Aws\Sns\SnsClient');
}
}
// Twilio is the hard requirement — always notify if missing.
if (!$twilio_sdk_installed) {
add_action('admin_notices', 'twp_sdk_missing_notice'); add_action('admin_notices', 'twp_sdk_missing_notice');
} }
// AWS is only required when the SNS provider is selected.
if (!$aws_sdk_installed && get_option('twp_sms_provider') === 'aws_sns') {
add_action('admin_notices', 'twp_aws_sdk_missing_notice');
}
} }
/** /**
* Display admin notice for missing SDK * Display admin notice for missing Twilio SDK
*/ */
function twp_sdk_missing_notice() { function twp_sdk_missing_notice() {
?> ?>
<div class="notice notice-error is-dismissible"> <div class="notice notice-error is-dismissible">
<h3>Twilio WordPress Plugin - SDK Required</h3> <h3>Twilio WordPress Plugin - Twilio SDK Required</h3>
<p><strong>The Twilio PHP SDK is required for this plugin to work.</strong></p> <p><strong>The Twilio PHP SDK is required for this plugin to work.</strong></p>
<p><strong>Recommended:</strong> Install SDK to external location (survives plugin updates):</p> <p><strong>Recommended:</strong> Reinstall or update the plugin. Plugin updates now bundle the SDK (the release zip ships a pre-built <code>vendor/</code> directory), so a fresh install or update is the simplest fix.</p>
<p style="margin-top: 10px;"><strong>Legacy / manual install:</strong> If you can't update the plugin, you can install the SDK to the external location instead:</p>
<code>chmod +x install-twilio-sdk-external.sh && ./install-twilio-sdk-external.sh</code> <code>chmod +x install-twilio-sdk-external.sh && ./install-twilio-sdk-external.sh</code>
<p style="margin-top: 10px;"><strong>Alternative:</strong> Install SDK inside plugin folder:</p>
<code>chmod +x install-twilio-sdk.sh && ./install-twilio-sdk.sh</code>
<p style="margin-top: 10px;"><em>Plugin path: <?php echo esc_html(TWP_PLUGIN_DIR); ?></em></p> <p style="margin-top: 10px;"><em>Plugin path: <?php echo esc_html(TWP_PLUGIN_DIR); ?></em></p>
<p><em>External SDK path: <?php echo esc_html(TWP_EXTERNAL_SDK_DIR); ?></em></p> <p><em>Bundled vendor path: <?php echo esc_html(TWP_PLUGIN_DIR . 'vendor/'); ?></em></p>
<p><em>External SDK fallback path: <?php echo esc_html(TWP_EXTERNAL_SDK_DIR); ?></em></p>
</div>
<?php
}
/**
* Display admin notice for missing AWS SDK (only fired when SNS provider is selected)
*/
function twp_aws_sdk_missing_notice() {
?>
<div class="notice notice-error is-dismissible">
<h3>Twilio WordPress Plugin - AWS SDK Required for SNS SMS</h3>
<p><strong>You have selected AWS SNS as your SMS provider, but the AWS PHP SDK is not available.</strong></p>
<p><strong>Recommended:</strong> Update the plugin to a release-bundled version — newer release zips bundle the AWS SDK alongside the Twilio SDK in <code>vendor/</code>.</p>
<p style="margin-top: 10px;"><strong>Legacy / manual install:</strong> Install the AWS SDK to the external location:</p>
<code>chmod +x install-aws-sdk-external.sh && ./install-aws-sdk-external.sh</code>
<p style="margin-top: 10px;"><em>External AWS SDK path: <?php echo esc_html(TWP_EXTERNAL_AWS_SDK_DIR); ?></em></p>
<p><em>If you don't need AWS SNS, switch the SMS provider back to Twilio under the plugin settings.</em></p>
</div> </div>
<?php <?php
} }
@@ -142,7 +189,8 @@ register_deactivation_hook(__FILE__, 'twp_deactivate');
/** /**
* Check SDK status after plugin updates * Check SDK status after plugin updates
* Shows warning if SDK was deleted during update and external SDK not available * Shows warning if neither the bundled vendor/ nor the external SDK is available
* after an update — this should be rare now that release zips ship vendor/.
*/ */
function twp_check_sdk_after_update($upgrader_object, $options) { function twp_check_sdk_after_update($upgrader_object, $options) {
// Only run for plugin updates // Only run for plugin updates
@@ -156,11 +204,11 @@ function twp_check_sdk_after_update($upgrader_object, $options) {
return; return;
} }
// Check if SDK is available // Check if a Twilio SDK autoloader is available anywhere
$external_sdk = file_exists(TWP_EXTERNAL_SDK_DIR . 'autoload.php');
$internal_sdk = file_exists(TWP_PLUGIN_DIR . 'vendor/autoload.php'); $internal_sdk = file_exists(TWP_PLUGIN_DIR . 'vendor/autoload.php');
$external_sdk = file_exists(TWP_EXTERNAL_SDK_DIR . 'autoload.php');
if (!$external_sdk && !$internal_sdk) { if (!$internal_sdk && !$external_sdk) {
// Set a transient to show warning on next admin page load // Set a transient to show warning on next admin page load
set_transient('twp_sdk_update_warning', true, 60 * 5); set_transient('twp_sdk_update_warning', true, 60 * 5);
} }
@@ -175,11 +223,13 @@ function twp_show_sdk_update_warning() {
delete_transient('twp_sdk_update_warning'); delete_transient('twp_sdk_update_warning');
?> ?>
<div class="notice notice-warning is-dismissible"> <div class="notice notice-warning is-dismissible">
<h3>Twilio WordPress Plugin - SDK Reinstall Required</h3> <h3>Twilio WordPress Plugin - SDK Missing After Update</h3>
<p><strong>The plugin was updated and the Twilio SDK needs to be reinstalled.</strong></p> <p><strong>The plugin was updated, but no Twilio SDK could be found.</strong></p>
<p>To prevent this in the future, install the SDK to the external location:</p> <p>Plugin release zips normally bundle the SDK in <code>vendor/</code>, so this usually means the release was built without dependencies, or the upload was incomplete. Try downloading the release zip again and reinstalling.</p>
<p style="margin-top: 10px;"><strong>Manual install fallback:</strong></p>
<code>cd <?php echo esc_html(TWP_PLUGIN_DIR); ?> && ./install-twilio-sdk-external.sh</code> <code>cd <?php echo esc_html(TWP_PLUGIN_DIR); ?> && ./install-twilio-sdk-external.sh</code>
<p style="margin-top: 10px;">The external SDK at <code><?php echo esc_html(TWP_EXTERNAL_SDK_DIR); ?></code> survives plugin updates.</p> <p style="margin-top: 10px;"><em>Bundled vendor path: <?php echo esc_html(TWP_PLUGIN_DIR . 'vendor/'); ?></em></p>
<p><em>External SDK fallback path: <?php echo esc_html(TWP_EXTERNAL_SDK_DIR); ?></em></p>
</div> </div>
<?php <?php
} }