-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetways-wp-postsync.php
More file actions
89 lines (78 loc) · 3.5 KB
/
Copy pathnetways-wp-postsync.php
File metadata and controls
89 lines (78 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* Plugin Name: NETWAYS WP PostSync
* Plugin URI: https://netways.de
* Description: Spiegelt Beiträge einer oder mehrerer WordPress-Quellen (REST-API) als verlinkte Teaser-Posts ins lokale WordPress — SEO-sicher (optional Cross-Domain-Canonical + 301), mit optionalem Featured-Image-Sideload und optionaler WP-Media-Folder-Zuordnung. Pull-Modell via WP-Cron.
* Version: 1.0.0
* Author: NETWAYS
* Author URI: https://netways.de
* License: Apache-2.0
* License URI: https://www.apache.org/licenses/LICENSE-2.0
* Text Domain: netways-wp-postsync
* Requires at least: 6.0
* Requires PHP: 7.4
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
define( 'NETWAYS_WP_POSTSYNC_VERSION', '1.0.0' );
define( 'NETWAYS_WP_POSTSYNC_FILE', __FILE__ );
define( 'NETWAYS_WP_POSTSYNC_PATH', plugin_dir_path( __FILE__ ) );
define( 'NETWAYS_WP_POSTSYNC_URL', plugin_dir_url( __FILE__ ) );
/** Name of the WP-Cron hook that triggers a sync run. */
define( 'NETWAYS_WP_POSTSYNC_CRON_HOOK', 'netways_wp_postsync_sync_run' );
require_once NETWAYS_WP_POSTSYNC_PATH . 'includes/class-netways-wp-postsync-settings.php';
require_once NETWAYS_WP_POSTSYNC_PATH . 'includes/class-netways-wp-postsync-media.php';
require_once NETWAYS_WP_POSTSYNC_PATH . 'includes/class-netways-wp-postsync-sync.php';
require_once NETWAYS_WP_POSTSYNC_PATH . 'includes/class-netways-wp-postsync-frontend.php';
require_once NETWAYS_WP_POSTSYNC_PATH . 'includes/class-netways-wp-postsync-admin.php';
/**
* Boot the plugin once all plugins are loaded.
*/
function netways_wp_postsync_bootstrap() {
Netways_WP_PostSync_Settings::instance();
Netways_WP_PostSync_Frontend::instance();
if ( is_admin() ) {
Netways_WP_PostSync_Admin::instance();
}
// The cron callback resolves the sync runner lazily so the heavy
// wp-admin/includes files are only loaded during an actual run.
add_action( NETWAYS_WP_POSTSYNC_CRON_HOOK, 'netways_wp_postsync_run_sync' );
}
add_action( 'plugins_loaded', 'netways_wp_postsync_bootstrap' );
/**
* Execute a full sync run. Shared by WP-Cron and the manual trigger.
*
* @param bool $run_now Run even when the "Sync aktiv" toggle is off (manual trigger).
* @param bool $force_reapply Re-write every field even when the source is unchanged.
* @return array Run statistics (created, updated, skipped, drafted, errors).
*/
function netways_wp_postsync_run_sync( $run_now = false, $force_reapply = false ) {
return ( new Netways_WP_PostSync_Sync() )->run( $run_now, $force_reapply );
}
/**
* Register the recurring cron event on activation.
*/
function netways_wp_postsync_activate() {
Netways_WP_PostSync_Settings::install_defaults();
netways_wp_postsync_reschedule_cron();
}
register_activation_hook( __FILE__, 'netways_wp_postsync_activate' );
/**
* Clear the scheduled event on deactivation. Synced posts/media are kept.
*/
function netways_wp_postsync_deactivate() {
wp_clear_scheduled_hook( NETWAYS_WP_POSTSYNC_CRON_HOOK );
}
register_deactivation_hook( __FILE__, 'netways_wp_postsync_deactivate' );
/**
* (Re)schedule the cron event using the configured interval. Called on
* activation and whenever the interval setting changes.
*/
function netways_wp_postsync_reschedule_cron() {
wp_clear_scheduled_hook( NETWAYS_WP_POSTSYNC_CRON_HOOK );
$recurrence = Netways_WP_PostSync_Settings::get( 'cron_recurrence', 'hourly' );
if ( ! wp_next_scheduled( NETWAYS_WP_POSTSYNC_CRON_HOOK ) ) {
wp_schedule_event( time() + 60, $recurrence, NETWAYS_WP_POSTSYNC_CRON_HOOK );
}
}