Created
August 4, 2020 20:20
-
-
Save wpexplorer/9c5d15d9cf82fb7b7e165b3c1b8071c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns correct theme button classes based on args. | |
* | |
* @since 3.2.0 | |
*/ | |
function wpex_get_button_classes( $style = array(), $color = '', $size = '', $align = '' ) { | |
$args = $style; | |
if ( ! is_array( $args ) ) { | |
$args = array( | |
'style' => $style, | |
'color' => $color, | |
'size' => $size, | |
'align' => $align, | |
); | |
} | |
$defaults = apply_filters( 'wpex_button_default_args', array( | |
'style' => '', | |
'color' => '', | |
'size' => '', | |
'align' => '', | |
) ); | |
foreach ( $defaults as $key => $value ) { | |
if ( empty( $args[ $key ] ) ) { | |
$args[ $key ] = $defaults[ $key ]; | |
} | |
} | |
extract( $args ); | |
$classes = array(); | |
// Style | |
switch ( $style ) { | |
case 'plain-text': | |
$classes[] = 'theme-txt-link'; | |
break; | |
default: | |
if ( $style ) { | |
$classes[] = 'theme-button'; | |
$classes[] = sanitize_html_class( $style ); | |
} else { | |
$classes[] = 'theme-button'; | |
} | |
break; | |
} | |
// Color | |
if ( $color ) { | |
$classes[] = sanitize_html_class( $color ); | |
} | |
// Size | |
if ( $size ) { | |
$classes[] = sanitize_html_class( $size ); | |
} | |
// Align | |
if ( $align ) { | |
$classes[] = 'align-' . sanitize_html_class( $align ); | |
} | |
// Sanitize | |
$classes = array_map( 'esc_attr', $classes ); | |
// Convert class array to string | |
$class = implode( ' ', $classes ); | |
// Apply filters and return classes | |
return apply_filters( 'wpex_get_theme_button_classes', $class, $style, $color, $size, $align ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment