wpseek.com
A WordPress-centric search engine for devs and theme authors
wp_get_icon › WordPress Function
Since7.1.0
Deprecatedn/a
› wp_get_icon ( $name, $args = array() )
| Parameters: (2) |
|
| Returns: |
|
| Defined at: |
|
| Codex: |
Returns the SVG markup for a registered icon.
Related Functions: wp_get_links, wp_site_icon, wp_get_connector, wp_register_icon, wp_get_connectors
Source
function wp_get_icon( $name, $args = array() ) {
$icon = WP_Icons_Registry::get_instance()->get_registered_icon( $name );
if ( is_null( $icon ) ) {
return '';
}
$svg = $icon['content'];
if ( empty( $svg ) ) {
return '';
}
$args = wp_parse_args(
$args,
array(
'size' => 24,
'class' => '',
'label' => '',
)
);
$processor = new WP_HTML_Tag_Processor( $svg );
if ( ! $processor->next_tag( 'svg' ) ) {
return '';
}
if ( is_numeric( $args['size'] ) ) {
$size = absint( $args['size'] );
$processor->set_attribute( 'width', (string) $size );
$processor->set_attribute( 'height', (string) $size );
}
if ( ! empty( $args['class'] ) ) {
foreach ( preg_split( '/\s+/', $args['class'], -1, PREG_SPLIT_NO_EMPTY ) as $class_name ) {
$processor->add_class( $class_name );
}
}
if ( ! empty( $args['label'] ) ) {
$processor->set_attribute( 'role', 'img' );
$processor->set_attribute( 'aria-label', $args['label'] );
$processor->remove_attribute( 'aria-hidden' );
$processor->remove_attribute( 'focusable' );
} else {
$processor->set_attribute( 'aria-hidden', 'true' );
$processor->set_attribute( 'focusable', 'false' );
$processor->remove_attribute( 'role' );
$processor->remove_attribute( 'aria-label' );
}
return $processor->get_updated_html();
}