| 1 |
<?php |
| 2 |
/** |
| 3 |
* The plugin file path class. |
| 4 |
* |
| 5 |
* @since 1.0.0 |
| 6 |
* |
| 7 |
* @package woo-additional-terms |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace Woo_Additional_Terms; |
| 11 |
|
| 12 |
/** |
| 13 |
* Class File. |
| 14 |
*/ |
| 15 |
class File { |
| 16 |
|
| 17 |
/** |
| 18 |
* The plugin file path. |
| 19 |
* |
| 20 |
* @since 1.0.0 |
| 21 |
* |
| 22 |
* @var string |
| 23 |
*/ |
| 24 |
private $file; |
| 25 |
|
| 26 |
/** |
| 27 |
* Constructor. |
| 28 |
* |
| 29 |
* @since 1.0.0 |
| 30 |
* |
| 31 |
* @param string $file The plugin file. |
| 32 |
* |
| 33 |
* @return void |
| 34 |
*/ |
| 35 |
public function __construct( $file ) { |
| 36 |
|
| 37 |
$this->file = $file; |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Return the plugin file. |
| 42 |
* |
| 43 |
* @since 1.0.0 |
| 44 |
* |
| 45 |
* @return string |
| 46 |
*/ |
| 47 |
public function plugin_file() { |
| 48 |
|
| 49 |
return $this->file; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Return the plugin base name. |
| 54 |
* |
| 55 |
* @since 1.0.0 |
| 56 |
* |
| 57 |
* @return string |
| 58 |
*/ |
| 59 |
public function plugin_basename() { |
| 60 |
|
| 61 |
return plugin_basename( $this->file ); |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Return the plugin path. |
| 66 |
* |
| 67 |
* @since 1.0.0 |
| 68 |
* |
| 69 |
* @param string $path The path to the file. |
| 70 |
* |
| 71 |
* @return string |
| 72 |
*/ |
| 73 |
public function plugin_path( $path = '' ) { |
| 74 |
|
| 75 |
return path_join( plugin_dir_path( $this->file ), $path ); |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Return the plugin url. |
| 80 |
* |
| 81 |
* @since 1.0.0 |
| 82 |
* |
| 83 |
* @param string $path The path to the file. |
| 84 |
* |
| 85 |
* @return string |
| 86 |
*/ |
| 87 |
public function plugin_url( $path = '' ) { |
| 88 |
|
| 89 |
return plugins_url( $path, $this->file ); |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Return plugin dirname. |
| 94 |
* |
| 95 |
* @since 1.6.0 |
| 96 |
* |
| 97 |
* @return string |
| 98 |
*/ |
| 99 |
public function dirname() { |
| 100 |
|
| 101 |
return dirname( plugin_basename( $this->file ) ); |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* Returns a full path for the asset (static resource CSS/JS) file. |
| 106 |
* |
| 107 |
* @since 1.0.0 |
| 108 |
* |
| 109 |
* @param string $file_name Asset file name (filename). |
| 110 |
* |
| 111 |
* @return string |
| 112 |
*/ |
| 113 |
public function asset_path( $file_name ) { |
| 114 |
|
| 115 |
$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : trailingslashit( 'minified' ); |
| 116 |
$directory = pathinfo( $file_name, PATHINFO_EXTENSION ); |
| 117 |
|
| 118 |
return woo_additional_terms()->service( 'file' )->plugin_url( "assets/{$directory}/{$min}{$file_name}" ); |
| 119 |
} |
| 120 |
} |
| 121 |
|