Skip to content

MainWP — Template Variables

When you create a contract from MainWP, the addon builds a variable map from the selected Client and Site, then applies it through WPSigner’s form/template prefill helper (FormFeedFieldPrefill::apply_variables).

Empty values are stripped before apply. History meta records whether prefill matched (variables prefilled / no prefill match).


  1. Name template fields (or mapping names) using the keys below — same idea as form feeds / Zapier mapping in WPSigner.
  2. Create from MainWP with a Client and/or Site selected.
  3. Matching keys receive values automatically on the new document.

If only a Site is selected and that Site has a linked MainWP client_id, the addon infers the Client for variable building.


KeySource
client_nameMainWP client name
client_emailMainWP client email
site_nameSite name
website_nameAlias of site_name
site_urlSite URL
website_urlAlias of site_url
property_addressCurrently filled with the site URL (convenient alias for address-style fields)
dateToday as Y-m-d (site timezone via wp_date)
todaySame as date
appointment_dateSame as date
current_dateHuman-readable date using WordPress date_format
mainwp_client_idClient ID as string (empty if none)
mainwp_site_idSite ID as string (empty if none)

Extend or override the map:

/**
* @param array<string,string> $vars
* @param int $client_id
* @param int $site_id
*/
add_filter('imwp_template_variables', function ($vars, $client_id, $site_id) {
// Example: add a custom CRM ID stored on the client.
if ($client_id) {
$vars['crm_id'] = (string) get_option('my_crm_id_' . $client_id, '');
}
return $vars;
}, 10, 3);

Return only string values. Empty strings are removed before apply.


SymptomFix
History says no prefill matchField mapping names do not match keys; or Client/Site had no usable values
Client fields emptySelect a Client, or ensure the Site has a linked client
Site URL missingSelect a Site with a valid URL in MainWP
Custom key ignoredAdd it via imwp_template_variables and map the template field to that name

More help: Troubleshooting.