From 9d4123cee1867ee7199b06bdc92d40611f547ecc Mon Sep 17 00:00:00 2001 From: Zach van Rijn Date: Wed, 21 Jul 2021 14:54:07 -0500 Subject: Initial unmodified import from Astra (Version: 3.6.5) @ /wp-content/themes/astra/. --- inc/core/class-astra-attr.php | 115 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 inc/core/class-astra-attr.php (limited to 'inc/core/class-astra-attr.php') diff --git a/inc/core/class-astra-attr.php b/inc/core/class-astra-attr.php new file mode 100644 index 0000000..2f55e46 --- /dev/null +++ b/inc/core/class-astra-attr.php @@ -0,0 +1,115 @@ +astra_parse_attr( $context, $attributes, $args ); + + $output = ''; + + // Cycle through attributes, build tag attribute string. + foreach ( $attributes as $key => $value ) { + + if ( ! $value ) { + continue; + } + + if ( true === $value ) { + $output .= esc_html( $key ) . ' '; + } else { + $output .= sprintf( '%s="%s" ', esc_html( $key ), esc_attr( $value ) ); + } + } + + $output = apply_filters( "astra_attr_{$context}_output", $output, $attributes, $context, $args ); + + return trim( $output ); + } + + /** + * Merge array of attributes with defaults, and apply contextual filter on array. + * + * The contextual filter is of the form `astra_attr_{context}`. + * + * @since 1.6.2 + * + * @param string $context The context, to build filter name. + * @param array $attributes Optional. Extra attributes to merge with defaults. + * @param array $args Optional. Custom data to pass to filter. + * @return array Merged and filtered attributes. + */ + public function astra_parse_attr( $context, $attributes = array(), $args = array() ) { + + $defaults = array( + 'class' => sanitize_html_class( $context ), + ); + + $attributes = wp_parse_args( $attributes, $defaults ); + + // Contextual filter. + return apply_filters( "astra_attr_{$context}", $attributes, $context, $args ); + } + + } + +endif; + +/** + * Kicking this off by calling 'get_instance()' method + */ +Astra_Attr::get_instance(); -- cgit v1.2.3-70-g09d2