wp plugin loaded
This commit is contained in:
328
igny8-wp-integration-plugin/includes/class-igny8-api.php
Normal file
328
igny8-wp-integration-plugin/includes/class-igny8-api.php
Normal file
@@ -0,0 +1,328 @@
|
||||
<?php
|
||||
/**
|
||||
* IGNY8 API Client Class
|
||||
*
|
||||
* Handles all communication with IGNY8 API v1.0
|
||||
* Follows WORDPRESS-PLUGIN-INTEGRATION.md guidelines
|
||||
*
|
||||
* @package Igny8Bridge
|
||||
*/
|
||||
|
||||
// Prevent direct access
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Igny8API Class
|
||||
*/
|
||||
class Igny8API {
|
||||
|
||||
/**
|
||||
* API base URL
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $base_url = 'https://api.igny8.com/api/v1';
|
||||
|
||||
/**
|
||||
* Access token
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
private $access_token = null;
|
||||
|
||||
/**
|
||||
* Refresh token
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
private $refresh_token = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
if (function_exists('igny8_get_secure_option')) {
|
||||
$this->access_token = igny8_get_secure_option('igny8_access_token');
|
||||
$this->refresh_token = igny8_get_secure_option('igny8_refresh_token');
|
||||
} else {
|
||||
$this->access_token = get_option('igny8_access_token');
|
||||
$this->refresh_token = get_option('igny8_refresh_token');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Login and store tokens
|
||||
*
|
||||
* @param string $email User email
|
||||
* @param string $password User password
|
||||
* @return bool True on success, false on failure
|
||||
*/
|
||||
public function login($email, $password) {
|
||||
$response = wp_remote_post($this->base_url . '/auth/login/', array(
|
||||
'headers' => array(
|
||||
'Content-Type' => 'application/json'
|
||||
),
|
||||
'body' => json_encode(array(
|
||||
'email' => $email,
|
||||
'password' => $password
|
||||
)),
|
||||
'timeout' => 30
|
||||
));
|
||||
|
||||
$body = $this->parse_response($response);
|
||||
|
||||
if ($body['success']) {
|
||||
$this->access_token = $body['data']['access'];
|
||||
$this->refresh_token = $body['data']['refresh'];
|
||||
|
||||
if (function_exists('igny8_store_secure_option')) {
|
||||
igny8_store_secure_option('igny8_access_token', $this->access_token);
|
||||
igny8_store_secure_option('igny8_refresh_token', $this->refresh_token);
|
||||
} else {
|
||||
update_option('igny8_access_token', $this->access_token);
|
||||
update_option('igny8_refresh_token', $this->refresh_token);
|
||||
}
|
||||
update_option('igny8_email', $email);
|
||||
|
||||
// Store token refresh time
|
||||
$timestamp = current_time('timestamp');
|
||||
update_option('igny8_token_refreshed_at', $timestamp);
|
||||
update_option('igny8_access_token_issued', $timestamp);
|
||||
update_option('igny8_last_api_health_check', $timestamp);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh access token
|
||||
*
|
||||
* @return bool True on success, false on failure
|
||||
*/
|
||||
public function refresh_token() {
|
||||
if (!$this->refresh_token) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$response = wp_remote_post($this->base_url . '/auth/refresh/', array(
|
||||
'headers' => array(
|
||||
'Content-Type' => 'application/json'
|
||||
),
|
||||
'body' => json_encode(array(
|
||||
'refresh' => $this->refresh_token
|
||||
)),
|
||||
'timeout' => 30
|
||||
));
|
||||
|
||||
$body = $this->parse_response($response);
|
||||
|
||||
if ($body['success']) {
|
||||
$this->access_token = $body['data']['access'];
|
||||
|
||||
// Refresh token may be updated
|
||||
if (isset($body['data']['refresh'])) {
|
||||
$this->refresh_token = $body['data']['refresh'];
|
||||
if (function_exists('igny8_store_secure_option')) {
|
||||
igny8_store_secure_option('igny8_refresh_token', $this->refresh_token);
|
||||
} else {
|
||||
update_option('igny8_refresh_token', $this->refresh_token);
|
||||
}
|
||||
}
|
||||
|
||||
if (function_exists('igny8_store_secure_option')) {
|
||||
igny8_store_secure_option('igny8_access_token', $this->access_token);
|
||||
} else {
|
||||
update_option('igny8_access_token', $this->access_token);
|
||||
}
|
||||
|
||||
$timestamp = current_time('timestamp');
|
||||
update_option('igny8_token_refreshed_at', $timestamp);
|
||||
update_option('igny8_access_token_issued', $timestamp);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse unified API response
|
||||
*
|
||||
* @param array|WP_Error $response HTTP response
|
||||
* @return array Parsed response
|
||||
*/
|
||||
private function parse_response($response) {
|
||||
if (is_wp_error($response)) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'error' => $response->get_error_message()
|
||||
);
|
||||
}
|
||||
|
||||
$body = json_decode(wp_remote_retrieve_body($response), true);
|
||||
$status_code = wp_remote_retrieve_response_code($response);
|
||||
|
||||
// Handle non-JSON responses
|
||||
if (!$body) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'error' => 'Invalid response format'
|
||||
);
|
||||
}
|
||||
|
||||
// Check if response follows unified format
|
||||
if (isset($body['success'])) {
|
||||
return $body;
|
||||
}
|
||||
|
||||
// Legacy format - wrap in unified format
|
||||
if ($status_code >= 200 && $status_code < 300) {
|
||||
return array(
|
||||
'success' => true,
|
||||
'data' => $body
|
||||
);
|
||||
} else {
|
||||
return array(
|
||||
'success' => false,
|
||||
'error' => $body['detail'] ?? 'Unknown error'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get headers with authentication
|
||||
*
|
||||
* @return array Headers array
|
||||
* @throws Exception If not authenticated
|
||||
*/
|
||||
private function get_headers() {
|
||||
if (!$this->access_token) {
|
||||
throw new Exception('Not authenticated');
|
||||
}
|
||||
|
||||
return array(
|
||||
'Authorization' => 'Bearer ' . $this->access_token,
|
||||
'Content-Type' => 'application/json'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make GET request
|
||||
*
|
||||
* @param string $endpoint API endpoint
|
||||
* @return array Response data
|
||||
*/
|
||||
public function get($endpoint) {
|
||||
$response = wp_remote_get($this->base_url . $endpoint, array(
|
||||
'headers' => $this->get_headers(),
|
||||
'timeout' => 30
|
||||
));
|
||||
|
||||
$body = $this->parse_response($response);
|
||||
|
||||
// Handle 401 - token expired
|
||||
if (!$body['success'] && wp_remote_retrieve_response_code($response) == 401) {
|
||||
// Try to refresh token
|
||||
if ($this->refresh_token()) {
|
||||
// Retry request
|
||||
$response = wp_remote_get($this->base_url . $endpoint, array(
|
||||
'headers' => $this->get_headers(),
|
||||
'timeout' => 30
|
||||
));
|
||||
$body = $this->parse_response($response);
|
||||
}
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make POST request
|
||||
*
|
||||
* @param string $endpoint API endpoint
|
||||
* @param array $data Request data
|
||||
* @return array Response data
|
||||
*/
|
||||
public function post($endpoint, $data) {
|
||||
$response = wp_remote_post($this->base_url . $endpoint, array(
|
||||
'headers' => $this->get_headers(),
|
||||
'body' => json_encode($data),
|
||||
'timeout' => 60
|
||||
));
|
||||
|
||||
$body = $this->parse_response($response);
|
||||
|
||||
// Handle 401 - token expired
|
||||
if (!$body['success'] && wp_remote_retrieve_response_code($response) == 401) {
|
||||
// Try to refresh token
|
||||
if ($this->refresh_token()) {
|
||||
// Retry request
|
||||
$response = wp_remote_post($this->base_url . $endpoint, array(
|
||||
'headers' => $this->get_headers(),
|
||||
'body' => json_encode($data),
|
||||
'timeout' => 60
|
||||
));
|
||||
$body = $this->parse_response($response);
|
||||
}
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make PUT request
|
||||
*
|
||||
* @param string $endpoint API endpoint
|
||||
* @param array $data Request data
|
||||
* @return array Response data
|
||||
*/
|
||||
public function put($endpoint, $data) {
|
||||
$response = wp_remote_request($this->base_url . $endpoint, array(
|
||||
'method' => 'PUT',
|
||||
'headers' => $this->get_headers(),
|
||||
'body' => json_encode($data),
|
||||
'timeout' => 60
|
||||
));
|
||||
|
||||
return $this->parse_response($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make DELETE request
|
||||
*
|
||||
* @param string $endpoint API endpoint
|
||||
* @return array Response data
|
||||
*/
|
||||
public function delete($endpoint) {
|
||||
$response = wp_remote_request($this->base_url . $endpoint, array(
|
||||
'method' => 'DELETE',
|
||||
'headers' => $this->get_headers(),
|
||||
'timeout' => 30
|
||||
));
|
||||
|
||||
return $this->parse_response($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if authenticated
|
||||
*
|
||||
* @return bool True if authenticated
|
||||
*/
|
||||
public function is_authenticated() {
|
||||
return !empty($this->access_token);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get access token
|
||||
*
|
||||
* @return string|null Access token
|
||||
*/
|
||||
public function get_access_token() {
|
||||
return $this->access_token;
|
||||
}
|
||||
}
|
||||
|
||||
202
igny8-wp-integration-plugin/includes/class-igny8-link-queue.php
Normal file
202
igny8-wp-integration-plugin/includes/class-igny8-link-queue.php
Normal file
@@ -0,0 +1,202 @@
|
||||
<?php
|
||||
/**
|
||||
* Link Insertion Queue
|
||||
*
|
||||
* Queues and processes link recommendations from IGNY8 Linker
|
||||
*
|
||||
* @package Igny8Bridge
|
||||
*/
|
||||
|
||||
// Prevent direct access
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queue link insertion
|
||||
*
|
||||
* @param array $link_data Link data
|
||||
* @return int|false Queue ID or false on failure
|
||||
*/
|
||||
function igny8_queue_link_insertion($link_data) {
|
||||
if (!igny8_is_connection_enabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$queue = get_option('igny8_link_queue', array());
|
||||
|
||||
$queue_item = array(
|
||||
'id' => uniqid('link_', true),
|
||||
'post_id' => intval($link_data['post_id']),
|
||||
'target_url' => esc_url_raw($link_data['target_url']),
|
||||
'anchor' => sanitize_text_field($link_data['anchor']),
|
||||
'source' => sanitize_text_field($link_data['source'] ?? 'igny8_linker'),
|
||||
'priority' => sanitize_text_field($link_data['priority'] ?? 'normal'),
|
||||
'status' => 'pending',
|
||||
'created_at' => $link_data['created_at'] ?? current_time('mysql'),
|
||||
'attempts' => 0
|
||||
);
|
||||
|
||||
$queue[] = $queue_item;
|
||||
|
||||
// Limit queue size (keep last 1000 items)
|
||||
if (count($queue) > 1000) {
|
||||
$queue = array_slice($queue, -1000);
|
||||
}
|
||||
|
||||
update_option('igny8_link_queue', $queue);
|
||||
|
||||
// Trigger processing if not already scheduled
|
||||
if (!wp_next_scheduled('igny8_process_link_queue')) {
|
||||
wp_schedule_single_event(time() + 60, 'igny8_process_link_queue');
|
||||
}
|
||||
|
||||
return $queue_item['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Process link insertion queue
|
||||
*/
|
||||
function igny8_process_link_queue() {
|
||||
if (!igny8_is_connection_enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (function_exists('igny8_is_module_enabled') && !igny8_is_module_enabled('linker')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$queue = get_option('igny8_link_queue', array());
|
||||
|
||||
if (empty($queue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Process up to 10 items per run
|
||||
$processed = 0;
|
||||
$max_per_run = 10;
|
||||
|
||||
foreach ($queue as $key => $item) {
|
||||
if ($processed >= $max_per_run) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ($item['status'] !== 'pending') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$result = igny8_insert_link_into_post($item);
|
||||
|
||||
if ($result['success']) {
|
||||
$queue[$key]['status'] = 'completed';
|
||||
$queue[$key]['completed_at'] = current_time('mysql');
|
||||
} else {
|
||||
$queue[$key]['attempts']++;
|
||||
|
||||
if ($queue[$key]['attempts'] >= 3) {
|
||||
$queue[$key]['status'] = 'failed';
|
||||
$queue[$key]['error'] = $result['error'] ?? 'Unknown error';
|
||||
}
|
||||
}
|
||||
|
||||
$processed++;
|
||||
}
|
||||
|
||||
update_option('igny8_link_queue', $queue);
|
||||
|
||||
// Schedule next run if there are pending items
|
||||
$has_pending = false;
|
||||
foreach ($queue as $item) {
|
||||
if ($item['status'] === 'pending') {
|
||||
$has_pending = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($has_pending && !wp_next_scheduled('igny8_process_link_queue')) {
|
||||
wp_schedule_single_event(time() + 60, 'igny8_process_link_queue');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert link into post content
|
||||
*
|
||||
* @param array $link_item Link queue item
|
||||
* @return array Result
|
||||
*/
|
||||
function igny8_insert_link_into_post($link_item) {
|
||||
$post_id = $link_item['post_id'];
|
||||
$target_url = $link_item['target_url'];
|
||||
$anchor = $link_item['anchor'];
|
||||
|
||||
$post = get_post($post_id);
|
||||
|
||||
if (!$post) {
|
||||
return array('success' => false, 'error' => 'Post not found');
|
||||
}
|
||||
|
||||
$content = $post->post_content;
|
||||
|
||||
// Check if link already exists
|
||||
if (strpos($content, $target_url) !== false) {
|
||||
return array('success' => true, 'message' => 'Link already exists');
|
||||
}
|
||||
|
||||
// Find first occurrence of anchor text not already in a link
|
||||
$anchor_escaped = preg_quote($anchor, '/');
|
||||
|
||||
// Pattern to find anchor text that's not inside an <a> tag
|
||||
// This is a simplified approach - find anchor text and check if it's not in a link
|
||||
$pattern = '/\b' . $anchor_escaped . '\b/i';
|
||||
|
||||
if (preg_match_all($pattern, $content, $matches, PREG_OFFSET_CAPTURE)) {
|
||||
foreach ($matches[0] as $match) {
|
||||
$position = $match[1];
|
||||
$length = strlen($match[0]);
|
||||
|
||||
// Check if this position is inside an <a> tag
|
||||
$before = substr($content, 0, $position);
|
||||
$after = substr($content, $position + $length);
|
||||
|
||||
// Count unclosed <a> tags before this position
|
||||
$open_tags = substr_count($before, '<a');
|
||||
$close_tags = substr_count($before, '</a>');
|
||||
|
||||
// If not inside a link, replace it
|
||||
if ($open_tags <= $close_tags) {
|
||||
$link_html = '<a href="' . esc_url($target_url) . '">' . esc_html($anchor) . '</a>';
|
||||
$new_content = substr_replace($content, $link_html, $position, $length);
|
||||
|
||||
$result = wp_update_post(array(
|
||||
'ID' => $post_id,
|
||||
'post_content' => $new_content
|
||||
));
|
||||
|
||||
if ($result && !is_wp_error($result)) {
|
||||
return array('success' => true, 'message' => 'Link inserted');
|
||||
} else {
|
||||
return array('success' => false, 'error' => 'Failed to update post');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If anchor not found, append link at end of content
|
||||
$link_html = "\n\n<p><a href=\"" . esc_url($target_url) . "\">" . esc_html($anchor) . "</a></p>";
|
||||
$new_content = $content . $link_html;
|
||||
|
||||
$result = wp_update_post(array(
|
||||
'ID' => $post_id,
|
||||
'post_content' => $new_content
|
||||
));
|
||||
|
||||
if ($result && !is_wp_error($result)) {
|
||||
return array('success' => true, 'message' => 'Link appended');
|
||||
} else {
|
||||
return array('success' => false, 'error' => 'Failed to update post');
|
||||
}
|
||||
}
|
||||
|
||||
// Register cron hook
|
||||
add_action('igny8_process_link_queue', 'igny8_process_link_queue');
|
||||
|
||||
294
igny8-wp-integration-plugin/includes/class-igny8-rest-api.php
Normal file
294
igny8-wp-integration-plugin/includes/class-igny8-rest-api.php
Normal file
@@ -0,0 +1,294 @@
|
||||
<?php
|
||||
/**
|
||||
* REST API Endpoints for IGNY8
|
||||
*
|
||||
* Provides endpoints for IGNY8 to query WordPress posts by content_id
|
||||
*
|
||||
* @package Igny8Bridge
|
||||
*/
|
||||
|
||||
// Prevent direct access
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Igny8RestAPI Class
|
||||
*/
|
||||
class Igny8RestAPI {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action('rest_api_init', array($this, 'register_routes'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register REST API routes
|
||||
*/
|
||||
public function register_routes() {
|
||||
// Get post by IGNY8 content_id
|
||||
register_rest_route('igny8/v1', '/post-by-content-id/(?P<content_id>\d+)', array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array($this, 'get_post_by_content_id'),
|
||||
'permission_callback' => array($this, 'check_permission'),
|
||||
'args' => array(
|
||||
'content_id' => array(
|
||||
'required' => true,
|
||||
'type' => 'integer',
|
||||
'description' => 'IGNY8 content ID'
|
||||
)
|
||||
)
|
||||
));
|
||||
|
||||
// Get post by IGNY8 task_id
|
||||
register_rest_route('igny8/v1', '/post-by-task-id/(?P<task_id>\d+)', array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array($this, 'get_post_by_task_id'),
|
||||
'permission_callback' => array($this, 'check_permission'),
|
||||
'args' => array(
|
||||
'task_id' => array(
|
||||
'required' => true,
|
||||
'type' => 'integer',
|
||||
'description' => 'IGNY8 task ID'
|
||||
)
|
||||
)
|
||||
));
|
||||
|
||||
// Get post status by content_id
|
||||
register_rest_route('igny8/v1', '/post-status/(?P<content_id>\d+)', array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array($this, 'get_post_status_by_content_id'),
|
||||
'permission_callback' => array($this, 'check_permission'),
|
||||
'args' => array(
|
||||
'content_id' => array(
|
||||
'required' => true,
|
||||
'type' => 'integer',
|
||||
'description' => 'IGNY8 content ID'
|
||||
)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check API permission
|
||||
*
|
||||
* @param WP_REST_Request $request Request object
|
||||
* @return bool|WP_Error
|
||||
*/
|
||||
public function check_permission($request) {
|
||||
// Check if connection is enabled
|
||||
if (!igny8_is_connection_enabled()) {
|
||||
return new WP_Error(
|
||||
'rest_forbidden',
|
||||
__('IGNY8 connection is disabled', 'igny8-bridge'),
|
||||
array('status' => 403)
|
||||
);
|
||||
}
|
||||
|
||||
// Check if authenticated with IGNY8
|
||||
$api = new Igny8API();
|
||||
|
||||
if (!$api->is_authenticated()) {
|
||||
return new WP_Error(
|
||||
'rest_forbidden',
|
||||
__('IGNY8 API not authenticated', 'igny8-bridge'),
|
||||
array('status' => 401)
|
||||
);
|
||||
}
|
||||
|
||||
// Verify API token from request header
|
||||
$auth_header = $request->get_header('Authorization');
|
||||
|
||||
if ($auth_header) {
|
||||
$token = get_option('igny8_access_token');
|
||||
if ($token && strpos($auth_header, 'Bearer ' . $token) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Allow if IGNY8 is connected (for internal use)
|
||||
if ($api->is_authenticated()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return new WP_Error(
|
||||
'rest_forbidden',
|
||||
__('Invalid authentication', 'igny8-bridge'),
|
||||
array('status' => 403)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get post by content_id
|
||||
*
|
||||
* @param WP_REST_Request $request Request object
|
||||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
public function get_post_by_content_id($request) {
|
||||
// Double-check connection is enabled
|
||||
if (!igny8_is_connection_enabled()) {
|
||||
return new WP_Error(
|
||||
'rest_forbidden',
|
||||
__('IGNY8 connection is disabled', 'igny8-bridge'),
|
||||
array('status' => 403)
|
||||
);
|
||||
}
|
||||
|
||||
$content_id = intval($request['content_id']);
|
||||
|
||||
// Find post by content_id meta
|
||||
$posts = get_posts(array(
|
||||
'meta_key' => '_igny8_content_id',
|
||||
'meta_value' => $content_id,
|
||||
'post_type' => 'any',
|
||||
'posts_per_page' => 1,
|
||||
'post_status' => 'any'
|
||||
));
|
||||
|
||||
if (empty($posts)) {
|
||||
return new WP_Error(
|
||||
'rest_not_found',
|
||||
__('Post not found for this content ID', 'igny8-bridge'),
|
||||
array('status' => 404)
|
||||
);
|
||||
}
|
||||
|
||||
$post = $posts[0];
|
||||
|
||||
return rest_ensure_response(array(
|
||||
'success' => true,
|
||||
'data' => array(
|
||||
'post_id' => $post->ID,
|
||||
'title' => $post->post_title,
|
||||
'status' => $post->post_status,
|
||||
'wordpress_status' => $post->post_status,
|
||||
'igny8_status' => igny8_map_wp_status_to_igny8($post->post_status),
|
||||
'url' => get_permalink($post->ID),
|
||||
'post_type' => $post->post_type,
|
||||
'content_id' => $content_id,
|
||||
'task_id' => get_post_meta($post->ID, '_igny8_task_id', true),
|
||||
'last_synced' => get_post_meta($post->ID, '_igny8_last_synced', true)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get post by task_id
|
||||
*
|
||||
* @param WP_REST_Request $request Request object
|
||||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
public function get_post_by_task_id($request) {
|
||||
// Double-check connection is enabled
|
||||
if (!igny8_is_connection_enabled()) {
|
||||
return new WP_Error(
|
||||
'rest_forbidden',
|
||||
__('IGNY8 connection is disabled', 'igny8-bridge'),
|
||||
array('status' => 403)
|
||||
);
|
||||
}
|
||||
|
||||
$task_id = intval($request['task_id']);
|
||||
|
||||
// Find post by task_id meta
|
||||
$posts = get_posts(array(
|
||||
'meta_key' => '_igny8_task_id',
|
||||
'meta_value' => $task_id,
|
||||
'post_type' => 'any',
|
||||
'posts_per_page' => 1,
|
||||
'post_status' => 'any'
|
||||
));
|
||||
|
||||
if (empty($posts)) {
|
||||
return new WP_Error(
|
||||
'rest_not_found',
|
||||
__('Post not found for this task ID', 'igny8-bridge'),
|
||||
array('status' => 404)
|
||||
);
|
||||
}
|
||||
|
||||
$post = $posts[0];
|
||||
|
||||
return rest_ensure_response(array(
|
||||
'success' => true,
|
||||
'data' => array(
|
||||
'post_id' => $post->ID,
|
||||
'title' => $post->post_title,
|
||||
'status' => $post->post_status,
|
||||
'wordpress_status' => $post->post_status,
|
||||
'igny8_status' => igny8_map_wp_status_to_igny8($post->post_status),
|
||||
'url' => get_permalink($post->ID),
|
||||
'post_type' => $post->post_type,
|
||||
'task_id' => $task_id,
|
||||
'content_id' => get_post_meta($post->ID, '_igny8_content_id', true),
|
||||
'last_synced' => get_post_meta($post->ID, '_igny8_last_synced', true)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get post status by content_id
|
||||
*
|
||||
* @param WP_REST_Request $request Request object
|
||||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
public function get_post_status_by_content_id($request) {
|
||||
// Double-check connection is enabled
|
||||
if (!igny8_is_connection_enabled()) {
|
||||
return new WP_Error(
|
||||
'rest_forbidden',
|
||||
__('IGNY8 connection is disabled', 'igny8-bridge'),
|
||||
array('status' => 403)
|
||||
);
|
||||
}
|
||||
|
||||
$content_id = intval($request['content_id']);
|
||||
|
||||
// Find post by content_id meta
|
||||
$posts = get_posts(array(
|
||||
'meta_key' => '_igny8_content_id',
|
||||
'meta_value' => $content_id,
|
||||
'post_type' => 'any',
|
||||
'posts_per_page' => 1,
|
||||
'post_status' => 'any',
|
||||
'fields' => 'ids' // Only get IDs for performance
|
||||
));
|
||||
|
||||
if (empty($posts)) {
|
||||
return rest_ensure_response(array(
|
||||
'success' => false,
|
||||
'message' => 'Post not found',
|
||||
'content_id' => $content_id
|
||||
));
|
||||
}
|
||||
|
||||
$post_id = $posts[0];
|
||||
$post = get_post($post_id);
|
||||
|
||||
return rest_ensure_response(array(
|
||||
'success' => true,
|
||||
'data' => array(
|
||||
'post_id' => $post_id,
|
||||
'wordpress_status' => $post->post_status,
|
||||
'igny8_status' => igny8_map_wp_status_to_igny8($post->post_status),
|
||||
'status_mapping' => array(
|
||||
'publish' => 'completed',
|
||||
'draft' => 'draft',
|
||||
'pending' => 'pending',
|
||||
'private' => 'completed',
|
||||
'trash' => 'archived',
|
||||
'future' => 'scheduled'
|
||||
),
|
||||
'content_id' => $content_id,
|
||||
'url' => get_permalink($post_id),
|
||||
'last_synced' => get_post_meta($post_id, '_igny8_last_synced', true)
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize REST API
|
||||
new Igny8RestAPI();
|
||||
|
||||
118
igny8-wp-integration-plugin/includes/class-igny8-site.php
Normal file
118
igny8-wp-integration-plugin/includes/class-igny8-site.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
/**
|
||||
* Site Integration Class
|
||||
*
|
||||
* Manages site data collection and semantic mapping
|
||||
* Follows WORDPRESS-PLUGIN-INTEGRATION.md guidelines
|
||||
*
|
||||
* @package Igny8Bridge
|
||||
*/
|
||||
|
||||
// Prevent direct access
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Igny8SiteIntegration Class
|
||||
*/
|
||||
class Igny8SiteIntegration {
|
||||
|
||||
/**
|
||||
* API instance
|
||||
*
|
||||
* @var Igny8API
|
||||
*/
|
||||
private $api;
|
||||
|
||||
/**
|
||||
* Site ID
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $site_id;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $site_id IGNY8 site ID
|
||||
*/
|
||||
public function __construct($site_id) {
|
||||
$this->api = new Igny8API();
|
||||
$this->site_id = $site_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Full site scan and semantic mapping
|
||||
*
|
||||
* @return array Result array
|
||||
*/
|
||||
public function full_site_scan() {
|
||||
// Collect all data
|
||||
$site_data = igny8_collect_site_data();
|
||||
|
||||
// Send to IGNY8
|
||||
$response = $this->api->post("/system/sites/{$this->site_id}/import/", array(
|
||||
'site_data' => $site_data,
|
||||
'import_type' => 'full_scan'
|
||||
));
|
||||
|
||||
if ($response['success']) {
|
||||
// Map to semantic strategy
|
||||
$mapping = igny8_map_site_to_semantic_strategy($this->site_id, $site_data);
|
||||
|
||||
return array(
|
||||
'success' => true,
|
||||
'import_id' => $response['data']['import_id'] ?? null,
|
||||
'semantic_map' => $mapping['data'] ?? null,
|
||||
'summary' => array(
|
||||
'posts' => count($site_data['posts']),
|
||||
'taxonomies' => count($site_data['taxonomies']),
|
||||
'products' => count($site_data['products'] ?? array()),
|
||||
'product_attributes' => count($site_data['product_attributes'] ?? array())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return array('success' => false, 'error' => $response['error'] ?? 'Unknown error');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get semantic strategy recommendations
|
||||
*
|
||||
* @return array|false Recommendations or false on failure
|
||||
*/
|
||||
public function get_recommendations() {
|
||||
$response = $this->api->get("/planner/sites/{$this->site_id}/recommendations/");
|
||||
|
||||
if ($response['success']) {
|
||||
return $response['data'];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply restructuring recommendations
|
||||
*
|
||||
* @param array $recommendations Recommendations array
|
||||
* @return bool True on success
|
||||
*/
|
||||
public function apply_restructuring($recommendations) {
|
||||
$response = $this->api->post("/planner/sites/{$this->site_id}/restructure/", array(
|
||||
'recommendations' => $recommendations
|
||||
));
|
||||
|
||||
return $response['success'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync incremental site data
|
||||
*
|
||||
* @return array|false Sync result or false on failure
|
||||
*/
|
||||
public function sync_incremental() {
|
||||
return igny8_sync_incremental_site_data($this->site_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
/**
|
||||
* Webhook Activity Logs
|
||||
*
|
||||
* Logs webhook activity for auditing and debugging
|
||||
*
|
||||
* @package Igny8Bridge
|
||||
*/
|
||||
|
||||
// Prevent direct access
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log webhook activity
|
||||
*
|
||||
* @param array $data Log data
|
||||
* @return string|false Log ID or false on failure
|
||||
*/
|
||||
function igny8_log_webhook_activity($data) {
|
||||
$logs = get_option('igny8_webhook_logs', array());
|
||||
|
||||
$log_entry = array(
|
||||
'id' => uniqid('webhook_', true),
|
||||
'event' => sanitize_text_field($data['event'] ?? 'unknown'),
|
||||
'data' => $data['data'] ?? null,
|
||||
'ip' => sanitize_text_field($data['ip'] ?? ''),
|
||||
'user_agent' => sanitize_text_field($data['user_agent'] ?? ''),
|
||||
'status' => sanitize_text_field($data['status'] ?? 'received'),
|
||||
'response' => $data['response'] ?? null,
|
||||
'error' => sanitize_text_field($data['error'] ?? ''),
|
||||
'received_at' => current_time('mysql'),
|
||||
'processed_at' => $data['processed_at'] ?? null
|
||||
);
|
||||
|
||||
$logs[] = $log_entry;
|
||||
|
||||
// Keep only last 500 logs
|
||||
if (count($logs) > 500) {
|
||||
$logs = array_slice($logs, -500);
|
||||
}
|
||||
|
||||
update_option('igny8_webhook_logs', $logs);
|
||||
|
||||
return $log_entry['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Update webhook log entry
|
||||
*
|
||||
* @param string $log_id Log ID
|
||||
* @param array $updates Updates to apply
|
||||
* @return bool Success
|
||||
*/
|
||||
function igny8_update_webhook_log($log_id, $updates) {
|
||||
$logs = get_option('igny8_webhook_logs', array());
|
||||
|
||||
foreach ($logs as $key => $log) {
|
||||
if ($log['id'] === $log_id) {
|
||||
foreach ($updates as $field => $value) {
|
||||
if ($field === 'status') {
|
||||
$logs[$key][$field] = sanitize_text_field($value);
|
||||
} elseif ($field === 'response') {
|
||||
$logs[$key][$field] = $value;
|
||||
} elseif ($field === 'processed_at') {
|
||||
$logs[$key][$field] = sanitize_text_field($value);
|
||||
} else {
|
||||
$logs[$key][$field] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
update_option('igny8_webhook_logs', $logs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get webhook logs
|
||||
*
|
||||
* @param array $args Query arguments
|
||||
* @return array Logs
|
||||
*/
|
||||
function igny8_get_webhook_logs($args = array()) {
|
||||
$defaults = array(
|
||||
'limit' => 50,
|
||||
'event' => null,
|
||||
'status' => null
|
||||
);
|
||||
|
||||
$args = wp_parse_args($args, $defaults);
|
||||
$logs = get_option('igny8_webhook_logs', array());
|
||||
|
||||
// Reverse to get newest first
|
||||
$logs = array_reverse($logs);
|
||||
|
||||
// Filter by event
|
||||
if ($args['event']) {
|
||||
$logs = array_filter($logs, function($log) use ($args) {
|
||||
return $log['event'] === $args['event'];
|
||||
});
|
||||
}
|
||||
|
||||
// Filter by status
|
||||
if ($args['status']) {
|
||||
$logs = array_filter($logs, function($log) use ($args) {
|
||||
return $log['status'] === $args['status'];
|
||||
});
|
||||
}
|
||||
|
||||
// Limit results
|
||||
if ($args['limit'] > 0) {
|
||||
$logs = array_slice($logs, 0, $args['limit']);
|
||||
}
|
||||
|
||||
return array_values($logs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear old webhook logs
|
||||
*
|
||||
* @param int $days_old Delete logs older than this many days
|
||||
* @return int Number of logs deleted
|
||||
*/
|
||||
function igny8_clear_old_webhook_logs($days_old = 30) {
|
||||
$logs = get_option('igny8_webhook_logs', array());
|
||||
$cutoff = strtotime("-{$days_old} days");
|
||||
$deleted = 0;
|
||||
|
||||
foreach ($logs as $key => $log) {
|
||||
$log_time = strtotime($log['received_at']);
|
||||
if ($log_time < $cutoff) {
|
||||
unset($logs[$key]);
|
||||
$deleted++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($deleted > 0) {
|
||||
update_option('igny8_webhook_logs', array_values($logs));
|
||||
}
|
||||
|
||||
return $deleted;
|
||||
}
|
||||
|
||||
381
igny8-wp-integration-plugin/includes/class-igny8-webhooks.php
Normal file
381
igny8-wp-integration-plugin/includes/class-igny8-webhooks.php
Normal file
@@ -0,0 +1,381 @@
|
||||
<?php
|
||||
/**
|
||||
* IGNY8 Webhooks Handler
|
||||
*
|
||||
* Handles incoming webhooks from IGNY8 SaaS
|
||||
*
|
||||
* @package Igny8Bridge
|
||||
*/
|
||||
|
||||
// Prevent direct access
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Igny8Webhooks Class
|
||||
*/
|
||||
class Igny8Webhooks {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action('rest_api_init', array($this, 'register_webhook_routes'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register webhook REST routes
|
||||
*/
|
||||
public function register_webhook_routes() {
|
||||
// Main webhook endpoint
|
||||
register_rest_route('igny8/v1', '/event', array(
|
||||
'methods' => 'POST',
|
||||
'callback' => array($this, 'handle_webhook'),
|
||||
'permission_callback' => array($this, 'verify_webhook_secret'),
|
||||
'args' => array(
|
||||
'event' => array(
|
||||
'required' => true,
|
||||
'type' => 'string',
|
||||
'description' => 'Event type'
|
||||
),
|
||||
'data' => array(
|
||||
'required' => true,
|
||||
'type' => 'object',
|
||||
'description' => 'Event data'
|
||||
)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify webhook shared secret
|
||||
*
|
||||
* @param WP_REST_Request $request Request object
|
||||
* @return bool|WP_Error
|
||||
*/
|
||||
public function verify_webhook_secret($request) {
|
||||
// First check if connection is enabled
|
||||
if (!igny8_is_connection_enabled()) {
|
||||
return new WP_Error(
|
||||
'rest_forbidden',
|
||||
__('IGNY8 connection is disabled', 'igny8-bridge'),
|
||||
array('status' => 403)
|
||||
);
|
||||
}
|
||||
|
||||
// Get shared secret from settings
|
||||
$shared_secret = igny8_get_webhook_secret();
|
||||
|
||||
if (empty($shared_secret)) {
|
||||
return new WP_Error(
|
||||
'rest_forbidden',
|
||||
__('Webhook secret not configured', 'igny8-bridge'),
|
||||
array('status' => 403)
|
||||
);
|
||||
}
|
||||
|
||||
// Check X-IGNY8-Signature header
|
||||
$signature = $request->get_header('X-IGNY8-Signature');
|
||||
|
||||
if (empty($signature)) {
|
||||
return new WP_Error(
|
||||
'rest_forbidden',
|
||||
__('Missing webhook signature', 'igny8-bridge'),
|
||||
array('status' => 401)
|
||||
);
|
||||
}
|
||||
|
||||
// Verify signature
|
||||
$body = $request->get_body();
|
||||
$expected_signature = hash_hmac('sha256', $body, $shared_secret);
|
||||
|
||||
if (!hash_equals($expected_signature, $signature)) {
|
||||
igny8_log_webhook_activity(array(
|
||||
'event' => 'authentication_failed',
|
||||
'ip' => $request->get_header('X-Forwarded-For') ?: $request->get_header('Remote-Addr'),
|
||||
'error' => 'Invalid signature'
|
||||
));
|
||||
|
||||
return new WP_Error(
|
||||
'rest_forbidden',
|
||||
__('Invalid webhook signature', 'igny8-bridge'),
|
||||
array('status' => 401)
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle incoming webhook
|
||||
*
|
||||
* @param WP_REST_Request $request Request object
|
||||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
public function handle_webhook($request) {
|
||||
// Double-check connection is enabled
|
||||
if (!igny8_is_connection_enabled()) {
|
||||
return new WP_Error(
|
||||
'rest_forbidden',
|
||||
__('IGNY8 connection is disabled', 'igny8-bridge'),
|
||||
array('status' => 403)
|
||||
);
|
||||
}
|
||||
|
||||
$event = $request->get_param('event');
|
||||
$data = $request->get_param('data');
|
||||
|
||||
if (empty($event) || empty($data)) {
|
||||
return new WP_Error(
|
||||
'rest_invalid_param',
|
||||
__('Missing event or data parameter', 'igny8-bridge'),
|
||||
array('status' => 400)
|
||||
);
|
||||
}
|
||||
|
||||
// Log webhook receipt
|
||||
$log_id = igny8_log_webhook_activity(array(
|
||||
'event' => $event,
|
||||
'data' => $data,
|
||||
'ip' => $request->get_header('X-Forwarded-For') ?: $request->get_header('Remote-Addr'),
|
||||
'user_agent' => $request->get_header('User-Agent'),
|
||||
'status' => 'received'
|
||||
));
|
||||
|
||||
// Route to appropriate handler
|
||||
$result = null;
|
||||
|
||||
switch ($event) {
|
||||
case 'task_published':
|
||||
case 'task_completed':
|
||||
$result = $this->handle_task_published($data);
|
||||
break;
|
||||
|
||||
case 'link_recommendation':
|
||||
case 'insert_link':
|
||||
$result = $this->handle_link_recommendation($data);
|
||||
break;
|
||||
|
||||
case 'optimizer_request':
|
||||
case 'optimizer_job_completed':
|
||||
$result = $this->handle_optimizer_request($data);
|
||||
break;
|
||||
|
||||
default:
|
||||
$result = array(
|
||||
'success' => false,
|
||||
'error' => 'Unknown event type: ' . $event
|
||||
);
|
||||
}
|
||||
|
||||
// Update log with result
|
||||
if ($log_id) {
|
||||
igny8_update_webhook_log($log_id, array(
|
||||
'status' => $result['success'] ? 'processed' : 'failed',
|
||||
'response' => $result,
|
||||
'processed_at' => current_time('mysql')
|
||||
));
|
||||
}
|
||||
|
||||
return rest_ensure_response($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle task published event
|
||||
*
|
||||
* @param array $data Event data
|
||||
* @return array Result
|
||||
*/
|
||||
private function handle_task_published($data) {
|
||||
if (!igny8_is_connection_enabled()) {
|
||||
return array('success' => false, 'error' => 'Connection disabled');
|
||||
}
|
||||
|
||||
if (function_exists('igny8_is_module_enabled') && !igny8_is_module_enabled('writer')) {
|
||||
return array('success' => false, 'error' => 'Writer module disabled');
|
||||
}
|
||||
|
||||
$task_id = $data['task_id'] ?? null;
|
||||
|
||||
if (!$task_id) {
|
||||
return array('success' => false, 'error' => 'Missing task_id');
|
||||
}
|
||||
|
||||
// Check if post already exists
|
||||
$existing_posts = get_posts(array(
|
||||
'meta_key' => '_igny8_task_id',
|
||||
'meta_value' => $task_id,
|
||||
'post_type' => 'any',
|
||||
'posts_per_page' => 1
|
||||
));
|
||||
|
||||
if (!empty($existing_posts)) {
|
||||
// Post already exists, just update status if needed
|
||||
$post_id = $existing_posts[0]->ID;
|
||||
$status = $data['status'] ?? 'publish';
|
||||
|
||||
if ($status === 'publish' || $status === 'completed') {
|
||||
wp_update_post(array(
|
||||
'ID' => $post_id,
|
||||
'post_status' => 'publish'
|
||||
));
|
||||
}
|
||||
|
||||
return array(
|
||||
'success' => true,
|
||||
'message' => 'Post updated',
|
||||
'post_id' => $post_id
|
||||
);
|
||||
}
|
||||
|
||||
// Fetch full task data and create post
|
||||
$api = new Igny8API();
|
||||
$task_response = $api->get("/writer/tasks/{$task_id}/");
|
||||
|
||||
if (!$task_response['success']) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'error' => 'Failed to fetch task: ' . ($task_response['error'] ?? 'Unknown error')
|
||||
);
|
||||
}
|
||||
|
||||
$task = $task_response['data'];
|
||||
$enabled_post_types = igny8_get_enabled_post_types();
|
||||
|
||||
$content_data = array(
|
||||
'task_id' => $task['id'],
|
||||
'title' => $task['title'] ?? 'Untitled',
|
||||
'content' => $task['content'] ?? '',
|
||||
'status' => $task['status'] ?? 'draft',
|
||||
'cluster_id' => $task['cluster_id'] ?? null,
|
||||
'sector_id' => $task['sector_id'] ?? null,
|
||||
'keyword_ids' => $task['keyword_ids'] ?? array(),
|
||||
'content_type' => $task['content_type'] ?? 'post',
|
||||
'categories' => $task['categories'] ?? array(),
|
||||
'tags' => $task['tags'] ?? array(),
|
||||
'featured_image' => $task['featured_image'] ?? null,
|
||||
'gallery_images' => $task['gallery_images'] ?? array(),
|
||||
'meta_title' => $task['meta_title'] ?? null,
|
||||
'meta_description' => $task['meta_description'] ?? null
|
||||
);
|
||||
|
||||
$post_id = igny8_create_wordpress_post_from_task($content_data, $enabled_post_types);
|
||||
|
||||
if (is_wp_error($post_id)) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'error' => $post_id->get_error_message()
|
||||
);
|
||||
}
|
||||
|
||||
return array(
|
||||
'success' => true,
|
||||
'message' => 'Post created',
|
||||
'post_id' => $post_id
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle link recommendation event
|
||||
*
|
||||
* @param array $data Event data
|
||||
* @return array Result
|
||||
*/
|
||||
private function handle_link_recommendation($data) {
|
||||
if (!igny8_is_connection_enabled()) {
|
||||
return array('success' => false, 'error' => 'Connection disabled');
|
||||
}
|
||||
|
||||
if (function_exists('igny8_is_module_enabled') && !igny8_is_module_enabled('linker')) {
|
||||
return array('success' => false, 'error' => 'Linker module disabled');
|
||||
}
|
||||
|
||||
$post_id = $data['post_id'] ?? null;
|
||||
$target_url = $data['target_url'] ?? null;
|
||||
$anchor = $data['anchor'] ?? $data['anchor_text'] ?? null;
|
||||
|
||||
if (!$post_id || !$target_url || !$anchor) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'error' => 'Missing required parameters: post_id, target_url, anchor'
|
||||
);
|
||||
}
|
||||
|
||||
// Queue link insertion
|
||||
$queued = igny8_queue_link_insertion(array(
|
||||
'post_id' => intval($post_id),
|
||||
'target_url' => esc_url_raw($target_url),
|
||||
'anchor' => sanitize_text_field($anchor),
|
||||
'source' => 'igny8_linker',
|
||||
'priority' => $data['priority'] ?? 'normal',
|
||||
'created_at' => current_time('mysql')
|
||||
));
|
||||
|
||||
if ($queued) {
|
||||
return array(
|
||||
'success' => true,
|
||||
'message' => 'Link queued for insertion',
|
||||
'queue_id' => $queued
|
||||
);
|
||||
}
|
||||
|
||||
return array(
|
||||
'success' => false,
|
||||
'error' => 'Failed to queue link insertion'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle optimizer request event
|
||||
*
|
||||
* @param array $data Event data
|
||||
* @return array Result
|
||||
*/
|
||||
private function handle_optimizer_request($data) {
|
||||
if (!igny8_is_connection_enabled()) {
|
||||
return array('success' => false, 'error' => 'Connection disabled');
|
||||
}
|
||||
|
||||
if (function_exists('igny8_is_module_enabled') && !igny8_is_module_enabled('optimizer')) {
|
||||
return array('success' => false, 'error' => 'Optimizer module disabled');
|
||||
}
|
||||
|
||||
$post_id = $data['post_id'] ?? null;
|
||||
$job_id = $data['job_id'] ?? null;
|
||||
$status = $data['status'] ?? null;
|
||||
$score_changes = $data['score_changes'] ?? null;
|
||||
$recommendations = $data['recommendations'] ?? null;
|
||||
|
||||
if (!$post_id) {
|
||||
return array('success' => false, 'error' => 'Missing post_id');
|
||||
}
|
||||
|
||||
// Update optimizer status if job_id provided
|
||||
if ($job_id) {
|
||||
update_post_meta($post_id, '_igny8_optimizer_job_id', $job_id);
|
||||
}
|
||||
|
||||
if ($status) {
|
||||
update_post_meta($post_id, '_igny8_optimizer_status', $status);
|
||||
}
|
||||
|
||||
if ($score_changes) {
|
||||
update_post_meta($post_id, '_igny8_optimizer_score_changes', $score_changes);
|
||||
}
|
||||
|
||||
if ($recommendations) {
|
||||
update_post_meta($post_id, '_igny8_optimizer_recommendations', $recommendations);
|
||||
}
|
||||
|
||||
return array(
|
||||
'success' => true,
|
||||
'message' => 'Optimizer data updated',
|
||||
'post_id' => $post_id
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize webhooks
|
||||
new Igny8Webhooks();
|
||||
|
||||
605
igny8-wp-integration-plugin/includes/functions.php
Normal file
605
igny8-wp-integration-plugin/includes/functions.php
Normal file
@@ -0,0 +1,605 @@
|
||||
<?php
|
||||
/**
|
||||
* Helper Functions
|
||||
*
|
||||
* WordPress integration functions for IGNY8 Bridge
|
||||
*
|
||||
* @package Igny8Bridge
|
||||
*/
|
||||
|
||||
// Prevent direct access
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get encryption key for secure option storage
|
||||
*
|
||||
* @return string Binary key
|
||||
*/
|
||||
function igny8_get_encryption_key() {
|
||||
$salt = wp_salt('auth');
|
||||
return hash('sha256', 'igny8_bridge_' . $salt, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypt a value for storage
|
||||
*
|
||||
* @param string $value Plain text value
|
||||
* @return string Encrypted value with prefix or original value on failure
|
||||
*/
|
||||
function igny8_encrypt_value($value) {
|
||||
if ($value === '' || $value === null) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (!function_exists('openssl_encrypt')) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$iv = openssl_random_pseudo_bytes(16);
|
||||
$cipher = openssl_encrypt($value, 'AES-256-CBC', igny8_get_encryption_key(), OPENSSL_RAW_DATA, $iv);
|
||||
|
||||
if ($cipher === false) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return 'igny8|' . base64_encode($iv . $cipher);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypt a stored value
|
||||
*
|
||||
* @param string $value Stored value
|
||||
* @return string Decrypted value or original on failure
|
||||
*/
|
||||
function igny8_decrypt_value($value) {
|
||||
if (!is_string($value) || strpos($value, 'igny8|') !== 0) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (!function_exists('openssl_decrypt')) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$encoded = substr($value, 6);
|
||||
$data = base64_decode($encoded, true);
|
||||
|
||||
if ($data === false || strlen($data) <= 16) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$iv = substr($data, 0, 16);
|
||||
$cipher = substr($data, 16);
|
||||
|
||||
$plain = openssl_decrypt($cipher, 'AES-256-CBC', igny8_get_encryption_key(), OPENSSL_RAW_DATA, $iv);
|
||||
|
||||
return ($plain === false) ? $value : $plain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an option securely
|
||||
*
|
||||
* @param string $option Option name
|
||||
* @param string $value Value to store
|
||||
*/
|
||||
function igny8_store_secure_option($option, $value) {
|
||||
if ($value === null || $value === '') {
|
||||
delete_option($option);
|
||||
return;
|
||||
}
|
||||
|
||||
update_option($option, igny8_encrypt_value($value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve secure option (with legacy fallback)
|
||||
*
|
||||
* @param string $option Option name
|
||||
* @return string Value
|
||||
*/
|
||||
function igny8_get_secure_option($option) {
|
||||
$stored = get_option($option);
|
||||
|
||||
if (!$stored) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$value = igny8_decrypt_value($stored);
|
||||
|
||||
return is_string($value) ? $value : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get supported post types for automation
|
||||
*
|
||||
* @return array Key => label
|
||||
*/
|
||||
function igny8_get_supported_post_types() {
|
||||
$types = array(
|
||||
'post' => __('Posts', 'igny8-bridge'),
|
||||
'page' => __('Pages', 'igny8-bridge'),
|
||||
);
|
||||
|
||||
if (post_type_exists('product')) {
|
||||
$types['product'] = __('Products', 'igny8-bridge');
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the list of selectable post types.
|
||||
*
|
||||
* @param array $types
|
||||
*/
|
||||
return apply_filters('igny8_supported_post_types', $types);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get enabled post types
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function igny8_get_enabled_post_types() {
|
||||
$saved = get_option('igny8_enabled_post_types');
|
||||
|
||||
if (is_array($saved) && !empty($saved)) {
|
||||
return $saved;
|
||||
}
|
||||
|
||||
return array_keys(igny8_get_supported_post_types());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configured control mode
|
||||
*
|
||||
* @return string mirror|hybrid
|
||||
*/
|
||||
function igny8_get_control_mode() {
|
||||
$mode = get_option('igny8_control_mode', 'mirror');
|
||||
return in_array($mode, array('mirror', 'hybrid'), true) ? $mode : 'mirror';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available automation modules
|
||||
*
|
||||
* @return array Key => label
|
||||
*/
|
||||
function igny8_get_available_modules() {
|
||||
$modules = array(
|
||||
'sites' => __('Sites (Data & Semantic Map)', 'igny8-bridge'),
|
||||
'planner' => __('Planner (Keywords & Briefs)', 'igny8-bridge'),
|
||||
'writer' => __('Writer (Tasks & Posts)', 'igny8-bridge'),
|
||||
'linker' => __('Linker (Internal Links)', 'igny8-bridge'),
|
||||
'optimizer' => __('Optimizer (Audits & Scores)', 'igny8-bridge'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Filter the list of IGNY8 modules that can be toggled.
|
||||
*
|
||||
* @param array $modules
|
||||
*/
|
||||
return apply_filters('igny8_available_modules', $modules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get enabled modules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function igny8_get_enabled_modules() {
|
||||
$saved = get_option('igny8_enabled_modules');
|
||||
|
||||
if (is_array($saved) && !empty($saved)) {
|
||||
return $saved;
|
||||
}
|
||||
|
||||
return array_keys(igny8_get_available_modules());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a module is enabled
|
||||
*
|
||||
* @param string $module Module key
|
||||
* @return bool
|
||||
*/
|
||||
function igny8_is_module_enabled($module) {
|
||||
$modules = igny8_get_enabled_modules();
|
||||
return in_array($module, $modules, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a post type is enabled for automation
|
||||
*
|
||||
* @param string $post_type Post type key
|
||||
* @return bool
|
||||
*/
|
||||
function igny8_is_post_type_enabled($post_type) {
|
||||
$post_types = igny8_get_enabled_post_types();
|
||||
return in_array($post_type, $post_types, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if IGNY8 connection is enabled
|
||||
* This is a master switch that disables all sync operations while preserving credentials
|
||||
*
|
||||
* @return bool True if connection is enabled
|
||||
*/
|
||||
function igny8_is_connection_enabled() {
|
||||
$enabled = get_option('igny8_connection_enabled', 1);
|
||||
return (bool) $enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get webhook shared secret
|
||||
*
|
||||
* @return string Webhook secret
|
||||
*/
|
||||
function igny8_get_webhook_secret() {
|
||||
$secret = get_option('igny8_webhook_secret');
|
||||
|
||||
if (empty($secret)) {
|
||||
// Generate secret if not exists
|
||||
$secret = wp_generate_password(64, false);
|
||||
update_option('igny8_webhook_secret', $secret);
|
||||
}
|
||||
|
||||
return $secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerate webhook secret
|
||||
*
|
||||
* @return string New secret
|
||||
*/
|
||||
function igny8_regenerate_webhook_secret() {
|
||||
$secret = wp_generate_password(64, false);
|
||||
update_option('igny8_webhook_secret', $secret);
|
||||
return $secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configuration for site scans
|
||||
*
|
||||
* @param array $overrides Override defaults
|
||||
* @return array
|
||||
*/
|
||||
function igny8_get_site_scan_settings($overrides = array()) {
|
||||
$defaults = array(
|
||||
'post_types' => igny8_get_enabled_post_types(),
|
||||
'include_products' => (bool) get_option('igny8_enable_woocommerce', class_exists('WooCommerce') ? 1 : 0),
|
||||
'per_page' => 100,
|
||||
'since' => null,
|
||||
'mode' => 'full',
|
||||
);
|
||||
|
||||
$settings = wp_parse_args($overrides, $defaults);
|
||||
|
||||
return apply_filters('igny8_site_scan_settings', $settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register IGNY8 post meta fields
|
||||
*/
|
||||
function igny8_register_post_meta() {
|
||||
$post_types = array('post', 'page', 'product');
|
||||
|
||||
// Define all meta fields with proper schema for REST API
|
||||
$meta_fields = array(
|
||||
'_igny8_task_id' => array(
|
||||
'type' => 'integer',
|
||||
'description' => 'IGNY8 task ID linked to this post',
|
||||
'single' => true,
|
||||
'show_in_rest' => true,
|
||||
),
|
||||
'_igny8_cluster_id' => array(
|
||||
'type' => 'integer',
|
||||
'description' => 'IGNY8 cluster ID',
|
||||
'single' => true,
|
||||
'show_in_rest' => true,
|
||||
),
|
||||
'_igny8_sector_id' => array(
|
||||
'type' => 'integer',
|
||||
'description' => 'IGNY8 sector ID',
|
||||
'single' => true,
|
||||
'show_in_rest' => true,
|
||||
),
|
||||
'_igny8_keyword_ids' => array(
|
||||
'type' => 'array',
|
||||
'description' => 'Array of IGNY8 keyword IDs',
|
||||
'single' => true,
|
||||
'show_in_rest' => array(
|
||||
'schema' => array(
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer'
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
'_igny8_content_id' => array(
|
||||
'type' => 'integer',
|
||||
'description' => 'IGNY8 content ID',
|
||||
'single' => true,
|
||||
'show_in_rest' => true,
|
||||
),
|
||||
'_igny8_wordpress_status' => array(
|
||||
'type' => 'string',
|
||||
'description' => 'WordPress post status (for IGNY8 reference)',
|
||||
'single' => true,
|
||||
'show_in_rest' => true,
|
||||
),
|
||||
'_igny8_last_synced' => array(
|
||||
'type' => 'string',
|
||||
'description' => 'Last sync timestamp',
|
||||
'single' => true,
|
||||
'show_in_rest' => true,
|
||||
),
|
||||
'_igny8_task_brief' => array(
|
||||
'type' => 'array',
|
||||
'description' => 'Cached IGNY8 writer brief data',
|
||||
'single' => true,
|
||||
'show_in_rest' => array(
|
||||
'schema' => array(
|
||||
'type' => 'object'
|
||||
)
|
||||
)
|
||||
),
|
||||
'_igny8_brief_cached_at' => array(
|
||||
'type' => 'string',
|
||||
'description' => 'Timestamp of cached IGNY8 brief',
|
||||
'single' => true,
|
||||
'show_in_rest' => true,
|
||||
),
|
||||
'_igny8_optimizer_job_id' => array(
|
||||
'type' => 'integer',
|
||||
'description' => 'IGNY8 optimizer job ID',
|
||||
'single' => true,
|
||||
'show_in_rest' => true,
|
||||
),
|
||||
'_igny8_optimizer_status' => array(
|
||||
'type' => 'string',
|
||||
'description' => 'IGNY8 optimizer job status',
|
||||
'single' => true,
|
||||
'show_in_rest' => true,
|
||||
),
|
||||
'_igny8_optimizer_score_changes' => array(
|
||||
'type' => 'array',
|
||||
'description' => 'IGNY8 optimizer score changes',
|
||||
'single' => true,
|
||||
'show_in_rest' => array(
|
||||
'schema' => array(
|
||||
'type' => 'object'
|
||||
)
|
||||
)
|
||||
),
|
||||
'_igny8_optimizer_recommendations' => array(
|
||||
'type' => 'array',
|
||||
'description' => 'IGNY8 optimizer recommendations',
|
||||
'single' => true,
|
||||
'show_in_rest' => array(
|
||||
'schema' => array(
|
||||
'type' => 'array'
|
||||
)
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
// Register each meta field for all relevant post types
|
||||
foreach ($meta_fields as $meta_key => $config) {
|
||||
foreach ($post_types as $post_type) {
|
||||
register_post_meta($post_type, $meta_key, $config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register IGNY8 taxonomies
|
||||
*/
|
||||
function igny8_register_taxonomies() {
|
||||
// Register sectors taxonomy (hierarchical) - only if not exists
|
||||
if (!taxonomy_exists('igny8_sectors')) {
|
||||
register_taxonomy('igny8_sectors', array('post', 'page', 'product'), array(
|
||||
'hierarchical' => true,
|
||||
'labels' => array(
|
||||
'name' => 'IGNY8 Sectors',
|
||||
'singular_name' => 'Sector',
|
||||
'menu_name' => 'Sectors',
|
||||
'all_items' => 'All Sectors',
|
||||
'edit_item' => 'Edit Sector',
|
||||
'view_item' => 'View Sector',
|
||||
'update_item' => 'Update Sector',
|
||||
'add_new_item' => 'Add New Sector',
|
||||
'new_item_name' => 'New Sector Name',
|
||||
'parent_item' => 'Parent Sector',
|
||||
'parent_item_colon' => 'Parent Sector:',
|
||||
'search_items' => 'Search Sectors',
|
||||
'not_found' => 'No sectors found',
|
||||
),
|
||||
'public' => true,
|
||||
'show_ui' => true,
|
||||
'show_admin_column' => false,
|
||||
'show_in_nav_menus' => true,
|
||||
'show_tagcloud' => false,
|
||||
'show_in_rest' => true,
|
||||
'rewrite' => array(
|
||||
'slug' => 'sectors',
|
||||
'with_front' => false,
|
||||
),
|
||||
'capabilities' => array(
|
||||
'manage_terms' => 'manage_categories',
|
||||
'edit_terms' => 'manage_categories',
|
||||
'delete_terms' => 'manage_categories',
|
||||
'assign_terms' => 'edit_posts',
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
// Register clusters taxonomy (hierarchical) - only if not exists
|
||||
if (!taxonomy_exists('igny8_clusters')) {
|
||||
register_taxonomy('igny8_clusters', array('post', 'page', 'product'), array(
|
||||
'hierarchical' => true,
|
||||
'labels' => array(
|
||||
'name' => 'IGNY8 Clusters',
|
||||
'singular_name' => 'Cluster',
|
||||
'menu_name' => 'Clusters',
|
||||
'all_items' => 'All Clusters',
|
||||
'edit_item' => 'Edit Cluster',
|
||||
'view_item' => 'View Cluster',
|
||||
'update_item' => 'Update Cluster',
|
||||
'add_new_item' => 'Add New Cluster',
|
||||
'new_item_name' => 'New Cluster Name',
|
||||
'parent_item' => 'Parent Cluster',
|
||||
'parent_item_colon' => 'Parent Cluster:',
|
||||
'search_items' => 'Search Clusters',
|
||||
'not_found' => 'No clusters found',
|
||||
),
|
||||
'public' => true,
|
||||
'show_ui' => true,
|
||||
'show_admin_column' => false,
|
||||
'show_in_nav_menus' => true,
|
||||
'show_tagcloud' => false,
|
||||
'show_in_rest' => true,
|
||||
'rewrite' => array(
|
||||
'slug' => 'clusters',
|
||||
'with_front' => false,
|
||||
),
|
||||
'capabilities' => array(
|
||||
'manage_terms' => 'manage_categories',
|
||||
'edit_terms' => 'manage_categories',
|
||||
'delete_terms' => 'manage_categories',
|
||||
'assign_terms' => 'edit_posts',
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Map WordPress post status to IGNY8 task status
|
||||
*
|
||||
* @param string $wp_status WordPress post status
|
||||
* @return string IGNY8 task status
|
||||
*/
|
||||
function igny8_map_wp_status_to_igny8($wp_status) {
|
||||
$status_map = array(
|
||||
'publish' => 'completed',
|
||||
'draft' => 'draft',
|
||||
'pending' => 'pending',
|
||||
'private' => 'completed',
|
||||
'trash' => 'archived',
|
||||
'future' => 'scheduled'
|
||||
);
|
||||
|
||||
return isset($status_map[$wp_status]) ? $status_map[$wp_status] : 'draft';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if post is managed by IGNY8
|
||||
*
|
||||
* @param int $post_id Post ID
|
||||
* @return bool True if IGNY8 managed
|
||||
*/
|
||||
function igny8_is_igny8_managed_post($post_id) {
|
||||
$task_id = get_post_meta($post_id, '_igny8_task_id', true);
|
||||
return !empty($task_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get post data for IGNY8 sync
|
||||
*
|
||||
* @param int $post_id Post ID
|
||||
* @return array|false Post data or false on failure
|
||||
*/
|
||||
function igny8_get_post_data_for_sync($post_id) {
|
||||
$post = get_post($post_id);
|
||||
|
||||
if (!$post) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return array(
|
||||
'id' => $post_id,
|
||||
'title' => $post->post_title,
|
||||
'status' => $post->post_status,
|
||||
'url' => get_permalink($post_id),
|
||||
'modified' => $post->post_modified,
|
||||
'published' => $post->post_date,
|
||||
'author' => get_the_author_meta('display_name', $post->post_author),
|
||||
'word_count' => str_word_count(strip_tags($post->post_content)),
|
||||
'meta' => array(
|
||||
'task_id' => get_post_meta($post_id, '_igny8_task_id', true),
|
||||
'content_id' => get_post_meta($post_id, '_igny8_content_id', true),
|
||||
'cluster_id' => get_post_meta($post_id, '_igny8_cluster_id', true),
|
||||
'sector_id' => get_post_meta($post_id, '_igny8_sector_id', true),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule cron jobs
|
||||
*/
|
||||
function igny8_schedule_cron_jobs() {
|
||||
// Schedule daily post status sync (WordPress → IGNY8)
|
||||
if (!wp_next_scheduled('igny8_sync_post_statuses')) {
|
||||
wp_schedule_event(time(), 'daily', 'igny8_sync_post_statuses');
|
||||
}
|
||||
|
||||
// Schedule daily site data sync (incremental)
|
||||
if (!wp_next_scheduled('igny8_sync_site_data')) {
|
||||
wp_schedule_event(time(), 'daily', 'igny8_sync_site_data');
|
||||
}
|
||||
|
||||
// Schedule periodic full site scan (runs at most once per week)
|
||||
if (!wp_next_scheduled('igny8_full_site_scan')) {
|
||||
wp_schedule_event(time(), 'daily', 'igny8_full_site_scan');
|
||||
}
|
||||
|
||||
// Schedule hourly sync from IGNY8 (IGNY8 → WordPress)
|
||||
if (!wp_next_scheduled('igny8_sync_from_igny8')) {
|
||||
wp_schedule_event(time(), 'hourly', 'igny8_sync_from_igny8');
|
||||
}
|
||||
|
||||
// Schedule taxonomy sync
|
||||
if (!wp_next_scheduled('igny8_sync_taxonomies')) {
|
||||
wp_schedule_event(time(), 'twicedaily', 'igny8_sync_taxonomies');
|
||||
}
|
||||
|
||||
// Schedule keyword sync
|
||||
if (!wp_next_scheduled('igny8_sync_keywords')) {
|
||||
wp_schedule_event(time(), 'daily', 'igny8_sync_keywords');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unschedule cron jobs
|
||||
*/
|
||||
function igny8_unschedule_cron_jobs() {
|
||||
$timestamp = wp_next_scheduled('igny8_sync_post_statuses');
|
||||
if ($timestamp) {
|
||||
wp_unschedule_event($timestamp, 'igny8_sync_post_statuses');
|
||||
}
|
||||
|
||||
$timestamp = wp_next_scheduled('igny8_sync_site_data');
|
||||
if ($timestamp) {
|
||||
wp_unschedule_event($timestamp, 'igny8_sync_site_data');
|
||||
}
|
||||
|
||||
$timestamp = wp_next_scheduled('igny8_sync_from_igny8');
|
||||
if ($timestamp) {
|
||||
wp_unschedule_event($timestamp, 'igny8_sync_from_igny8');
|
||||
}
|
||||
|
||||
$timestamp = wp_next_scheduled('igny8_full_site_scan');
|
||||
if ($timestamp) {
|
||||
wp_unschedule_event($timestamp, 'igny8_full_site_scan');
|
||||
}
|
||||
|
||||
$timestamp = wp_next_scheduled('igny8_sync_taxonomies');
|
||||
if ($timestamp) {
|
||||
wp_unschedule_event($timestamp, 'igny8_sync_taxonomies');
|
||||
}
|
||||
|
||||
$timestamp = wp_next_scheduled('igny8_sync_keywords');
|
||||
if ($timestamp) {
|
||||
wp_unschedule_event($timestamp, 'igny8_sync_keywords');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user