Template_Tag_Handler::process_content( string $content, array $args )

Processes content and replaces template tags.

Description

Parameters

$content

(string) (Required) Input content.

$args

(array) (Required) Arguments to pass to the template tag callbacks. Must validate against the handler's arguments definition.

Return

(string) Content with template tags replaced.

Source

File: src/components/template-tag-handler.php

	public function process_content( $content, $args ) {
		if ( false === strpos( $content, '{' ) ) {
			return $content;
		}

		try {
			$args = $this->validate_tag_args( $args, $this->args_definition );
		} catch ( InvalidArgumentException $e ) {
			return $content;
		}

		$placeholders = array();
		$replacements = array();

		foreach ( $this->tags as $slug => $data ) {
			$placeholders[] = '{' . $slug . '}';
			$replacements[] = (string) call_user_func_array( $data['callback'], $args );
		}

		return str_replace( $placeholders, $replacements, $content );
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.