Purpose

Modify the selector before a template is created, allowing you to adjust or set additional properties (e.g., an entry ID) programmatically.

Usage

add_filter( "wr_template_modify_TemplateRequest_selector", array( $this, "set_entry_for_prefilling_stuff" ), 10, 2 );

Parameters

  • $selector (array): The current selector array used to create the template.
  • $request_payload (array): The request payload associated with the template request.

Use Case

This functionality is useful when:

  • You need to add or modify properties in the selector dynamically (e.g., setting an entry ID based on conditions).
  • Custom logic is required to prefill or customize the template creation process.

Implementation Example

The following example adds an entry ID (42) to the selector for a specific template:

add_filter( "wr_template_modify_TemplateRequest_selector", array( $this, "set_entry_for_prefilling_stuff" ), 10, 2 );
 
public function set_entry_for_prefilling_stuff( $selector, $request_payload  ) {
	if ( isset( $selector['template'] ) && $selector['template'] === "my_wanted_template" ) {
		$selector["id"] = 42;
	}
	return $selector;
}