PluginProbe
Bogo / 3.9.3
Bogo v3.9.3
3.9.3 trunk 1.0 1.1 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5 2.6 2.6.1 2.7 2.8 2.8.1 2.9 3.0 3.0.1 All 52 releases
bogo / includes / formatting.php

formatting.php in Bogo 3.9.3, at includes/formatting.php

48 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Returns a formatted string of HTML attributes.
5 *
6 * @param array $atts Associative array of attribute name and value pairs.
7 * @return string Formatted HTML attributes.
8 */
9 function bogo_format_atts( $atts ) {
10 $atts_filtered = array();
11
12 foreach ( $atts as $name => $value ) {
13 $name = strtolower( trim( $name ) );
14
15 if ( ! preg_match( '/^[a-z_:][a-z_:.0-9-]*$/', $name ) ) {
16 continue;
17 }
18
19 static $boolean_attributes = array(
20 'checked', 'disabled', 'multiple', 'readonly', 'required', 'selected',
21 );
22
23 if ( in_array( $name, $boolean_attributes ) and '' === $value ) {
24 $value = false;
25 }
26
27 if ( is_numeric( $value ) ) {
28 $value = (string) $value;
29 }
30
31 if ( null === $value or false === $value ) {
32 unset( $atts_filtered[$name] );
33 } elseif ( true === $value ) {
34 $atts_filtered[$name] = $name; // boolean attribute
35 } elseif ( is_string( $value ) ) {
36 $atts_filtered[$name] = trim( $value );
37 }
38 }
39
40 $output = '';
41
42 foreach ( $atts_filtered as $name => $value ) {
43 $output .= sprintf( ' %1$s="%2$s"', $name, esc_attr( $value ) );
44 }
45
46 return trim( $output );
47 }
48