Skip to content

Commit 9bd028a

Browse files
committed
Setup: Singleton full path
1 parent 353ec2f commit 9bd028a

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

class-plugin.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
declare( strict_types = 1 );
2323
namespace Peroks\WP\Plugin\Name;
2424

25-
require_once 'inc/trait-singleton.php';
25+
require_once __DIR__ . '/inc/trait-singleton.php';
2626

2727
/**
2828
* The plugin main class.
@@ -96,6 +96,26 @@ protected function run(): void {
9696
}
9797
}
9898

99+
/**
100+
* Gets the current plugin version.
101+
*/
102+
public static function version(): string {
103+
$version = wp_cache_get( 'version', self::PREFIX ) ?: '';
104+
105+
if ( empty( $version ) ) {
106+
if ( empty( function_exists( 'get_plugin_data' ) ) ) {
107+
if ( empty( is_readable( ABSPATH . 'wp-admin/includes/plugin.php' ) ) ) {
108+
return '';
109+
}
110+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
111+
}
112+
$data = get_plugin_data( self::FILE, false, false );
113+
$version = apply_filters( self::FILTER_PLUGIN_VERSION, $data['Version'], static::class );
114+
wp_cache_set( 'version', $version, self::PREFIX );
115+
}
116+
return $version;
117+
}
118+
99119
/**
100120
* Gets a full filesystem path from a local path.
101121
*
@@ -121,26 +141,6 @@ public static function url( string $path = '' ): string {
121141
$url = plugins_url( $path, self::FILE );
122142
return apply_filters( self::FILTER_PLUGIN_URL, $url, $path );
123143
}
124-
125-
/**
126-
* Gets the current plugin version.
127-
*/
128-
public static function version(): string {
129-
$version = wp_cache_get( 'version', self::PREFIX ) ?: '';
130-
131-
if ( empty( $version ) ) {
132-
if ( empty( function_exists( 'get_plugin_data' ) ) ) {
133-
if ( empty( is_readable( ABSPATH . 'wp-admin/includes/plugin.php' ) ) ) {
134-
return '';
135-
}
136-
require_once ABSPATH . 'wp-admin/includes/plugin.php';
137-
}
138-
$data = get_plugin_data( self::FILE, false, false );
139-
$version = $data['Version'];
140-
wp_cache_set( 'version', $version, self::PREFIX );
141-
}
142-
return apply_filters( self::FILTER_PLUGIN_VERSION, $version );
143-
}
144144
}
145145

146146
// Registers and runs the main plugin class.

0 commit comments

Comments
 (0)