Retrieves the content of a registered icon.
Parameters
$icon_namestringrequired- Icon name including namespace.
Source
protected function get_content( $icon_name ) {
if ( ! isset( $this->registered_icons[ $icon_name ]['content'] ) ) {
$file_path = $this->registered_icons[ $icon_name ]['file_path'] ?? '';
$is_stringy = is_string( $file_path ) || ( is_object( $file_path ) && method_exists( $file_path, '__toString' ) );
$icon_path = $is_stringy ? realpath( (string) $file_path ) : false;
if (
! is_string( $icon_path ) ||
! str_ends_with( $icon_path, '.svg' ) ||
! is_file( $icon_path ) ||
! is_readable( $icon_path )
) {
wp_trigger_error(
__METHOD__,
__( 'Icon file is missing or unreadable.' )
);
return null;
}
$content = $this->sanitize_icon_content( file_get_contents( $icon_path ) );
if ( empty( $content ) ) {
wp_trigger_error(
__METHOD__,
__( 'Icon content does not contain valid SVG markup.' )
);
return null;
}
$this->registered_icons[ $icon_name ]['content'] = $content;
}
return $this->registered_icons[ $icon_name ]['content'];
}
Changelog
| Version | Description |
|---|---|
| 7.0.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.