wpseek.com
A WordPress-centric search engine for devs and theme authors
wp_get_tooltip_helper › WordPress Function
Since7.1.0
Deprecatedn/a
› wp_get_tooltip_helper ( $content, $args = array() )
| Parameters: (2) |
|
| Returns: |
|
| Defined at: |
|
| Codex: |
Retrieves the markup for an accessible tooltip or toggletip.
Returns a button and either a hover/focus triggered tooltip popover or an action triggered toggle tip. Enqueue thewp-tooltip style and script where it is used.
Tooltips are used to show the accessible name of a control.
Toggletips are be used for longer supporting text explaining context.Related Functions: wp_get_tooltip, wp_get_http_headers, wp_get_toggletip, wp_get_theme, wp_get_themes
Source
function wp_get_tooltip_helper( $content, $args = array() ) {
$content = trim( (string) $content );
if ( '' === $content ) {
return '';
}
$defaults = array(
'id' => '',
'label' => __( 'Help' ),
'close_label' => __( 'Close' ),
'icon' => 'dashicons-editor-help',
'class' => '',
'type' => 'tooltip',
'attributes' => array(),
);
$args = wp_parse_args( $args, $defaults );
$id = '' !== $args['id'] ? $args['id'] : wp_unique_id( 'wp-tooltip-' );
$classes = ( 'tooltip' === $args['type'] ) ? 'wp-tooltip wp-is-tooltip' : 'wp-tooltip wp-is-toggletip';
if ( '' !== $args['class'] ) {
$classes .= ' ' . $args['class'];
}
$icon = '' !== $args['icon'] ? ' ' . $args['icon'] : '';
if ( 'tooltip' === $args['type'] ) {
// Tooltips are only used to visually display labels.
$label = wp_strip_all_tags( $content, true );
$markup = sprintf(
'<div class="%1$s">' .
'<button type="button" class="wp-tooltip__toggle" popovertarget="%2$s" aria-label="%3$s">' .
'<span class="dashicons%4$s" aria-hidden="true"></span>' .
'</button>' .
'<span popover="hint" id="%2$s" class="wp-tooltip__bubble" role="tooltip">' .
'<span id="%2$s-text" class="wp-tooltip__text">%5$s</span>' .
'</span>' .
'</div>',
esc_attr( $classes ),
esc_attr( $id ),
esc_attr( $label ),
esc_attr( $icon ),
esc_html( $content ),
);
} else {
$markup = sprintf(
'<div class="%1$s">' .
'<button type="button" class="wp-tooltip__toggle" popovertarget="%2$s" aria-label="%3$s" aria-haspopup="dialog">' .
'<span class="dashicons%4$s" aria-hidden="true"></span>' .
'</button>' .
'<dialog popover="auto" id="%2$s" class="wp-tooltip__bubble" autofocus>' .
'<span id="%2$s-text" class="wp-tooltip__text">%5$s</span>' .
'<button type="button" class="wp-tooltip__close" popovertarget="%2$s" popovertargetaction="hide" aria-label="%6$s">' .
'<span class="dashicons dashicons-no-alt" aria-hidden="true"></span>' .
'</button>' .
'</dialog>' .
'</div>',
esc_attr( $classes ),
esc_attr( $id ),
esc_attr( $args['label'] ),
esc_attr( $icon ),
esc_html( $content ),
esc_attr( $args['close_label'] ),
);
}
return $markup;
}