-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipecode-instagram-apify.php
More file actions
70 lines (56 loc) · 2.77 KB
/
Copy pathpipecode-instagram-apify.php
File metadata and controls
70 lines (56 loc) · 2.77 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
<?php
/**
* Plugin Name: Pipecode Instagram Apify
* Plugin URI: https://pipe-code.github.io/
* Description: Syncs the latest Instagram posts via Apify and stores them in a custom table. Includes REST API and admin panel.
* Version: 1.0.2
* Author: Pipecode
* Author URI: https://pipe-code.github.io/
* License: GPL v2 or later
* Text Domain: pipecode-instagram-apify
*/
defined('ABSPATH') || exit;
define('PC_INSTAGRAM_VERSION', '1.0.2');
define('PC_INSTAGRAM_DIR', plugin_dir_path(__FILE__));
define('PC_INSTAGRAM_URL', plugin_dir_url(__FILE__));
define('PC_INSTAGRAM_TABLE', 'instagram_posts');
require_once PC_INSTAGRAM_DIR . 'includes/class-instagram-db.php';
require_once PC_INSTAGRAM_DIR . 'includes/class-instagram-sync.php';
require_once PC_INSTAGRAM_DIR . 'includes/class-instagram-admin.php';
require_once PC_INSTAGRAM_DIR . 'includes/class-instagram-api.php';
// ── Activation ──────────────────────────────────────────────────────────────
register_activation_hook(__FILE__, ['PC_Instagram_DB', 'create_table']);
register_activation_hook(__FILE__, function () {
if (! wp_next_scheduled('pc_instagram_daily_sync')) {
$next_6am = strtotime('today 06:00 UTC');
if ($next_6am <= time()) {
$next_6am = strtotime('tomorrow 06:00 UTC');
}
wp_schedule_event($next_6am, 'daily', 'pc_instagram_daily_sync');
}
});
// ── Deactivation — wipe everything ──────────────────────────────────────────
register_deactivation_hook(__FILE__, function () {
// Cancel cron
$timestamp = wp_next_scheduled('pc_instagram_daily_sync');
if ($timestamp) {
wp_unschedule_event($timestamp, 'pc_instagram_daily_sync');
}
// Drop custom table
PC_Instagram_DB::drop_table();
// Delete all plugin options
delete_option('pc_instagram_settings');
delete_option('pc_instagram_last_sync');
delete_option('pc_instagram_db_version');
});
// ── Cron ────────────────────────────────────────────────────────────────────
add_action('pc_instagram_daily_sync', function () {
@set_time_limit(300);
$sync = new PC_Instagram_Sync();
$sync->run();
});
// ── Boot ────────────────────────────────────────────────────────────────────
add_action('plugins_loaded', function () {
PC_Instagram_Admin::init();
PC_Instagram_API::init();
});