I'm developing a WordPress theme and trying to escaping group of attribute at once that store with a variable.
<?php
$attributes = array();
$classes = array(
'header-section'
);
if ( true == $noticebar ) {
$classes[] = 'topnotice-exist';
}
if ( true == $option['switch-top-bar'] ) {
$classes[] = 'topbar-exist';
}
if ( true == $option['switch-menu-sticky'] ) {
if ( '2' == $option['fixed-menu-style'] ) {
$classes[] = 'fixed-after-pixel';
} elseif ('3' == $option['fixed-menu-style']) {
$classes[] = 'only-after-scroll-up';
} else {
$classes[] = 'only-after-scroll';
}
}
$classes = implode( ' ', $classes );
if ( $classes ) {
$attributes[] = 'class="' . trim( $classes ) . '"';
}
if ( $option['transition'] ) {
$attributes[] = 'data-transition="' . esc_attr( $option['transition'] ) . '"';
}
$attributes[] = 'id="header"';
$attributes = implode( ' ', $attributes );
?>
<div <?php echo $attributes; ?>> <!-- here is my question -->
<!-- html/php -->
</div>
So my question is how may I escape $attribute
here, I can't use esc_attr()
nor esc_html()
. currently I'm using wp_kses_post()
for escaping this $attribute
variable but I'm not sure that is it good idea or not.
I have good idea about sprintf()
and printf()
so don't bring them here, I just need know, How can I echo $attribute
with proper way according to WordPress escaping roles?
echo $attributes
variable here and maintain WordPress standard escaping rules. Or if I directly echo $attributes variable here is it good for codex theme or like themeforest?