-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclockwork-for-wp.php
90 lines (71 loc) · 1.93 KB
/
clockwork-for-wp.php
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
90
<?php
declare(strict_types=1);
use Clockwork_For_Wp\Plugin;
/*
* A basic Clockwork integration for WordPress.
*
* @package clockwork_for_wp
*/
/*
* Plugin Name: Clockwork for WP
* Plugin URI: https://github.com/ssnepenthe/clockwork-for-wp
* Description: A basic <a href="https://underground.works/clockwork/">Clockwork</a> integration for WordPress.
* Version: 0.1.0
* Author: Ryan McLaughlin
* Author URI: https://github.com/ssnepenthe
* License: MIT
*/
if ( ! \defined( 'ABSPATH' ) ) {
exit;
}
function _cfw_deactivate_self(): void {
if ( isset( $_GET['activate'] ) ) {
unset( $_GET['activate'] );
}
\deactivate_plugins( __FILE__ );
}
function _cfw_admin_error_notice( $message ): void {
$notice = <<<'EOD'
<div class="notice notice-error">
<p>Clockwork for WP: %s</p>
</div>
EOD;
\printf( $notice, \esc_html( $message ) );
}
if ( ! \function_exists( 'wp_get_environment_type' ) ) {
\add_action( 'admin_init', '_cfw_deactivate_self' );
\add_action(
'admin_notices',
static function (): void {
\_cfw_admin_error_notice( 'Plugin deactivated: This plugin requires WordPress version 5.5.0 or greater.' );
}
);
return;
}
if (
'production' === \wp_get_environment_type()
&& ! ( \defined( 'CFW_RUN_ON_PROD' ) && CFW_RUN_ON_PROD )
) {
\add_action( 'admin_init', '_cfw_deactivate_self' );
\add_action(
'admin_notices',
static function (): void {
\_cfw_admin_error_notice( 'Plugin deactivated: This plugin can only run on non-production environments.' );
}
);
return;
}
if ( ! \file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
\add_action(
'admin_notices',
static function (): void {
\_cfw_admin_error_notice( 'Plugin not loaded: Unable to locate Composer autoloader.' );
}
);
return;
}
require_once __DIR__ . '/vendor/autoload.php';
// @todo Check for minimum php version.
// @todo Check that dependencies have been installed.
require_once __DIR__ . '/src/instance.php';
\_cfw_instance()->run();