Last active
March 15, 2023 21:51
-
-
Save landbryo/ce0ab537fa936677d456c0f0cae67965 to your computer and use it in GitHub Desktop.
Get SCV file contents for use in a PHP template.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Setup class. | |
| */ | |
| class Setup { | |
| /** | |
| * Return only one instance of Setup. | |
| * | |
| * @return Setup | |
| */ | |
| public static function get_instance() { | |
| static $instance; | |
| if ( empty( $instance ) ) { | |
| $instance = new self(); | |
| } | |
| return $instance; | |
| } | |
| /** | |
| * Add Hooks and Actions | |
| */ | |
| protected function __construct() { | |
| } | |
| /** | |
| * Get plugin dir path (memoized). | |
| * | |
| * @return string | |
| */ | |
| public function get_plugin_path() { | |
| static $path; | |
| if ( empty( $path ) ) { | |
| $path = plugin_dir_path( __FILE__ ); | |
| } | |
| return $path; | |
| } | |
| /** | |
| * Get an SVG file's contents from the src/img directory by filename. | |
| * | |
| * @param string $filename The filename of the svg including the extension. | |
| * | |
| * @return string | |
| */ | |
| public function get_svg_contents( $filename ) { | |
| $icon_file_path = $this->get_plugin_path() . 'src/img/' . $filename; | |
| if ( file_exists( $icon_file_path ) ) { | |
| // phpcs:ignore WordPressVIPMinimum.Performance.FetchingRemoteData.FileGetContentsUnknown | |
| $contents = file_get_contents( $icon_file_path ); | |
| return $contents ? $contents : ''; | |
| } | |
| return ''; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment