Files
twilio-wp-plugin/twilio-wp-plugin.php
Josh Knapp a3345ed854
All checks were successful
Create Release / build (push) Successful in 3s
Use version placeholder for auto-deployment
Replace hardcoded version with {auto_update_value_on_deploy} placeholder that gets replaced during the Gitea workflow build process.

Changes:
- Updated Version comment to use placeholder
- Updated TWP_VERSION constant to use placeholder
- Modified release workflow to replace both instances of the placeholder

This matches the pattern used in the fourthwall plugin and ensures the version is automatically set during the release build process.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-01 16:32:42 -08:00

142 lines
4.1 KiB
PHP

<?php
/**
* Plugin Name: Twilio WP Plugin
* Plugin URI: https://repo.anhonesthost.net/wp-plugins/twilio-wp-plugin
* Description: WordPress plugin for Twilio integration with phone scheduling, call forwarding, queue management, and Eleven Labs TTS
* Version: {auto_update_value_on_deploy}
* Author: Josh Knapp
* License: GPL v2 or later
* Text Domain: twilio-wp-plugin
*/
// If this file is called directly, abort.
if (!defined('WPINC')) {
die;
}
// Plugin constants
define('TWP_VERSION', '{auto_update_value_on_deploy}');
define('TWP_DB_VERSION', '1.6.2'); // Track database version separately
define('TWP_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('TWP_PLUGIN_URL', plugin_dir_url(__FILE__));
define('TWP_PLUGIN_BASENAME', plugin_basename(__FILE__));
/**
* Plugin activation hook
*/
function twp_activate() {
require_once TWP_PLUGIN_DIR . 'includes/class-twp-activator.php';
TWP_Activator::activate();
}
/**
* Check if Twilio SDK is installed and show admin notice if not
*/
function twp_check_sdk_installation() {
$autoloader_path = TWP_PLUGIN_DIR . 'vendor/autoload.php';
$sdk_installed = false;
if (file_exists($autoloader_path)) {
// Try to load autoloader and check for classes
require_once $autoloader_path;
$sdk_installed = class_exists('Twilio\Rest\Client');
}
if (!$sdk_installed) {
add_action('admin_notices', 'twp_sdk_missing_notice');
}
}
/**
* Display admin notice for missing SDK
*/
function twp_sdk_missing_notice() {
?>
<div class="notice notice-error is-dismissible">
<h3>Twilio WordPress Plugin - SDK Required</h3>
<p><strong>The Twilio PHP SDK is required for this plugin to work.</strong></p>
<p>To install the SDK, run this command in your plugin directory:</p>
<code>chmod +x install-twilio-sdk.sh && ./install-twilio-sdk.sh</code>
<p>Or install via Composer: <code>composer install</code></p>
<p><em>Plugin path: <?php echo TWP_PLUGIN_DIR; ?></em></p>
</div>
<?php
}
// Check SDK installation and database updates on admin pages
if (is_admin()) {
add_action('admin_init', 'twp_check_sdk_installation');
add_action('admin_init', 'twp_check_database_updates');
add_action('admin_init', 'twp_setup_auto_revert_cron');
}
// Hook up cron functions
add_filter('cron_schedules', 'twp_add_cron_interval');
add_action('twp_auto_revert_agents', 'twp_handle_auto_revert_agents');
/**
* Check and perform database updates if needed
*/
function twp_check_database_updates() {
$current_db_version = get_option('twp_db_version', '1.0.0');
if (version_compare($current_db_version, TWP_DB_VERSION, '<')) {
require_once TWP_PLUGIN_DIR . 'includes/class-twp-activator.php';
TWP_Activator::ensure_tables_exist();
update_option('twp_db_version', TWP_DB_VERSION);
}
}
/**
* Setup auto-revert cron job for agent status
*/
function twp_setup_auto_revert_cron() {
if (!wp_next_scheduled('twp_auto_revert_agents')) {
wp_schedule_event(time(), 'twp_every_minute', 'twp_auto_revert_agents');
}
}
/**
* Handle auto-revert cron job
*/
function twp_handle_auto_revert_agents() {
require_once TWP_PLUGIN_DIR . 'includes/class-twp-agent-manager.php';
TWP_Agent_Manager::revert_auto_busy_agents();
}
/**
* Add custom cron schedule
*/
function twp_add_cron_interval($schedules) {
$schedules['twp_every_minute'] = array(
'interval' => 60, // Every 60 seconds
'display' => esc_html__('Every Minute (TWP)', 'twilio-wp-plugin')
);
return $schedules;
}
/**
* Plugin deactivation hook
*/
function twp_deactivate() {
require_once TWP_PLUGIN_DIR . 'includes/class-twp-deactivator.php';
TWP_Deactivator::deactivate();
}
register_activation_hook(__FILE__, 'twp_activate');
register_deactivation_hook(__FILE__, 'twp_deactivate');
/**
* Core plugin class
*/
require plugin_dir_path(__FILE__) . 'includes/class-twp-core.php';
/**
* Begin execution of the plugin
*/
function run_twilio_wp_plugin() {
$plugin = new TWP_Core();
$plugin->run();
}
run_twilio_wp_plugin();