WP_HTML_Processor::set_attribute()publicWP 6.6.0

Updates or creates a new attribute on the currently matched tag with the passed value.

For boolean attributes special handling is provided:

  • When true is passed as the value, then only the attribute name is added to the tag.
  • When false is passed, the attribute gets removed if it existed before.

For string attributes, the value is escaped using the esc_attr function.

Метод класса: WP_HTML_Processor{}

Хуков нет.

Возвращает

true|false. Whether an attribute value was set.

Использование

$WP_HTML_Processor = new WP_HTML_Processor();
$WP_HTML_Processor->set_attribute( $name, $value ): bool;
$name(строка) (обязательный)
The attribute name to target.
$value(строка|true|false) (обязательный)
The new attribute value.

Список изменений

С версии 6.6.0 Введена.
С версии 6.6.0 Subclassed for the HTML Processor.

Код WP_HTML_Processor::set_attribute() WP 6.8.1

public function set_attribute( $name, $value ): bool {
	return $this->is_virtual() ? false : parent::set_attribute( $name, $value );
}