-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhwp-previews.php
More file actions
143 lines (122 loc) · 3.53 KB
/
hwp-previews.php
File metadata and controls
143 lines (122 loc) · 3.53 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/**
* Plugin Name: HWP Previews
* Plugin URI: https://github.com/wpengine/hwptoolkit
* GitHub Plugin URI: https://github.com/wpengine/hwptoolkit
* Description: Headless Previews solution as a WordPress plugin with extensive configurability.
* Author: WPEngine Headless OSS Team
* Author URI: https://github.com/wpengine
* Update URI: https://github.com/wpengine/hwptoolkit
* Version: 1.0.1
* Text Domain: hwp-previews
* Domain Path: /languages
* Requires at least: 6.0
* Tested up to: 6.9
* Requires PHP: 7.4+
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*
* @package HWP\Previews
*/
declare(strict_types=1);
use HWP\Previews\Autoloader;
use HWP\Previews\Plugin;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Load the autoloader.
require_once __DIR__ . '/src/Autoloader.php';
if ( ! Autoloader::autoload() ) {
return;
}
if ( file_exists( __DIR__ . '/activation.php' ) ) {
require_once __DIR__ . '/activation.php';
// @phpstan-ignore-next-line
register_activation_hook( __FILE__, 'hwp_previews_activation_callback' );
}
if ( file_exists( __DIR__ . '/deactivation.php' ) ) {
require_once __DIR__ . '/deactivation.php';
// @phpstan-ignore-next-line
register_deactivation_hook( __FILE__, 'hwp_previews_deactivation_callback' );
}
// phpcs:enable Generic.Metrics.CyclomaticComplexity.TooHigh
// phpcs:enable SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
if ( ! function_exists( 'hwp_previews_init' ) ) {
/**
* Initializes plugin.
*/
function hwp_previews_init(): void {
hwp_previews_constants();
hwp_previews_plugin_init();
hwp_previews_plugin_admin_notice();
}
}
if ( ! function_exists( 'hwp_previews_constants' ) ) {
/**
* Define plugin constants.
*/
function hwp_previews_constants(): void {
if ( ! defined( 'HWP_PREVIEWS_VERSION' ) ) {
define( 'HWP_PREVIEWS_VERSION', '1.0.1' );
}
if ( ! defined( 'HWP_PREVIEWS_PLUGIN_DIR' ) ) {
define( 'HWP_PREVIEWS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
if ( ! defined( 'HWP_PREVIEWS_PLUGIN_URL' ) ) {
define( 'HWP_PREVIEWS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
if ( ! defined( 'HWP_PREVIEWS_SETTINGS_GROUP' ) ) {
define( 'HWP_PREVIEWS_SETTINGS_GROUP', 'hwp_previews_settings_group' );
}
if ( ! defined( 'HWP_PREVIEWS_SETTINGS_KEY' ) ) {
define( 'HWP_PREVIEWS_SETTINGS_KEY', 'hwp_previews_settings' );
}
}
}
if ( ! function_exists( 'hwp_previews_plugin_init' ) ) {
/**
* Initialize the HWP Previews plugin.
*/
function hwp_previews_plugin_init(): ?Plugin {
if ( ! defined( 'HWP_PREVIEWS_PLUGIN_DIR' ) ) {
return null;
}
require_once HWP_PREVIEWS_PLUGIN_DIR . 'src/Plugin.php';
return Plugin::init();
}
}
if ( ! function_exists( 'hwp_previews_plugin_admin_notice' ) ) {
/**
* Display an admin notice if the plugin is not properly initialized.
*/
function hwp_previews_plugin_admin_notice(): void {
if ( defined( 'HWP_PREVIEWS_PLUGIN_DIR' ) ) {
return;
}
add_action(
'admin_notices',
static function (): void {
?>
<div class="error notice">
<p>
<?php
echo 'Composer vendor directory must be present for HWP Previews to work.'
?>
</p>
</div>
<?php
},
10,
0
);
}
}
/**
* Load plugin text domain.
*/
function hwp_previews_load_textdomain(): void {
load_plugin_textdomain( 'hwp-previews', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
add_action( 'init', 'hwp_previews_load_textdomain', 1, 0 );
/** @psalm-suppress HookNotFound */
add_action( 'plugins_loaded', 'hwp_previews_init', 15, 0 );