Created
February 10, 2021 11:23
-
-
Save LGitHub-sprout/467fe0db38eafeacabc44ea9cb737a0c to your computer and use it in GitHub Desktop.
Replicating GeneratePress 'do_element_classes( )' function
This file contains 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
<?php | |
/** | |
* Display HTML classes for elements | |
* | |
* @since 0.1 | |
* | |
* @package wphierarchy | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; // Exit if accessed directly. | |
} | |
/** | |
* Display HTML classes for an element. | |
*/ | |
function wphierarchy_do_element_classes( $context, $class = '' ) { | |
$after = apply_filters( 'wphierarchy_after_element_class_attribute', '', $context ); | |
if ( $after ) { | |
$after = ' ' . $after; | |
} | |
echo 'class="' . join( ' ', wphierarchy_get_element_classes( $context, $class ) ) . '"' . $after; | |
} | |
function wphierarchy_get_element_classes( $context, $class = '' ) { | |
$classes = array(); | |
if ( ! empty( $class ) ) { | |
if ( ! is_array( $class ) ) { | |
$class = preg_split( '#\s+#', $class ); | |
} | |
$classes = array_merge( $classes, $class ); | |
} | |
$classes = array_map( 'esc_attr', $classes ); | |
return apply_filters( "wphierarchy_create_{$context}_class", $classes, $class ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment