RWMB_Field::render_attributes PHP Method

render_attributes() public static method

Renders an attribute array into an html attributes string
public static render_attributes ( array $attributes ) : string
$attributes array
return string
	public static function render_attributes( $attributes ) {
		$output = '';

		foreach ( $attributes as $key => $value ) {
			if ( false === $value || '' === $value ) {
				continue;
			}

			if ( is_array( $value ) ) {
				$value = json_encode( $value );
			}

			$output .= sprintf( true === $value ? ' %s' : ' %s="%s"', $key, esc_attr( $value ) );
		}

		return $output;
	}

Usage Example

Exemplo n.º 1
0
 /**
  * @see Walker::start_el()
  *
  * @param string $output            Passed by reference. Used to append additional content.
  * @param object $object            Item data object.
  * @param int    $depth             Depth of item.
  * @param int    $current_object_id Item ID.
  * @param array  $args
  */
 public function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0)
 {
     $label = $this->db_fields['label'];
     $id = $this->db_fields['id'];
     $attributes = RWMB_Field::call('get_attributes', $this->field, $object->{$id});
     $output .= sprintf('<li><label><input %s %s>%s</label>', RWMB_Field::render_attributes($attributes), checked(in_array($object->{$id}, $this->meta), 1, false), $object->{$label});
 }
All Usage Examples Of RWMB_Field::render_attributes