| 1 |
<?php |
| 2 |
/** |
| 3 |
* Extension Icon class |
| 4 |
* |
| 5 |
* @package Timetics |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Timetics\Core\Addon; |
| 9 |
|
| 10 |
defined( 'ABSPATH' ) || exit; |
| 11 |
|
| 12 |
/** |
| 13 |
* Class Extension_Icon |
| 14 |
* |
| 15 |
* Loads SVG/PNG icons for Arraytics plugins from assets/images/addons/. |
| 16 |
*/ |
| 17 |
class Extension_Icon { |
| 18 |
|
| 19 |
/** |
| 20 |
* Get the icon for a given plugin by name. |
| 21 |
* |
| 22 |
* Returns raw SVG markup for .svg files, or a URL string for image files. |
| 23 |
* |
| 24 |
* @param string $name Plugin/extension slug (e.g. 'eventin'). |
| 25 |
* @return string SVG markup or image URL, empty string if not found. |
| 26 |
*/ |
| 27 |
public static function get( string $name ): string { |
| 28 |
return self::load( $name ); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Load icon file from assets/images/addons/. |
| 33 |
* |
| 34 |
* @param string $file_name File name without extension. |
| 35 |
* @return string |
| 36 |
*/ |
| 37 |
private static function load( string $file_name ): string { |
| 38 |
$extensions = [ 'svg', 'png', 'webp', 'jpg' ]; |
| 39 |
$base_path = TIMETICS_PLUGIN_DIR . 'assets/images/addons/'; |
| 40 |
$base_url = TIMETICS_ASSETS_URL . 'images/addons/'; |
| 41 |
|
| 42 |
foreach ( $extensions as $ext ) { |
| 43 |
$file = $base_path . $file_name . '.' . $ext; |
| 44 |
if ( file_exists( $file ) ) { |
| 45 |
return 'svg' === $ext |
| 46 |
? file_get_contents( $file ) // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents |
| 47 |
: $base_url . $file_name . '.' . $ext; |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
return ''; |
| 52 |
} |
| 53 |
} |
| 54 |
|