-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathplugin-boilerplate.php
131 lines (116 loc) · 3.89 KB
/
plugin-boilerplate.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
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
<?php
/**
* The plugin bootstrap file
*
* This file is read by WordPress to generate the plugin information in the plugin
* admin area. This file also includes all of the dependencies used by the plugin,
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @link plugin_author_url
* @since 1.0.0
* @package Root
*
* @wordpress-plugin
* Plugin Name: my_plugin_name
* Plugin URI:
* Description: Plugin Description
* Version: 1.0.0
* Author: plugin_author_name
* Author URI: plugin_author_url
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Requires PHP: 7.4
* Text Domain: text-domain
*/
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! defined( 'PREFIX_VERSION' ) ) {
define( 'PREFIX_VERSION', '1.0.0' );
}
/**
* Check PHP version
*/
if ( function_exists( 'phpversion' ) ) {
if ( version_compare( phpversion(), '7.4', '<' ) ) {
add_action(
'admin_notices',
function() {
echo "<div class='notice notice-error is-dismissible'>";
/* translators: 1: Opening <p> HTML element 2: Opening <strong> HTML element 3: Closing <strong> HTML element 4: Closing <p> HTML element */
echo sprintf( esc_html__( '%1$s%2$s my_plugin_name NOTICE:%3$s PHP version too low to use this plugin. Please change to at least PHP 7.4. You can contact your web host for assistance in updating your PHP version.%4$s', 'text-domain' ), '<p>', '<strong>', '</strong>', '</p>' );
echo '</div>';
}
);
return;
}
}
/**
* Check PHP versions
*/
if ( defined( 'PHP_VERSION' ) ) {
if ( version_compare( PHP_VERSION, '7.4', '<' ) ) {
add_action(
'admin_notices',
function() {
echo "<div class='notice notice-error is-dismissible'>";
/* translators: 1: Opening <p> HTML element 2: Opening <strong> HTML element 3: Closing <strong> HTML element 4: Closing <p> HTML element */
echo sprintf( esc_html__( '%1$s%2$s my_plugin_name NOTICE:%3$s PHP version too low to use this plugin. Please change to at least PHP 7.4. You can contact your web host for assistance in updating your PHP version.%4$s', 'text-domain' ), '<p>', '<strong>', '</strong>', '</p>' );
echo '</div>';
}
);
return;
}
}
// Composer autoload.
require_once dirname( __FILE__ ) . '/vendor/autoload.php';
/**
* The code that runs during plugin activation.
* This action is documented in includes/class-prefix-activator.php
*/
if ( ! function_exists( 'activate_prefix' ) ) {
/**
* Code to run when plugin is activated.
*
* @return void
*/
function activate_prefix() {
\Root\Notices\RootActivator::activate();
}
}
/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-prefix-deactivator.php
*/
if ( ! function_exists( 'deactivate_prefix' ) ) {
/**
* Code to run when plugin is deactivated.
*
* @return void
*/
function deactivate_prefix() {
\Root\Notices\RootDeactivator::deactivate();
}
}
register_activation_hook( __FILE__, 'activate_prefix' );
register_deactivation_hook( __FILE__, 'deactivate_prefix' );
define( 'PREFIX_BASE_FILE', basename( plugin_dir_path( __FILE__ ) ) );
define( 'PREFIX_PLUGIN_NAME', 'my_plugin_shortname' );
define( 'PREFIX_PLUGIN_DIR', __DIR__ . '/' );
define( 'PREFIX_PLUGIN_ASSETS_DIR', __DIR__ . '/assets/' );
define( 'PREFIX_PLUGIN_ASSETS_PATH_URL', plugin_dir_url( __FILE__ ) . 'assets/' );
define( 'PREFIX_PLUGIN_PATH_URL', plugin_dir_url( __FILE__ ) );
$debug = false;
// Add SL_DEV_DEBUGGING to your wp-config.php file on your test environment. Feel free to rename constant.
if ( defined( 'SL_DEV_DEBUGGING' ) ) {
$debug = true;
}
define( 'PREFIX_DEBUG', $debug );
if ( ! function_exists( 'PREFIX_INIT' ) ) {
function PREFIX_INIT() {
$plugin_instance = \Root\Bootstrap\Main::getInstance();
$plugin_instance->run();
}
}
add_action( 'plugins_loaded', 'PREFIX_INIT' );