This commit is contained in:
alorig
2025-11-22 12:38:12 +05:00
parent 3d3ac0647e
commit 3fb86eacf1
3 changed files with 371 additions and 5 deletions

View File

@@ -63,7 +63,10 @@ class Igny8Admin {
*/
public function register_settings() {
register_setting('igny8_settings', 'igny8_email');
register_setting('igny8_settings', 'igny8_site_id');
register_setting('igny8_settings', 'igny8_site_id', array(
'type' => 'integer',
'sanitize_callback' => 'absint'
));
register_setting('igny8_settings', 'igny8_enable_two_way_sync', array(
'type' => 'boolean',
'sanitize_callback' => array($this, 'sanitize_boolean'),
@@ -275,11 +278,33 @@ class Igny8Admin {
}
}
// Try to get site ID (if available) using the authenticated client
// Try to get site ID by matching current site URL
$site_response = $api->get('/system/sites/');
if ($site_response['success'] && !empty($site_response['results'])) {
$site = $site_response['results'][0];
update_option('igny8_site_id', $site['id']);
$current_site_url = get_site_url();
$current_domain = parse_url($current_site_url, PHP_URL_HOST);
// Try to find matching site by domain
$matched_site = null;
foreach ($site_response['results'] as $site) {
if (!empty($site['domain'])) {
$site_domain = parse_url($site['domain'], PHP_URL_HOST);
if ($site_domain === $current_domain) {
$matched_site = $site;
break;
}
}
}
// Fallback to first site if no match found
if ($matched_site) {
update_option('igny8_site_id', $matched_site['id']);
error_log('IGNY8: Matched site by domain: ' . $matched_site['name'] . ' (ID: ' . $matched_site['id'] . ')');
} else {
$site = $site_response['results'][0];
update_option('igny8_site_id', $site['id']);
error_log('IGNY8: No domain match, using first site: ' . $site['name'] . ' (ID: ' . $site['id'] . ')');
}
}
add_settings_error(

View File

@@ -214,7 +214,30 @@ $webhook_logs = igny8_get_webhook_logs(array('limit' => 10));
<?php if ($site_id) : ?>
<tr>
<th scope="row"><?php _e('Site ID', 'igny8-bridge'); ?></th>
<td><?php echo esc_html($site_id); ?></td>
<td>
<?php echo esc_html($site_id); ?>
<p class="description">
<?php _e('Auto-detected from your IGNY8 account. If incorrect, reconnect or manually enter below.', 'igny8-bridge'); ?>
</p>
</td>
</tr>
<?php else : ?>
<tr>
<th scope="row">
<label for="igny8_site_id_manual"><?php _e('Site ID (Manual)', 'igny8-bridge'); ?></label>
</th>
<td>
<input
type="number"
id="igny8_site_id_manual"
name="igny8_site_id"
value=""
class="regular-text"
/>
<p class="description">
<?php _e('If auto-detection failed, manually enter your IGNY8 Site ID here. You can find it in the IGNY8 app URL: /sites/{site_id}/...', 'igny8-bridge'); ?>
</p>
</td>
</tr>
<?php endif; ?>
</table>