Skip to content

Instantly share code, notes, and snippets.

@landbryo
Last active March 15, 2023 21:51
Show Gist options
  • Select an option

  • Save landbryo/ce0ab537fa936677d456c0f0cae67965 to your computer and use it in GitHub Desktop.

Select an option

Save landbryo/ce0ab537fa936677d456c0f0cae67965 to your computer and use it in GitHub Desktop.
Get SCV file contents for use in a PHP template.
<?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