This commit is contained in:
alorig
2025-11-22 14:34:28 +05:00
parent 029c66a0f1
commit 3b3be535d6
15 changed files with 3122 additions and 140 deletions

View File

@@ -63,10 +63,7 @@ class Igny8Admin {
*/
public function register_settings() {
register_setting('igny8_settings', 'igny8_email');
register_setting('igny8_settings', 'igny8_site_id', array(
'type' => 'integer',
'sanitize_callback' => 'absint'
));
register_setting('igny8_settings', 'igny8_site_id');
register_setting('igny8_settings', 'igny8_enable_two_way_sync', array(
'type' => 'boolean',
'sanitize_callback' => array($this, 'sanitize_boolean'),
@@ -85,6 +82,12 @@ class Igny8Admin {
'default' => array_keys(igny8_get_supported_post_types())
));
register_setting('igny8_bridge_controls', 'igny8_enabled_taxonomies', array(
'type' => 'array',
'sanitize_callback' => array($this, 'sanitize_taxonomies'),
'default' => array('category', 'post_tag', 'product_cat', 'igny8_sectors', 'igny8_clusters')
));
register_setting('igny8_bridge_controls', 'igny8_enable_woocommerce', array(
'type' => 'boolean',
'sanitize_callback' => array($this, 'sanitize_boolean'),
@@ -278,33 +281,11 @@ class Igny8Admin {
}
}
// Try to get site ID by matching current site URL
// Try to get site ID (if available) using the authenticated client
$site_response = $api->get('/system/sites/');
if ($site_response['success'] && !empty($site_response['results'])) {
$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'] . ')');
}
$site = $site_response['results'][0];
update_option('igny8_site_id', $site['id']);
}
add_settings_error(
@@ -568,6 +549,31 @@ class Igny8Admin {
return !empty($clean) ? $clean : $supported;
}
/**
* Sanitize taxonomies option
*
* @param mixed $value Raw value
* @return array
*/
public function sanitize_taxonomies($value) {
$supported = array_keys(igny8_get_supported_taxonomies());
if (!is_array($value)) {
return array('category', 'post_tag', 'product_cat', 'igny8_sectors', 'igny8_clusters');
}
$clean = array();
foreach ($value as $taxonomy) {
$taxonomy = sanitize_key($taxonomy);
if (in_array($taxonomy, $supported, true)) {
$clean[] = $taxonomy;
}
}
// Return defaults if nothing selected
return !empty($clean) ? $clean : array('category', 'post_tag');
}
/**
* Sanitize boolean option
*

View File

@@ -41,6 +41,8 @@ $next_site_sync = wp_next_scheduled('igny8_sync_site_data');
$next_site_sync_formatted = $next_site_sync ? date_i18n($date_format . ' ' . $time_format, $next_site_sync) : __('Not scheduled', 'igny8-bridge');
$available_post_types = igny8_get_supported_post_types();
$enabled_post_types = igny8_get_enabled_post_types();
$available_taxonomies = igny8_get_supported_taxonomies();
$enabled_taxonomies = igny8_get_enabled_taxonomies();
$control_mode = igny8_get_control_mode();
$woocommerce_enabled = (int) get_option('igny8_enable_woocommerce', class_exists('WooCommerce') ? 1 : 0);
$woocommerce_detected = class_exists('WooCommerce');
@@ -214,30 +216,7 @@ $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); ?>
<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>
<td><?php echo esc_html($site_id); ?></td>
</tr>
<?php endif; ?>
</table>
@@ -422,7 +401,7 @@ $webhook_logs = igny8_get_webhook_logs(array('limit' => 10));
</td>
</tr>
<tr>
<th scope="row"><?php _e('WooCommerce Data', 'igny8-bridge'); ?></th>
<th scope="row"><?php _e('WooCommerce Products', 'igny8-bridge'); ?></th>
<td>
<label>
<input
@@ -432,7 +411,7 @@ $webhook_logs = igny8_get_webhook_logs(array('limit' => 10));
<?php checked($woocommerce_enabled, 1); ?>
<?php disabled(!$woocommerce_detected); ?>
/>
<?php _e('Include products, categories, and inventory during site scans.', 'igny8-bridge'); ?>
<?php _e('Sync WooCommerce products and categories.', 'igny8-bridge'); ?>
</label>
<?php if (!$woocommerce_detected) : ?>
<p class="description">
@@ -442,32 +421,22 @@ $webhook_logs = igny8_get_webhook_logs(array('limit' => 10));
</td>
</tr>
<tr>
<th scope="row">Taxonomy ID</th>
<th scope="row"><?php _e('Taxonomies to Sync', 'igny8-bridge'); ?></th>
<td>
<input
type="text"
id="igny8_taxonomy_id"
name="igny8_taxonomy_id"
value="<?php echo esc_attr(get_option('igny8_taxonomy_id', '')); ?>"
class="regular-text"
/>
<?php foreach ($available_taxonomies as $taxonomy_slug => $taxonomy_label) : ?>
<label>
<input
type="checkbox"
name="igny8_enabled_taxonomies[]"
value="<?php echo esc_attr($taxonomy_slug); ?>"
<?php checked(in_array($taxonomy_slug, $enabled_taxonomies, true)); ?>
/>
<?php echo esc_html($taxonomy_label); ?> (<?php echo esc_html($taxonomy_slug); ?>)
</label>
<br />
<?php endforeach; ?>
<p class="description">
<?php _e('The taxonomy ID used for IGNY8 synchronization.', 'igny8-bridge'); ?>
</p>
</td>
</tr>
<tr>
<th scope="row">Attribute ID</th>
<td>
<input
type="text"
id="igny8_attribute_id"
name="igny8_attribute_id"
value="<?php echo esc_attr(get_option('igny8_attribute_id', '')); ?>"
class="regular-text"
/>
<p class="description">
<?php _e('The attribute ID used for IGNY8 synchronization.', 'igny8-bridge'); ?>
<?php _e('Select which taxonomies to synchronize bidirectionally with IGNY8.', 'igny8-bridge'); ?>
</p>
</td>
</tr>