WP_HTML_Tag_Processor::set_attribute( string $name, string|bool $value ): bool

In this article

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

Description

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.

Parameters

$namestringrequired
The attribute name to target.
$valuestring|boolrequired
The new attribute value.

Return

bool Whether an attribute value was set.

Source

				return 'feFuncB';

			case 'fefuncg':
				return 'feFuncG';

			case 'fefuncr':
				return 'feFuncR';

			case 'fegaussianblur':
				return 'feGaussianBlur';

			case 'feimage':
				return 'feImage';

			case 'femerge':
				return 'feMerge';

			case 'femergenode':
				return 'feMergeNode';

			case 'femorphology':
				return 'feMorphology';

			case 'feoffset':
				return 'feOffset';

			case 'fepointlight':
				return 'fePointLight';

			case 'fespecularlighting':
				return 'feSpecularLighting';

			case 'fespotlight':
				return 'feSpotLight';

			case 'fetile':
				return 'feTile';

			case 'feturbulence':
				return 'feTurbulence';

			case 'foreignobject':
				return 'foreignObject';

			case 'glyphref':
				return 'glyphRef';

			case 'lineargradient':
				return 'linearGradient';

			case 'radialgradient':
				return 'radialGradient';

			case 'textpath':
				return 'textPath';

			default:
				return $lower_tag_name;
		}
	}

	// This unnecessary return prevents tools from inaccurately reporting type errors.
	return $tag_name;
}

/**
 * Returns the adjusted attribute name for a given attribute, taking into
 * account the current parsing context, whether HTML, SVG, or MathML.
 *
 * @since 6.7.0
 *
 * @param string $attribute_name Which attribute to adjust.
 *
 * @return string|null
 */
public function get_qualified_attribute_name( $attribute_name ): ?string {
	if ( self::STATE_MATCHED_TAG !== $this->parser_state ) {
		return null;
	}

	$namespace  = $this->get_namespace();
	$lower_name = strtolower( $attribute_name );

	if ( 'math' === $namespace && 'definitionurl' === $lower_name ) {
		return 'definitionURL';
	}

	if ( 'svg' === $this->get_namespace() ) {
		switch ( $lower_name ) {
			case 'attributename':
				return 'attributeName';

			case 'attributetype':
				return 'attributeType';

			case 'basefrequency':
				return 'baseFrequency';

			case 'baseprofile':
				return 'baseProfile';

			case 'calcmode':
				return 'calcMode';

			case 'clippathunits':
				return 'clipPathUnits';

			case 'diffuseconstant':
				return 'diffuseConstant';

			case 'edgemode':
				return 'edgeMode';

			case 'filterunits':
				return 'filterUnits';

			case 'glyphref':
				return 'glyphRef';

			case 'gradienttransform':
				return 'gradientTransform';

			case 'gradientunits':
				return 'gradientUnits';

			case 'kernelmatrix':
				return 'kernelMatrix';

			case 'kernelunitlength':
				return 'kernelUnitLength';

			case 'keypoints':
				return 'keyPoints';

			case 'keysplines':
				return 'keySplines';

			case 'keytimes':
				return 'keyTimes';

Changelog

VersionDescription
6.2.1Fix: Only create a single update for multiple calls with case-variant attribute names.
6.2.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.