-
Notifications
You must be signed in to change notification settings - Fork 2
/
plugin-name.php
87 lines (72 loc) · 2.58 KB
/
plugin-name.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
<?php
/**
* Main Plugin File
*
* @link http://example.com
* @since 1.0.0
* @package Plugin_Name
*
* @wordpress-plugin
* Plugin Name: PWPF - Plugin WordPress Framework
* Plugin URI: http://example.com/plugin-name-uri/
* Description: This is a short description of what the plugin does. It's displayed in the WordPress admin area.
* Version: 1.0.0
* Author: Your Name or Your Company
* Author URI: http://example.com/
* Text Domain: plugin-name
* Domain Path: /languages
*/
// If this file is called directly, abort.
use Plugin_Name\App\Activator;
use Plugin_Name\App\Deactivate;
use Plugin_Name\App\Update;
use Plugin_Name\Includes\RequirementsChecker;
use const Plugin_Name\MAIN_PATH;
if (!defined('WPINC')) {
die;
}
define('Plugin_Name\MAIN_PATH', __DIR__ . DIRECTORY_SEPARATOR);
/**
* Load PSR-4
*/
require_once __DIR__ . '/vendor_prefixed/autoload.php';
include_once __DIR__ . '/vendor_prefixed/dframe/src/Functions.php';
/**
* Creates/Maintains the object of Requirements Checker Class
*
* @return RequirementsChecker
* @since 1.0.0
*/
try {
register_activation_hook(MAIN_PATH . 'plugin-name.php', [new Activator(), 'activate']);
register_deactivation_hook(MAIN_PATH . 'plugin-name.php', [new Deactivate(), 'deactivate']);
add_action('upgrader_process_complete', [new Update(), 'update'], 10, 2);
$requirementsChecker = \Plugin_Name\Includes\RequirementsChecker::getPluginRequirementsChecker();
if (!$requirementsChecker->requirementsMet()) {
add_action('admin_notices', [$requirementsChecker, 'showRequirementsErrors']);
// Deactivate plugin immediately if requirements are not met.
require_once(ABSPATH . 'wp-admin' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'plugin.php');
deactivate_plugins(plugin_basename(__FILE__));
throw new Exception('Plugin Name plugin requirements are not met.');
}
} catch (Exception $e) {
return (new \Plugin_Name\App\Deactivate())->deactivate();
}
if (!function_exists('dieTriggerError')) {
function dieTriggerError($e)
{
add_action('get_header', function () use ($e) {
if (is_user_logged_in()) {
wp_die($e);
}
wp_die(
'<h1>There is a problem with website.</h1><br />We got the information and are already on it. Please check back later.'
);
});
}
}
try {
$app = new \Plugin_Name\Includes\Plugin_Name::getPluginName();
} catch (Throwable $e) {
dieTriggerError($e);
}