-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththe-plugin.php
98 lines (86 loc) · 2.45 KB
/
the-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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
* The Plugin
*
* @package ThePlugin
* @copyright Copyright(c) YYYY, Plugin Author
* @license http://opensource.org/licenses/GPL-2.0 GNU General Public License, version 2 (GPL-2.0)
*
* Plugin Name: The Plugin
* Plugin URI: https://pluginsite.com
* Description: Give a description for The Plugin.
* Version: 0.0.0
* Author: Plugin Author
* Author URI: https://authorsite.com
* License: GPL2
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: the-plugin
* Domain Path: /languages
* Network: false
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Setup the plugin auto loader.
require_once( 'php/autoloader.php' );
/**
* Admin notice for incompatible versions of PHP.
*/
function _the_plugin_php_version_error() {
printf( '<div class="error"><p>%s</p></div>', esc_html( _the_plugin_php_version_text() ) );
}
/**
* String describing the minimum PHP version.
*
* "Namespace" is a PHP 5.3 introduced feature. This is a hard requirement
* for the plugin structure.
*
* "Traits" is a PHP 5.4 introduced feature. Remove "Traits" support from
* php/autoloader if you want to support a lower PHP version.
* Remember to update the checked version below if you do.
*
* @return string
*/
function _the_plugin_php_version_text() {
return __( 'The Plugin plugin error: Your version of PHP is too old to run this plugin. You must be running PHP 5.4 or higher.', 'the-plugin' );
}
// If the PHP version is too low, show warning and return.
if ( version_compare( phpversion(), '5.4', '<' ) ) {
if ( defined( 'WP_CLI' ) ) {
WP_CLI::warning( _the_plugin_php_version_text() );
} else {
add_action( 'admin_notices', '_the_plugin_php_version_error' );
}
return;
}
/**
* Get the plugin object.
*
* @return \ThePlugin\PluginInterface
*/
function the_plugin() {
static $instance;
if ( null === $instance ) {
$instance = new \ThePlugin\Plugin();
}
return $instance;
}
/**
* Setup the plugin instance.
*/
the_plugin()
->set_basename( plugin_basename( __FILE__ ) )
->set_directory( plugin_dir_path( __FILE__ ) )
->set_file( __FILE__ )
->set_slug( 'the-plugin' )
->set_url( plugin_dir_url( __FILE__ ) );
/**
* Register plugin components.
*/
the_plugin()
->register_component( new \ThePlugin\View\AdminMenu() );
/**
* Sometimes we need to do some things after the plugin is loaded, so call the PluginInterface::plugin_loaded().
*/
add_action( 'plugins_loaded', array( the_plugin(), 'plugin_loaded' ) );