-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathassetdrips.php
More file actions
79 lines (70 loc) · 2.61 KB
/
Copy pathassetdrips.php
File metadata and controls
79 lines (70 loc) · 2.61 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
<?php
/**
* Plugin Name: AssetDrips
* Plugin URI: https://codedrips.com/assetdrips
* Description: Find, organise, and optimise large WordPress media libraries — non-destructively. Unused-media detection (Sift), a fast index with faceted search (Find), folders/tags/bulk-edit (Sort), and image optimisation with WebP/AVIF (Squeeze).
* Version: 1.0.0
* Requires at least: 6.0
* Requires PHP: 8.1
* Author: CodeDrips
* Author URI: https://codedrips.com
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: assetdrips
*
* @package AssetDrips
*/
declare( strict_types=1 );
namespace AssetDrips;
defined( 'ABSPATH' ) || exit;
define( 'ASSETDRIPS_VERSION', '1.0.0' );
define( 'ASSETDRIPS_FILE', __FILE__ );
define( 'ASSETDRIPS_DIR', plugin_dir_path( __FILE__ ) );
define( 'ASSETDRIPS_URL', plugin_dir_url( __FILE__ ) );
// Composer autoloader. Required for the PSR-4 AssetDrips\ namespace.
$assetdrips_autoload = __DIR__ . '/vendor/autoload.php';
if ( is_readable( $assetdrips_autoload ) ) {
require $assetdrips_autoload;
}
/**
* Activation: install/upgrade custom tables, then kick off the initial index
* backfill so an existing library is searchable without a manual CLI step.
*
* The recurring reconcile (registered in Plugin::boot()) is scheduled to first
* run on the very next WP-Cron tick instead of the default +1 hour, so the
* index builds itself shortly after activation. reconcile() backfills every
* attachment missing from the index (IDX-06) and is idempotent. boot()'s own
* `wp_next_scheduled()` guard then sees this schedule and does not double-book.
*/
register_activation_hook(
__FILE__,
static function (): void {
Db\Schema::install();
if ( ! wp_next_scheduled( 'assetdrips_index_reconcile' ) ) {
wp_schedule_event( time(), 'daily', 'assetdrips_index_reconcile' );
}
}
);
/**
* Deactivation: no destructive teardown of data or tables — they persist so a
* reactivation resumes cleanly. Only the self-scheduled cron events are cleared
* so they do not fire while the plugin is inactive; they reschedule on next boot.
*/
register_deactivation_hook(
__FILE__,
static function (): void {
wp_clear_scheduled_hook( 'assetdrips_index_reconcile' );
wp_clear_scheduled_hook( 'assetdrips_usage_refresh' );
wp_clear_scheduled_hook( 'assetdrips_squeeze_batch' );
wp_clear_scheduled_hook( 'assetdrips_squeeze_single' );
}
);
/**
* Boot the plugin once WordPress and all plugins are loaded.
*/
add_action(
'plugins_loaded',
static function (): void {
Plugin::instance()->boot();
}
);