or tag.
*/
function su_html_icon( $args ) {
if ( is_string( $args ) ) {
$args = array( 'icon' => $args );
}
$args = wp_parse_args(
$args,
array(
'icon' => '',
'size' => '',
'color' => '',
'style' => '',
'alt' => '',
'enqueue-fa' => false,
)
);
if ( ! $args['icon'] ) {
return '';
}
if ( $args['style'] ) {
$args['style'] = rtrim( $args['style'], ';' ) . ';';
}
$args['size'] = intval( $args['size'] );
// Font Awesome icon
if ( strpos( $args['icon'], 'icon:' ) !== false ) {
if ( $args['size'] ) {
$args['style'] .= 'font-size:' . $args['size'] . 'px;';
}
if ( $args['color'] ) {
$args['style'] .= 'color:' . $args['color'] . ';';
}
if ( $args['enqueue-fa'] ) {
su_query_asset( 'css', 'su-icons' );
}
return '';
}
// Image icon
if ( strpos( $args['icon'], '/' ) !== false ) {
if ( $args['size'] ) {
$args['style'] .= 'width:' . $args['size'] . 'px;height:' . $args['size'] . 'px;';
}
return '
';
}
return false;
}
/**
* Create HTML dropdown.
*
* @since 5.0.5
* @param array $args Args.
* @return string Dropdown markup.
*/
function su_html_dropdown( $args ) {
$args = wp_parse_args(
$args,
array(
'id' => '',
'name' => '',
'class' => '',
'multiple' => '',
'size' => '',
'disabled' => '',
'selected' => '',
'none' => '',
'options' => array(),
'style' => '',
'noselect' => '',
)
);
$options = array();
if ( ! is_array( $args['options'] ) ) {
$args['options'] = array();
}
if ( $args['id'] ) {
$args['id'] = ' id="' . $args['id'] . '"';
}
if ( $args['name'] ) {
$args['name'] = ' name="' . $args['name'] . '"';
}
if ( $args['class'] ) {
$args['class'] = ' class="' . $args['class'] . '"';
}
if ( $args['style'] ) {
$args['style'] = ' style="' . esc_attr( $args['style'] ) . '"';
}
if ( $args['multiple'] ) {
$args['multiple'] = ' multiple="multiple"';
}
if ( $args['disabled'] ) {
$args['disabled'] = ' disabled="disabled"';
}
if ( $args['size'] ) {
$args['size'] = ' size="' . $args['size'] . '"';
}
if ( $args['none'] ) {
$args['options'][0] = $args['none'];
}
foreach ( $args['options'] as $id => $text ) {
$options[] = '';
}
$options = implode( '', $options );
$options = str_replace(
'value="' . $args['selected'] . '"',
'value="' . $args['selected'] . '" selected="selected"',
$options
);
return $args['noselect']
? $options :
'';
}
/**
* Create a HTML table from a CSV string.
*
* @since 5.3.0
* @param string $csv CSV input.
* @param string $delimiter Column delimiter.
* @return string HTML output.
*/
function su_csv_to_html( $csv, $delimiter = ',', $header = false ) {
if ( ! is_string( $csv ) ) {
return '';
}
if ( ! function_exists( 'str_getcsv' ) ) {
return $csv;
}
$html = '';
$rows = explode( PHP_EOL, $csv );
foreach ( $rows as $row ) {
$html .= '