Closed interceptclients closed 8 years ago
you can use the wpsp_template_id
hook to change template based on your logic.
Thanx, found that but am too new to all this to get it to work. Hoping to have a working example to follow.
Will this work?
/* Set SparkPost Template */
function sp_assign_template($body) {
$blog_id = get_current_blog_id();
$this->settings = SparkPost::get_settings();
$template_id = $this->settings['template'];
if ( ( is_multisite() ) && ( $blog_id <> '1' ) ) {
$new_template_id = $template_id . '-' . $blog_id;
$body['content']['template_id'] = $new_template_id;
} else {
$body['content']['template_id'] = $template_id;
}
return $body;
}
add_filter('wpsp_template_id', 'sp_assign_template');
If so, how can I confirm the new template was actually created in SparkPost?
...... Rick
@interceptclients
$this->settings = SparkPost::get_settings();
Rest looks good, though I'm not sure about particular logics to detect blog id.
Trying to get the settings not modify them. How do I get the stored template value?
I don't want to create templates I want to validate they exist. How's that done?
wpsp_template_id
hook provides you that.
function sp_assign_template($storedTemplateId) {
// $storedTemplateId contains the template ID that's stored in settings
return 'NEW_TEMPLATE_ID';
}
add_filter('wpsp_template_id', 'sp_assign_template');
And if you want to validate, if the template really exists in SparkPost, you have to use the API I've linked above. Remember, your API key must have permission to read templates for that.
Thank you. How can I validate a template exists before trying to use it? If the new template was not created it should assign the stored template id.
How can I validate a template exists before trying to use it?
And if you want to validate, if the template really exists in SparkPost, you have to use the API I've linked above. Remember, your API key must have permission to read templates for that.
Missed that, thank you. Well over my head to create, need a php example to modify. Appreciate your prompt and thorough replies. Maybe I can find someone on fiverr willing to do it for me.
Cool. Glad to know that helped.
Seems I missed something previously. How is the modified $body with the new template id returned if the stored template id is passed in the function call?
just return the new template id from the function.
Thanx a bunch!
I updated the above example to make it clearer. Thanks
Like this,
/* Set SparkPost Template */
function sp_assign_template($storedTemplateId) {
$blog_id = get_current_blog_id();
if ( ( is_multisite() ) && ( $blog_id <> '1' ) ) {
$newTemplateId = $storedTemplateId . '-' . $blog_id;
}
return $newTemplateId;
}
Right. But your code now has logical error.
function sp_assign_template($storedTemplateId) {
$blog_id = get_current_blog_id();
if ( ( is_multisite() ) && ( $blog_id <> '1' ) ) {
return $storedTemplateId . '-' . $blog_id;
} else {
return $storedTemplateId;
}
}
Fabulous, you're the BEST!
Does anyone have any code samples for switching templates based on which blog in a multi-site implementation is sending transactional emails?
Thanx in advance for your thoughts ....... Rick