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

@@ -77,13 +77,6 @@ class Igny8RestAPI {
'callback' => array($this, 'get_site_metadata'),
'permission_callback' => '__return_true',
));
// Status endpoint for health checks (public)
register_rest_route('igny8/v1', '/status', array(
'methods' => 'GET',
'callback' => array($this, 'get_plugin_status'),
'permission_callback' => '__return_true', // Public endpoint for health checks
));
}
/**
@@ -426,60 +419,6 @@ class Igny8RestAPI {
return $this->build_unified_response(true, $data, 'Site metadata retrieved', null, null, 200);
}
/**
* Get plugin status for health checks
*
* @param WP_REST_Request $request Request object
* @return WP_REST_Response
*/
public function get_plugin_status($request) {
// Get plugin configuration status
$api_key = function_exists('igny8_get_secure_option') ? igny8_get_secure_option('igny8_api_key') : get_option('igny8_api_key');
$access_token = function_exists('igny8_get_secure_option') ? igny8_get_secure_option('igny8_access_token') : get_option('igny8_access_token');
$email = get_option('igny8_email', '');
$site_id = get_option('igny8_site_id', '');
$connection_enabled = igny8_is_connection_enabled();
$two_way_sync = (int) get_option('igny8_enable_two_way_sync', 1);
// Check if plugin is configured
$has_api_key = !empty($api_key);
$has_access_token = !empty($access_token);
$has_site_id = !empty($site_id);
$is_configured = $has_api_key && $has_access_token && $has_site_id && $connection_enabled;
// Get last sync times
$last_site_sync = intval(get_option('igny8_last_site_sync', 0));
$last_structure_sync = intval(get_option('igny8_last_structure_sync', 0));
// Determine plugin status
$status = 'not_configured';
if ($is_configured && ($last_site_sync > 0 || $last_structure_sync > 0)) {
$status = 'active';
} elseif ($is_configured) {
$status = 'configured';
} elseif ($has_api_key || $has_access_token) {
$status = 'partial';
}
// Build response
return rest_ensure_response(array(
'plugin' => 'IGNY8 WordPress Bridge',
'version' => defined('IGNY8_BRIDGE_VERSION') ? IGNY8_BRIDGE_VERSION : 'unknown',
'status' => $status,
'connected' => $is_configured,
'has_api_key' => $has_api_key,
'has_site_id' => $has_site_id,
'connection_enabled' => $connection_enabled,
'two_way_sync_enabled' => (bool) $two_way_sync,
'last_site_sync' => $last_site_sync > 0 ? gmdate('Y-m-d\TH:i:s\Z', $last_site_sync) : null,
'last_structure_sync' => $last_structure_sync > 0 ? gmdate('Y-m-d\TH:i:s\Z', $last_structure_sync) : null,
'can_reach_igny8' => $last_site_sync > 0 || $last_structure_sync > 0, // If we've synced, we can reach IGNY8
'timestamp' => current_time('mysql'),
'site_url' => get_site_url(),
'site_name' => get_bloginfo('name'),
));
}
}
// Initialize REST API

View File

@@ -158,6 +158,100 @@ function igny8_get_control_mode() {
return in_array($mode, array('mirror', 'hybrid'), true) ? $mode : 'mirror';
}
/**
* Get supported taxonomies for syncing
*
* @return array Key => label
*/
function igny8_get_supported_taxonomies() {
$taxonomies = array();
// Standard WordPress taxonomies
if (taxonomy_exists('category')) {
$taxonomies['category'] = __('Categories', 'igny8-bridge');
}
if (taxonomy_exists('post_tag')) {
$taxonomies['post_tag'] = __('Tags', 'igny8-bridge');
}
// WooCommerce taxonomies
if (taxonomy_exists('product_cat')) {
$taxonomies['product_cat'] = __('Product Categories', 'igny8-bridge');
}
if (taxonomy_exists('product_tag')) {
$taxonomies['product_tag'] = __('Product Tags', 'igny8-bridge');
}
if (taxonomy_exists('product_shipping_class')) {
$taxonomies['product_shipping_class'] = __('Product Shipping Classes', 'igny8-bridge');
}
// IGNY8 taxonomies (always include)
if (taxonomy_exists('igny8_sectors')) {
$taxonomies['igny8_sectors'] = __('IGNY8 Sectors', 'igny8-bridge');
}
if (taxonomy_exists('igny8_clusters')) {
$taxonomies['igny8_clusters'] = __('IGNY8 Clusters', 'igny8-bridge');
}
// Get custom taxonomies (public only)
$custom_taxonomies = get_taxonomies(array(
'public' => true,
'_builtin' => false
), 'objects');
foreach ($custom_taxonomies as $taxonomy) {
// Skip if already added above
if (isset($taxonomies[$taxonomy->name])) {
continue;
}
// Skip post formats and other system taxonomies
if (in_array($taxonomy->name, array('post_format', 'wp_theme', 'wp_template_part_area'), true)) {
continue;
}
$taxonomies[$taxonomy->name] = $taxonomy->label;
}
/**
* Filter the list of selectable taxonomies.
*
* @param array $taxonomies
*/
return apply_filters('igny8_supported_taxonomies', $taxonomies);
}
/**
* Get enabled taxonomies for syncing
*
* @return array
*/
function igny8_get_enabled_taxonomies() {
$saved = get_option('igny8_enabled_taxonomies');
if (is_array($saved) && !empty($saved)) {
return $saved;
}
// Default: enable common taxonomies
return array('category', 'post_tag', 'product_cat', 'igny8_sectors', 'igny8_clusters');
}
/**
* Check if a taxonomy is enabled for syncing
*
* @param string $taxonomy Taxonomy key
* @return bool
*/
function igny8_is_taxonomy_enabled($taxonomy) {
$taxonomies = igny8_get_enabled_taxonomies();
return in_array($taxonomy, $taxonomies, true);
}
/**
* Get available automation modules
*