Purpose

Set data for a template programmatically, allowing you to bypass reliance on database-stored data.

Usage

add_filter( "wr_template_object_set_data", array( $this, "my_template_object_set_data" ), 10, 3 );

Parameters

  • $data (array): The current data set for the template.
  • $options (array): Additional options passed to the template.
  • $selector (array): A selector that can be used to target specific parts of the template.

Use Case

This functionality is useful when:

  • The required data does not exist in the database and is sourced externally (e.g., from files or APIs).
  • You need to calculate or generate data dynamically using custom logic.

Implementation Example

add_filter( "wr_template_object_set_data", array( $this, "my_template_object_set_data" ), 10, 3 );
 
public function my_template_object_set_data( $data, $options = array(), $selector = array() ) {
	if ( !empty($options["identifier"] && $options["identifier"] === "my_template_object_identifier" ) ) {
		return array("placeholder" => 1)
	}
	return $data;
}