-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlugin.php
130 lines (112 loc) · 2.59 KB
/
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
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
<?php
namespace Endurance_WP_Plugin_Updater;
/**
* Class Plugin
*
* Get information about the current plugin context.
*
* @method author
* @method author_uri
* @method description
* @method domain_path
* @method license
* @method license_uri
* @method name
* @method requires_wp_version
* @method requires_php_version
* @method text_domain
* @method uri
* @method version
*/
class Plugin {
/**
* A collection of valid WordPress plugin file headers.
*
* @var array
*/
const HEADERS = array(
'author' => 'Author',
'author_uri' => 'AuthorURI',
'description' => 'Description',
'domain_path' => 'DomainPath',
'license' => 'License',
'license_uri' => 'LicenseURI',
'name' => 'Name',
'requires_wp_version' => 'RequiresAtLeast',
'requires_php_version' => 'RequiresPHP',
'text_domain' => 'TextDomain',
'uri' => 'PluginURI',
'version' => 'Version',
);
/**
* The absolute path to the plugin file.
*
* @var string
*/
protected $file;
/**
* Plugin constructor.
*
* @param string $file The absolute path to the plugin file.
*/
public function __construct( $file = __FILE__ ) {
$this->file = $file;
}
/**
* Get the plugin basename.
*
* @return string
*/
public function basename() {
return plugin_basename( $this->file );
}
/**
* Get the plugin slug.
*
* @return string
*/
public function slug() {
return basename( plugin_dir_path( $this->file ) );
}
/**
* Get a specific plugin file header.
*
* @param string $name The plugin file header name.
*
* @return string
*/
protected function get_file_header( $name ) {
$file_headers = $this->get_file_headers();
return (string) isset( $file_headers[ $name ] ) ? $file_headers[ $name ] : '';
}
/**
* Get all plugin file headers.
*
* @return array
*/
protected function get_file_headers() {
static $file_headers = array();
if ( empty( $file_headers ) ) {
if ( ! function_exists( 'get_plugin_data' ) ) {
require wp_normalize_path( ABSPATH . '/wp-admin/includes/plugin.php' );
}
$file_headers = get_plugin_data( $this->file );
}
return $file_headers;
}
/**
* Magic method for fetching data from plugin file headers.
*
* @param string $name The method name.
* @param array $args The method parameters.
*
* @return string
*/
public function __call( $name, $args ) {
$value = '';
if ( array_key_exists( $name, $this::HEADERS ) ) {
$value = $this->get_file_header( $this::HEADERS[ $name ] );
}
return $value;
}
}