| 1 |
<?php |
| 2 |
namespace Crocoblock\Blocks_Style; |
| 3 |
|
| 4 |
/** |
| 5 |
* Path and URL trait |
| 6 |
* |
| 7 |
* @since 1.0.0 |
| 8 |
*/ |
| 9 |
trait Path_Url_Trait { |
| 10 |
|
| 11 |
/** |
| 12 |
* Module directory path. |
| 13 |
* |
| 14 |
* @since 1.0.0 |
| 15 |
* @access protected |
| 16 |
* @var srting. |
| 17 |
*/ |
| 18 |
protected $path; |
| 19 |
|
| 20 |
/** |
| 21 |
* Module directory URL. |
| 22 |
* |
| 23 |
* @since 1.0.0 |
| 24 |
* @access protected |
| 25 |
* @var srting. |
| 26 |
*/ |
| 27 |
protected $url; |
| 28 |
|
| 29 |
/** |
| 30 |
* Set module directory path |
| 31 |
* |
| 32 |
* @param string $path Path. |
| 33 |
* @return self |
| 34 |
*/ |
| 35 |
public function set_path( $path ) { |
| 36 |
$this->path = $path; |
| 37 |
return $this; |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Get module directory path to file |
| 42 |
* |
| 43 |
* @param string $file File name. |
| 44 |
* @return string |
| 45 |
*/ |
| 46 |
public function get_path( string $file = '' ) { |
| 47 |
if ( ! $this->path ) { |
| 48 |
$this->path = trailingslashit( plugin_dir_path( __FILE__ ) ); |
| 49 |
} |
| 50 |
|
| 51 |
return $this->path . $file; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Set module directory URL |
| 56 |
* |
| 57 |
* @param string $url URL. |
| 58 |
* @return self |
| 59 |
*/ |
| 60 |
public function set_url( $url ) { |
| 61 |
$this->url = $url; |
| 62 |
return $this; |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Get module directory URL to file |
| 67 |
* |
| 68 |
* @param string $file File name. |
| 69 |
* @return string |
| 70 |
*/ |
| 71 |
public function get_url( string $file = '' ) { |
| 72 |
if ( ! $this->url ) { |
| 73 |
$this->url = trailingslashit( plugin_dir_url( __FILE__ ) ); |
| 74 |
} |
| 75 |
|
| 76 |
return $this->url . $file; |
| 77 |
} |
| 78 |
} |
| 79 |
|