-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-plugin.php
81 lines (73 loc) · 2.2 KB
/
wp-plugin.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
<?php
/**
* Plugin Name: WP Plugin
* Plugin URI: #
* Description: My WordPress plugin boilerplate.
* Author: #
* Author URI: #
* Version: 1.0.0
* Text Domain: wp-plugin
* Tested up to: 5.5
*/
// Useful constants.
define('WP_PLUGIN_DIR', __DIR__ . '/');
define('WP_PLUGIN_URI', plugins_url('/', __FILE__));
define('WP_PLUGIN_VER', '1.0.0');
/**
* Do activation
*
* @see https://developer.wordpress.org/reference/functions/register_activation_hook/
*/
function wp_plugin_activate($network)
{
try {
if (version_compare(PHP_VERSION, '7.2', '<')) {
throw new Exception(__('This plugin requires PHP version 7.2 at least!', 'textdomain'));
}
if (version_compare($GLOBALS['wp_version'], '5.2', '<')) {
throw new Exception(__('This plugin requires WordPress version 5.2 at least!', 'textdomain'));
}
if (!defined('WP_CONTENT_DIR') || !is_writable(WP_CONTENT_DIR)) {
throw new Exception(__('WordPress content directory is inaccessible.', 'textdomain'));
}
} catch (Exception $e) {
if (defined('DOING_AJAX') && DOING_AJAX) {
header('Content-Type: application/json; charset=' . get_option('blog_charset'));
status_header(500);
exit(json_encode([
'success' => false,
'name' => __('Plugin Activation Error', 'textdomain'),
'message' => $e->getMessage()
]));
} else {
exit($e->getMessage());
}
}
// Maybe add default settings.
// add_option({$settings_key}, [
//
// ]);
}
register_activation_hook(__FILE__, 'wp_plugin_activate');
/**
* Do installation
*
* @see https://developer.wordpress.org/reference/hooks/plugins_loaded/
*/
function wp_plugin_install()
{
// Make sure translation is available.
load_plugin_textdomain('textdomain', false, 'wp-plugin/languages');
// Load resources
}
add_action('plugins_loaded', 'wp_plugin_install', 10, 0);
/**
* Do deactivation
*
* @see https://developer.wordpress.org/reference/functions/register_deactivation_hook/
*/
function wp_plugin_deactivate($network)
{
// Do something
}
register_activation_hook(__FILE__, 'wp_plugin_deactivate');