Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Plugin | |
0.00% |
0 / 18 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| __set | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| setup | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace NewfoldLabs\WP\ModuleLoader; |
| 4 | |
| 5 | use WP_Forge\Fluent\Fluent; |
| 6 | |
| 7 | /** |
| 8 | * Plugin class. |
| 9 | * |
| 10 | * @property string $basename Plugin basename |
| 11 | * @property string $name Plugin name |
| 12 | * @property string $dir Plugin directory |
| 13 | * @property string $file Plugin file |
| 14 | * @property Fluent $headers Plugin file headers |
| 15 | * @property string $url Plugin URL |
| 16 | * @property string $version Plugin version |
| 17 | * |
| 18 | * @method void file( string $file ) |
| 19 | */ |
| 20 | class Plugin extends Fluent { |
| 21 | |
| 22 | public function __construct( $attributes = [] ) { |
| 23 | parent::__construct( $attributes ); |
| 24 | if ( $this->has( 'file' ) ) { |
| 25 | $this->setup( $this->file ); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | public function __set( $key, $value ) { |
| 30 | |
| 31 | switch ( $key ) { |
| 32 | case 'file': |
| 33 | $this->setup( $value ); |
| 34 | |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | $this->set( $key, $value ); |
| 39 | |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * When the plugin file is set, collect all the info we can about the plugin. |
| 44 | * |
| 45 | * @param string $file |
| 46 | */ |
| 47 | protected function setup( $file ) { |
| 48 | |
| 49 | $this->set( 'file', $file ); |
| 50 | $this->set( 'dir', plugin_dir_path( $file ) ); |
| 51 | $this->set( 'url', plugin_dir_url( $file ) ); |
| 52 | $this->set( 'basename', plugin_basename( $file ) ); |
| 53 | |
| 54 | if ( ! function_exists( 'get_plugin_data' ) ) { |
| 55 | require ABSPATH . 'wp-admin/includes/plugin.php'; |
| 56 | } |
| 57 | |
| 58 | $data = get_plugin_data( $file, true, false ); |
| 59 | |
| 60 | $this->set( 'name', $data['Name'] ?? '' ); |
| 61 | $this->set( 'version', $data['Version'] ?? '' ); |
| 62 | $this->headers = new Fluent( $data ); |
| 63 | |
| 64 | } |
| 65 | |
| 66 | } |