229 lines
6.7 KiB
PHP
229 lines
6.7 KiB
PHP
<?php
|
|
/**
|
|
* Plugin Name: IGNY8 WordPress Bridge
|
|
* Plugin URI: https://igny8.com/igny8-wp-bridge
|
|
* Description: Lightweight bridge plugin that connects WordPress to IGNY8 API for one-way content publishing.
|
|
* Version: 1.3.8
|
|
* Author: IGNY8
|
|
* Author URI: https://igny8.com/
|
|
* License: GPL v2 or later
|
|
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
|
* Text Domain: igny8-bridge
|
|
* Domain Path: /languages
|
|
* Requires at least: 5.0
|
|
* Requires PHP: 7.4
|
|
*
|
|
* @package Igny8Bridge
|
|
*/
|
|
|
|
// Prevent direct access
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
// Define plugin constants
|
|
define('IGNY8_BRIDGE_VERSION', '1.3.8');
|
|
define('IGNY8_BRIDGE_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
|
define('IGNY8_BRIDGE_PLUGIN_URL', plugin_dir_url(__FILE__));
|
|
define('IGNY8_BRIDGE_PLUGIN_FILE', __FILE__);
|
|
define('IGNY8_BRIDGE_PLUGIN_BASENAME', plugin_basename(__FILE__));
|
|
|
|
/**
|
|
* Main plugin class
|
|
*/
|
|
class Igny8Bridge {
|
|
|
|
/**
|
|
* Single instance of the class
|
|
*
|
|
* @var Igny8Bridge
|
|
*/
|
|
private static $instance = null;
|
|
|
|
/**
|
|
* Get single instance
|
|
*
|
|
* @return Igny8Bridge
|
|
*/
|
|
public static function get_instance() {
|
|
if (null === self::$instance) {
|
|
self::$instance = new self();
|
|
}
|
|
return self::$instance;
|
|
}
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
private function __construct() {
|
|
$this->init();
|
|
}
|
|
|
|
/**
|
|
* Initialize plugin
|
|
*/
|
|
private function init() {
|
|
// Load core files
|
|
$this->load_dependencies();
|
|
|
|
// Initialize hooks
|
|
add_action('plugins_loaded', array($this, 'load_plugin_textdomain'));
|
|
add_action('init', array($this, 'init_plugin'));
|
|
|
|
// Activation/Deactivation hooks
|
|
register_activation_hook(__FILE__, array($this, 'activate'));
|
|
register_deactivation_hook(__FILE__, array($this, 'deactivate'));
|
|
}
|
|
|
|
/**
|
|
* Load plugin dependencies
|
|
*/
|
|
private function load_dependencies() {
|
|
// Core classes
|
|
require_once IGNY8_BRIDGE_PLUGIN_DIR . 'includes/functions.php';
|
|
require_once IGNY8_BRIDGE_PLUGIN_DIR . 'includes/class-igny8-logger.php'; // Load logger first
|
|
require_once IGNY8_BRIDGE_PLUGIN_DIR . 'includes/class-igny8-api.php';
|
|
require_once IGNY8_BRIDGE_PLUGIN_DIR . 'includes/class-igny8-site.php';
|
|
require_once IGNY8_BRIDGE_PLUGIN_DIR . 'includes/class-igny8-rest-api.php';
|
|
require_once IGNY8_BRIDGE_PLUGIN_DIR . 'includes/class-igny8-updater.php';
|
|
// Webhooks removed - using API key authentication only
|
|
|
|
// Webhook logs (used in admin and frontend)
|
|
require_once IGNY8_BRIDGE_PLUGIN_DIR . 'includes/class-igny8-webhook-logs.php';
|
|
|
|
// Template functions and loader (for frontend content display)
|
|
require_once IGNY8_BRIDGE_PLUGIN_DIR . 'includes/template-functions.php';
|
|
require_once IGNY8_BRIDGE_PLUGIN_DIR . 'includes/class-igny8-template-loader.php';
|
|
|
|
// Admin classes (only in admin)
|
|
if (is_admin()) {
|
|
require_once IGNY8_BRIDGE_PLUGIN_DIR . 'admin/class-admin.php';
|
|
require_once IGNY8_BRIDGE_PLUGIN_DIR . 'admin/class-admin-columns.php';
|
|
require_once IGNY8_BRIDGE_PLUGIN_DIR . 'admin/class-post-meta-boxes.php';
|
|
}
|
|
|
|
// IGNY8 to WordPress publishing (one-way only)
|
|
require_once IGNY8_BRIDGE_PLUGIN_DIR . 'sync/igny8-to-wp.php';
|
|
|
|
// Data collection
|
|
require_once IGNY8_BRIDGE_PLUGIN_DIR . 'data/site-collection.php';
|
|
require_once IGNY8_BRIDGE_PLUGIN_DIR . 'data/semantic-mapping.php';
|
|
require_once IGNY8_BRIDGE_PLUGIN_DIR . 'data/link-graph.php';
|
|
}
|
|
|
|
/**
|
|
* Load plugin textdomain
|
|
*/
|
|
public function load_plugin_textdomain() {
|
|
load_plugin_textdomain(
|
|
'igny8-bridge',
|
|
false,
|
|
dirname(IGNY8_BRIDGE_PLUGIN_BASENAME) . '/languages'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Initialize plugin functionality
|
|
*/
|
|
public function init_plugin() {
|
|
// Register post meta fields
|
|
igny8_register_post_meta();
|
|
|
|
// Register taxonomies
|
|
igny8_register_taxonomies();
|
|
|
|
// Initialize admin (if in admin)
|
|
if (is_admin()) {
|
|
Igny8Admin::get_instance();
|
|
}
|
|
|
|
// Initialize auto-updater
|
|
if (class_exists('Igny8_Updater')) {
|
|
new Igny8_Updater(
|
|
IGNY8_BRIDGE_PLUGIN_FILE,
|
|
IGNY8_BRIDGE_VERSION,
|
|
'https://api.igny8.com/api/plugins/'
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Plugin activation
|
|
*/
|
|
public function activate() {
|
|
// Register post meta and taxonomies
|
|
igny8_register_post_meta();
|
|
igny8_register_taxonomies();
|
|
|
|
// Flush rewrite rules
|
|
flush_rewrite_rules();
|
|
|
|
// Set default options
|
|
if (!get_option('igny8_bridge_version')) {
|
|
add_option('igny8_bridge_version', IGNY8_BRIDGE_VERSION);
|
|
}
|
|
|
|
// Set default post status option
|
|
if (!get_option('igny8_default_post_status')) {
|
|
add_option('igny8_default_post_status', 'draft');
|
|
}
|
|
|
|
// Register installation with IGNY8 API
|
|
$this->register_installation();
|
|
}
|
|
|
|
/**
|
|
* Register this plugin installation with IGNY8 API
|
|
*/
|
|
private function register_installation() {
|
|
// Get API key and site ID
|
|
$api_key = get_option('igny8_api_key');
|
|
$site_id = get_option('igny8_site_id');
|
|
|
|
// Skip if not configured yet
|
|
if (empty($api_key) || empty($site_id)) {
|
|
return;
|
|
}
|
|
|
|
// Register installation
|
|
$response = wp_remote_post(
|
|
'https://api.igny8.com/api/plugins/igny8-wp-bridge/register-installation/',
|
|
array(
|
|
'headers' => array(
|
|
'Authorization' => 'Bearer ' . $api_key,
|
|
'Content-Type' => 'application/json',
|
|
),
|
|
'body' => wp_json_encode(array(
|
|
'site_id' => intval($site_id),
|
|
'version' => IGNY8_BRIDGE_VERSION,
|
|
)),
|
|
'timeout' => 15,
|
|
)
|
|
);
|
|
|
|
// Log result (don't fail activation if this fails)
|
|
if (is_wp_error($response)) {
|
|
error_log('IGNY8 Bridge: Failed to register installation - ' . $response->get_error_message());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Plugin deactivation
|
|
*/
|
|
public function deactivate() {
|
|
// Flush rewrite rules
|
|
flush_rewrite_rules();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Initialize plugin
|
|
*/
|
|
function igny8_bridge_init() {
|
|
return Igny8Bridge::get_instance();
|
|
}
|
|
|
|
// Start the plugin
|
|
igny8_bridge_init();
|
|
|