-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstants.php
91 lines (72 loc) · 2.03 KB
/
constants.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
<?php
namespace Helsinki\WordPress\Site\Core;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Condifugration
*/
function define_constants(string $file) : void {
if ( ! function_exists('get_plugin_data') ) {
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
$pluginData = get_plugin_data( $file, false, false );
$dirname = dirname( $file );
$basename = basename( $file );
$dirbasename = basename( $dirname );
$is_mu_plugin = (false !== strpos($file, WPMU_PLUGIN_DIR));
define( __NAMESPACE__ . '\\PLUGIN_VERSION', $pluginData['Version'] );
define( __NAMESPACE__ . '\\PLUGIN_MAIN_FILE', $file );
define( __NAMESPACE__ . '\\PLUGIN_PATH', $dirname . DIRECTORY_SEPARATOR );
define( __NAMESPACE__ . '\\PLUGIN_DIRNAME', $dirbasename );
define( __NAMESPACE__ . '\\PLUGIN_BASENAME', $basename );
define( __NAMESPACE__ . '\\PLUGIN_SLUG', str_replace( '-', '_', PLUGIN_DIRNAME ) );
define( __NAMESPACE__ . '\\PLUGIN_NAME', $dirbasename . DIRECTORY_SEPARATOR . $basename );
define( __NAMESPACE__ . '\\PLUGIN_URL', plugin_dir_url( $file ) );
define( __NAMESPACE__ . '\\IS_MUST_USE_PLUGIN', $is_mu_plugin );
}
/**
* Helpers
*/
function plugin_version() : string {
return PLUGIN_VERSION;
}
function plugin_main_file() : string {
return PLUGIN_MAIN_FILE;
}
function plugin_path() : string {
return PLUGIN_PATH;
}
function plugin_dirname() : string {
return PLUGIN_DIRNAME;
}
function plugin_basename() : string {
return PLUGIN_BASENAME;
}
function plugin_slug() : string {
return PLUGIN_SLUG;
}
function plugin_name() : string {
return PLUGIN_NAME;
}
function plugin_url() : string {
return PLUGIN_URL;
}
function is_debug() : bool {
return defined('WP_DEBUG') && WP_DEBUG;
}
function is_must_use_plugin() : bool {
return IS_MUST_USE_PLUGIN;
}
function asset_version() : string {
return is_debug() ? (string) time() : plugin_version();
}
function assets_url() : string {
return PLUGIN_URL . 'assets/';
}
function script_url() : string {
return assets_url() . 'js/';
}
function style_url() : string {
return assets_url() . 'css/';
}