Shopseitige Diagnose (SSH, 28.08.): der Hook partnercenter_api_fetch_orders_status war in WP-Cron GAR NICHT eingeplant (grep leer), obwohl WP-Cron läuft (System-Cron trifft wp-cron.php alle 5 Min, DISABLE_WP_CRON=1 korrekt kompensiert). Damit pollte nichts /api/wp/status → jede abgeschlossene Bestellung blieb auf 'open' = orange. Ursache: Der Event wurde nur im register_activation_hook eingeplant und im Deaktivierungs-Hook gelöscht. Ein In-Place-Update (ohne Reaktivierung) ließ ihn dauerhaft verschwinden. Fix (Connector v1.6.0): partnercenter_api_ensure_cron() auf 'init' — plant den stündlichen Event nach, falls er fehlt (wp_next_scheduled-Guard). Selbstheilend, übersteht künftige Updates. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
125 lines
3.2 KiB
PHP
125 lines
3.2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Plugin Name: PARTNERCENTER API Connector
|
|
* Description: Connect WooCommerce to PARTNERCENTER API
|
|
* Version: 1.6.0
|
|
* Author: Cross Media Cloud
|
|
* Author URI: https://www.cross-media-cloud.de
|
|
* License: GNU General Public License v2 or later
|
|
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
|
* Text Domain: partnercenter-api
|
|
* Domain Path: /languages/
|
|
*/
|
|
if (! defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Load plugin text domain
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
function partnercenter_api_load_textdomain()
|
|
{
|
|
|
|
load_plugin_textdomain('partnercenter-api', false, plugin_basename(dirname(__FILE__)).'/languages');
|
|
|
|
}
|
|
add_action('plugins_loaded', 'partnercenter_api_load_textdomain');
|
|
|
|
/**
|
|
* Function to run after plugin activation
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
function partnercenter_api_activate()
|
|
{
|
|
|
|
// Add event to wp cron
|
|
wp_schedule_event(time(), 'hourly', 'partnercenter_api_fetch_orders_status');
|
|
|
|
}
|
|
register_activation_hook(__FILE__, 'partnercenter_api_activate');
|
|
|
|
/**
|
|
* AP-38: Selbstheilung des Status-Cron.
|
|
*
|
|
* Der stündliche Status-Abgleich wurde bisher NUR bei der Plugin-Aktivierung
|
|
* eingeplant. Nach einem In-Place-Update (ohne echte Deaktivierung + Reaktivierung)
|
|
* fehlte der Event dauerhaft — es lief keine Statusabfrage mehr, und die Ampel
|
|
* blieb bei abgeschlossenen Bestellungen orange. Hier bei jedem Request prüfen und
|
|
* bei Bedarf nachplanen (wp_next_scheduled ist billig, wp_schedule_event feuert nur,
|
|
* wenn der Event fehlt).
|
|
*
|
|
* @since 1.6.0
|
|
*/
|
|
function partnercenter_api_ensure_cron()
|
|
{
|
|
if (! wp_next_scheduled('partnercenter_api_fetch_orders_status')) {
|
|
wp_schedule_event(time(), 'hourly', 'partnercenter_api_fetch_orders_status');
|
|
}
|
|
}
|
|
add_action('init', 'partnercenter_api_ensure_cron');
|
|
|
|
/**
|
|
* Function to run after plugin deactivation
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
function partnercenter_api_deactivate()
|
|
{
|
|
|
|
/*
|
|
* Remove order status check from wp cron
|
|
*/
|
|
$timestamp = wp_next_scheduled('partnercenter_api_fetch_orders_status');
|
|
wp_unschedule_event($timestamp, 'partnercenter_api_fetch_orders_status');
|
|
// Clean hook
|
|
wp_clear_scheduled_hook('partnercenter_api_fetch_orders_status');
|
|
|
|
}
|
|
register_deactivation_hook(__FILE__, 'partnercenter_api_deactivate');
|
|
|
|
/**
|
|
* Load API class if needed
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
function partnercenter_api_init()
|
|
{
|
|
|
|
/**
|
|
* Load the API class.
|
|
*/
|
|
require_once plugin_dir_path(__FILE__).'public/partnercenter-api/partnercenter-api.php';
|
|
|
|
return new PARTNERCENTER_API_Requests;
|
|
|
|
}
|
|
add_filter('PARTNERCENTER_API', 'partnercenter_api_init');
|
|
|
|
/*
|
|
* Load all public features.
|
|
*/
|
|
// Load testing short code
|
|
require_once 'public/shortcode.php';
|
|
// Load WooCommerce status related features
|
|
require_once 'public/woocommerce/order-status.php';
|
|
// Load DHL label forwarding ("DHL for WooCommerce" integration)
|
|
require_once 'public/woocommerce/dhl-label.php';
|
|
// Load endpoint
|
|
require_once 'public/end-point.php';
|
|
|
|
/*
|
|
* Load admin features.
|
|
*/
|
|
if (is_admin()) {
|
|
|
|
// Load post list features
|
|
require_once 'admin/post-list.php';
|
|
|
|
// Load button to forward order to fulfilment by PARTNERCENTER
|
|
require_once 'admin/order-forwarding-button-metabox.php';
|
|
|
|
}
|