Compare commits
4 Commits
2026.03.07
...
2026.03.07
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
78e6c5a4ee | ||
|
|
eedb7bdb8f | ||
|
|
f8c9c23077 | ||
|
|
5d3035a62c |
@@ -1,53 +0,0 @@
|
||||
name: Update Plugin Version
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [created, edited]
|
||||
|
||||
jobs:
|
||||
update-version:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Get release tag
|
||||
id: get_tag
|
||||
run: echo "TAG=${GITEA_REF#refs/tags/}" >> $GITEA_ENV
|
||||
|
||||
- name: Update version in plugin file
|
||||
run: |
|
||||
# Replace version in main plugin file (both header and constant)
|
||||
sed -i "s/Version: {auto_update_value_on_deploy}/Version: ${{ env.TAG }}/" twilio-wp-plugin.php
|
||||
sed -i "s/TWP_VERSION', '{auto_update_value_on_deploy}/TWP_VERSION', '${{ env.TAG }}/" twilio-wp-plugin.php
|
||||
|
||||
# Verify changes
|
||||
grep "Version:" twilio-wp-plugin.php
|
||||
grep "TWP_VERSION" twilio-wp-plugin.php
|
||||
|
||||
- name: Commit changes
|
||||
run: |
|
||||
git config --local user.email "action@gitea.com"
|
||||
git config --local user.name "Gitea Action"
|
||||
git add twilio-wp-plugin.php
|
||||
git commit -m "Update version to ${{ env.TAG }}" || echo "No changes to commit"
|
||||
git push || echo "Nothing to push"
|
||||
|
||||
- name: Create plugin zip
|
||||
run: |
|
||||
mkdir -p /tmp/twilio-wp-plugin
|
||||
rsync -av --exclude=".git" --exclude=".gitea" --exclude="build" . /tmp/twilio-wp-plugin/
|
||||
cd /tmp
|
||||
zip -r $GITEA_WORK_DIR/twilio-wp-plugin.zip twilio-wp-plugin
|
||||
|
||||
- name: Upload zip to release
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ gitea.event.release.upload_url }}
|
||||
asset_path: twilio-wp-plugin.zip
|
||||
asset_name: twilio-wp-plugin.zip
|
||||
asset_content_type: application/zip
|
||||
@@ -1580,10 +1580,127 @@ class TWP_Admin {
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<hr>
|
||||
|
||||
<h2>Automatic Updates</h2>
|
||||
<?php
|
||||
require_once TWP_PLUGIN_DIR . 'includes/class-twp-auto-updater.php';
|
||||
$updater = new TWP_Auto_Updater();
|
||||
|
||||
// Handle manual update check
|
||||
if (isset($_POST['twp_check_updates']) && check_admin_referer('twp_update_settings')) {
|
||||
$update_result = $updater->manual_check_for_updates();
|
||||
if (isset($update_result)) {
|
||||
echo '<div class="notice notice-' . ($update_result['update_available'] ? 'warning' : 'success') . ' is-dismissible">';
|
||||
echo '<p><strong>' . esc_html($update_result['message']) . '</strong></p></div>';
|
||||
}
|
||||
}
|
||||
|
||||
// Handle save update settings
|
||||
if (isset($_POST['twp_save_update_settings']) && check_admin_referer('twp_update_settings')) {
|
||||
update_option('twp_auto_update_enabled', isset($_POST['twp_auto_update_enabled']) ? '1' : '0');
|
||||
update_option('twp_gitea_repo', sanitize_text_field($_POST['twp_gitea_repo']));
|
||||
update_option('twp_gitea_token', sanitize_text_field($_POST['twp_gitea_token']));
|
||||
echo '<div class="notice notice-success is-dismissible"><p><strong>Update settings saved.</strong></p></div>';
|
||||
}
|
||||
|
||||
$update_status = $updater->get_update_status();
|
||||
$auto_update_enabled = get_option('twp_auto_update_enabled', '1') === '1';
|
||||
$gitea_repo = get_option('twp_gitea_repo', 'wp-plugins/twilio-wp-plugin');
|
||||
$gitea_token = get_option('twp_gitea_token', '');
|
||||
?>
|
||||
<form method="post" action="">
|
||||
<?php wp_nonce_field('twp_update_settings'); ?>
|
||||
<div class="card">
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row">Current Version</th>
|
||||
<td>
|
||||
<strong><?php echo esc_html($update_status['current_version']); ?></strong>
|
||||
<?php if ($update_status['update_available']): ?>
|
||||
<span style="color: #d63638; margin-left: 10px;">
|
||||
Update available: <?php echo esc_html($update_status['latest_version']); ?>
|
||||
</span>
|
||||
<?php else: ?>
|
||||
<span style="color: #00a32a; margin-left: 10px;">Up to date</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="twp_auto_update_enabled">Enable Auto-Updates</label>
|
||||
</th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox"
|
||||
id="twp_auto_update_enabled"
|
||||
name="twp_auto_update_enabled"
|
||||
value="1"
|
||||
<?php checked($auto_update_enabled); ?>>
|
||||
Automatically check for updates every 12 hours
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="twp_gitea_repo">Gitea Repository</label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="text"
|
||||
id="twp_gitea_repo"
|
||||
name="twp_gitea_repo"
|
||||
value="<?php echo esc_attr($gitea_repo); ?>"
|
||||
class="regular-text"
|
||||
placeholder="org/repo-name">
|
||||
<p class="description">
|
||||
Format: organization/repository (e.g., wp-plugins/twilio-wp-plugin)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="twp_gitea_token">Gitea Access Token</label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="password"
|
||||
id="twp_gitea_token"
|
||||
name="twp_gitea_token"
|
||||
value="<?php echo esc_attr($gitea_token); ?>"
|
||||
class="regular-text">
|
||||
<p class="description">
|
||||
Optional. Required only for private repositories.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Last Update Check</th>
|
||||
<td>
|
||||
<?php
|
||||
$last_check = $update_status['last_check'];
|
||||
if ($last_check > 0) {
|
||||
echo esc_html(human_time_diff($last_check, current_time('timestamp')) . ' ago');
|
||||
} else {
|
||||
echo 'Never';
|
||||
}
|
||||
?>
|
||||
<button type="submit" name="twp_check_updates" class="button" style="margin-left: 15px;">
|
||||
Check Now
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
<button type="submit" name="twp_save_update_settings" class="button button-primary">
|
||||
Save Update Settings
|
||||
</button>
|
||||
</p>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display schedules page
|
||||
*/
|
||||
|
||||
@@ -13,13 +13,6 @@ if (!current_user_can('manage_options')) {
|
||||
wp_die(__('You do not have sufficient permissions to access this page.'));
|
||||
}
|
||||
|
||||
// Handle manual update check
|
||||
if (isset($_POST['twp_check_updates']) && check_admin_referer('twp_mobile_settings')) {
|
||||
require_once TWP_PLUGIN_DIR . 'includes/class-twp-auto-updater.php';
|
||||
$updater = new TWP_Auto_Updater();
|
||||
$update_result = $updater->manual_check_for_updates();
|
||||
}
|
||||
|
||||
// Handle test notification
|
||||
if (isset($_POST['twp_test_notification']) && check_admin_referer('twp_mobile_settings')) {
|
||||
require_once TWP_PLUGIN_DIR . 'includes/class-twp-fcm.php';
|
||||
@@ -49,10 +42,6 @@ if (isset($_POST['twp_save_mobile_settings']) && check_admin_referer('twp_mobile
|
||||
} else {
|
||||
update_option('twp_fcm_service_account_json', '');
|
||||
}
|
||||
update_option('twp_auto_update_enabled', isset($_POST['twp_auto_update_enabled']) ? '1' : '0');
|
||||
update_option('twp_gitea_repo', sanitize_text_field($_POST['twp_gitea_repo']));
|
||||
update_option('twp_gitea_token', sanitize_text_field($_POST['twp_gitea_token']));
|
||||
|
||||
$settings_saved = true;
|
||||
}
|
||||
|
||||
@@ -60,15 +49,6 @@ if (isset($_POST['twp_save_mobile_settings']) && check_admin_referer('twp_mobile
|
||||
$fcm_project_id = get_option('twp_fcm_project_id', '');
|
||||
$fcm_service_account_json = get_option('twp_fcm_service_account_json', '');
|
||||
$fcm_sa_configured = !empty($fcm_service_account_json) && !empty($fcm_project_id);
|
||||
$auto_update_enabled = get_option('twp_auto_update_enabled', '1') === '1';
|
||||
$gitea_repo = get_option('twp_gitea_repo', 'wp-plugins/twilio-wp-plugin');
|
||||
$gitea_token = get_option('twp_gitea_token', '');
|
||||
|
||||
// Get update status
|
||||
require_once TWP_PLUGIN_DIR . 'includes/class-twp-auto-updater.php';
|
||||
$updater = new TWP_Auto_Updater();
|
||||
$update_status = $updater->get_update_status();
|
||||
|
||||
// Get mobile app statistics
|
||||
global $wpdb;
|
||||
$sessions_table = $wpdb->prefix . 'twp_mobile_sessions';
|
||||
@@ -86,12 +66,6 @@ $total_sessions = $wpdb->get_var("SELECT COUNT(*) FROM $sessions_table");
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (isset($update_result)): ?>
|
||||
<div class="notice notice-<?php echo $update_result['update_available'] ? 'warning' : 'success'; ?> is-dismissible">
|
||||
<p><strong><?php echo esc_html($update_result['message']); ?></strong></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (isset($notification_result)): ?>
|
||||
<div class="notice notice-<?php echo $notification_result['success'] ? 'success' : 'error'; ?> is-dismissible">
|
||||
<p><strong><?php echo esc_html($notification_result['message']); ?></strong></p>
|
||||
@@ -183,91 +157,6 @@ $total_sessions = $wpdb->get_var("SELECT COUNT(*) FROM $sessions_table");
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<!-- Auto-Update Settings -->
|
||||
<div class="card" style="max-width: 100%; margin-bottom: 20px;">
|
||||
<h2>Automatic Updates</h2>
|
||||
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row">Current Version</th>
|
||||
<td>
|
||||
<strong><?php echo esc_html($update_status['current_version']); ?></strong>
|
||||
<?php if ($update_status['update_available']): ?>
|
||||
<span style="color: #d63638; margin-left: 10px;">
|
||||
⚠ Update available: <?php echo esc_html($update_status['latest_version']); ?>
|
||||
</span>
|
||||
<?php else: ?>
|
||||
<span style="color: #00a32a; margin-left: 10px;">✓ Up to date</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="twp_auto_update_enabled">Enable Auto-Updates</label>
|
||||
</th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox"
|
||||
id="twp_auto_update_enabled"
|
||||
name="twp_auto_update_enabled"
|
||||
value="1"
|
||||
<?php checked($auto_update_enabled); ?>>
|
||||
Automatically check for updates every 12 hours
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="twp_gitea_repo">Gitea Repository</label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="text"
|
||||
id="twp_gitea_repo"
|
||||
name="twp_gitea_repo"
|
||||
value="<?php echo esc_attr($gitea_repo); ?>"
|
||||
class="regular-text"
|
||||
placeholder="org/repo-name">
|
||||
<p class="description">
|
||||
Format: organization/repository (e.g., wp-plugins/twilio-wp-plugin)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="twp_gitea_token">Gitea Access Token</label>
|
||||
</th>
|
||||
<td>
|
||||
<input type="password"
|
||||
id="twp_gitea_token"
|
||||
name="twp_gitea_token"
|
||||
value="<?php echo esc_attr($gitea_token); ?>"
|
||||
class="regular-text"
|
||||
placeholder="">
|
||||
<p class="description">
|
||||
Optional. Required only for private repositories. Create token at:
|
||||
<a href="https://repo.anhonesthost.net/user/settings/applications" target="_blank">Gitea Settings > Applications</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Last Update Check</th>
|
||||
<td>
|
||||
<?php
|
||||
$last_check = $update_status['last_check'];
|
||||
if ($last_check > 0) {
|
||||
echo esc_html(human_time_diff($last_check, current_time('timestamp')) . ' ago');
|
||||
} else {
|
||||
echo 'Never';
|
||||
}
|
||||
?>
|
||||
<button type="submit" name="twp_check_updates" class="button" style="margin-left: 15px;">
|
||||
Check Now
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- API Documentation -->
|
||||
<div class="card" style="max-width: 100%; margin-bottom: 20px;">
|
||||
<h2>API Endpoints</h2>
|
||||
|
||||
@@ -19,7 +19,7 @@ class TWP_Auto_Updater {
|
||||
public function __construct() {
|
||||
$this->plugin_basename = plugin_basename(dirname(dirname(__FILE__)) . '/twilio-wp-plugin.php');
|
||||
$this->current_version = defined('TWP_VERSION') ? TWP_VERSION : '0.0.0';
|
||||
$this->gitea_api_url = $this->gitea_base_url . '/api/v1/repos/' . $this->gitea_repo . '/releases/latest';
|
||||
$this->gitea_api_url = $this->gitea_base_url . '/api/v1/repos/' . $this->gitea_repo . '/releases?limit=1&draft=false';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +74,7 @@ class TWP_Auto_Updater {
|
||||
$custom_repo = get_option('twp_gitea_repo', '');
|
||||
if (!empty($custom_repo)) {
|
||||
$this->gitea_repo = $custom_repo;
|
||||
$this->gitea_api_url = $this->gitea_base_url . '/api/v1/repos/' . $this->gitea_repo . '/releases/latest';
|
||||
$this->gitea_api_url = $this->gitea_base_url . '/api/v1/repos/' . $this->gitea_repo . '/releases?limit=1&draft=false';
|
||||
}
|
||||
|
||||
$update_info = $this->get_latest_release();
|
||||
@@ -184,9 +184,16 @@ class TWP_Auto_Updater {
|
||||
return false;
|
||||
}
|
||||
|
||||
$release = json_decode($response);
|
||||
$releases = json_decode($response);
|
||||
|
||||
if (!$release || !isset($release->tag_name)) {
|
||||
if (!$releases || !is_array($releases) || empty($releases)) {
|
||||
error_log('TWP Auto-Updater: No releases found from Gitea');
|
||||
return false;
|
||||
}
|
||||
|
||||
$release = $releases[0];
|
||||
|
||||
if (!isset($release->tag_name)) {
|
||||
error_log('TWP Auto-Updater: Invalid release data from Gitea');
|
||||
return false;
|
||||
}
|
||||
@@ -210,6 +217,12 @@ class TWP_Auto_Updater {
|
||||
$download_url = $release->zipball_url;
|
||||
}
|
||||
|
||||
// Append auth token to download URL for private repos
|
||||
if (!empty($gitea_token) && $download_url) {
|
||||
$separator = (strpos($download_url, '?') !== false) ? '&' : '?';
|
||||
$download_url .= $separator . 'token=' . urlencode($gitea_token);
|
||||
}
|
||||
|
||||
// Format changelog
|
||||
$changelog = !empty($release->body) ? $release->body : 'No changelog provided for this release.';
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ class TWP_Mobile_Auth {
|
||||
private $secret_key;
|
||||
private $token_expiry = 86400; // 24 hours in seconds
|
||||
private $refresh_expiry = 2592000; // 30 days in seconds
|
||||
private $current_user_id = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -330,7 +331,7 @@ class TWP_Mobile_Auth {
|
||||
}
|
||||
|
||||
// Store user ID for later use
|
||||
$request->set_param('_twp_user_id', $payload->user_id);
|
||||
$this->current_user_id = $payload->user_id;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -339,8 +340,7 @@ class TWP_Mobile_Auth {
|
||||
* Get current user ID from token
|
||||
*/
|
||||
public function get_current_user_id() {
|
||||
$request = rest_get_server()->get_request();
|
||||
return $request->get_param('_twp_user_id');
|
||||
return $this->current_user_id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user