Comments (17)
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.
from wordpress-sparkpost.
Thanx a bunch!
from wordpress-sparkpost.
you can use the wpsp_template_id
hook to change template based on your logic.
from wordpress-sparkpost.
Thanx, found that but am too new to all this to get it to work. Hoping to have a working example to follow.
from wordpress-sparkpost.
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
from wordpress-sparkpost.
- you don't need to modify settings, the way you did in
$this->settings = SparkPost::get_settings();
- you can't create template here. you need to create template using SparkPost UI or using API. Once you created the template, all you need here is to specify it's ID.
Rest looks good, though I'm not sure about particular logics to detect blog id.
from wordpress-sparkpost.
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?
from wordpress-sparkpost.
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.
from wordpress-sparkpost.
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.
from wordpress-sparkpost.
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.
from wordpress-sparkpost.
Cool. Glad to know that helped.
from wordpress-sparkpost.
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?
from wordpress-sparkpost.
just return the new template id from the function.
from wordpress-sparkpost.
I updated the above example to make it clearer. Thanks
from wordpress-sparkpost.
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;
}
from wordpress-sparkpost.
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;
}
}
from wordpress-sparkpost.
Fabulous, you're the BEST!
from wordpress-sparkpost.
Related Issues (20)
- Support adding Campaign tag HOT 1
- Newly installed sparkpost plugin, getting SSL error: Failed to enable crypto HOT 3
- Show admin-wide alert if plugin is not ready to send!
- BuddyPress not sent with SparkPost HOT 3
- Why is Content-Type unsupported? HOT 9
- API Transmission Endpoint Changes HOT 2
- Retry transmissions after 5xx Error HOT 1
- Sparkpost replaces the url with a custom url HOT 3
- Emails could not be sent. htmlentities() expects parameter 1 to be string, array given in xxx HOT 8
- Missing assets folder in plugin installation HOT 6
- Retry transmissions after cURL error
- QUIT
- Sparkpost for only one contact form?
- reply-to not working
- Disable SparkPost mailer using a PHP constant
- Plugin uses incorrect bounce domain HOT 1
- Wondering if this plugin is still being maintained? HOT 1
- Deprecated notice on WP 5.5 HOT 2
- Fatal error: Uncaught Error in PHPMailer HOT 2
- official 3.2.8 tagged release
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wordpress-sparkpost.