Git Product home page Git Product logo

Comments (17)

interceptclients avatar interceptclients commented on July 1, 2024 1

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.

interceptclients avatar interceptclients commented on July 1, 2024 1

Thanx a bunch!

from wordpress-sparkpost.

rajumsys avatar rajumsys commented on July 1, 2024

you can use the wpsp_template_id hook to change template based on your logic.

from wordpress-sparkpost.

interceptclients avatar interceptclients commented on July 1, 2024

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.

interceptclients avatar interceptclients commented on July 1, 2024

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.

rajumsys avatar rajumsys commented on July 1, 2024

@interceptclients

  • 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.

interceptclients avatar interceptclients commented on July 1, 2024

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.

rajumsys avatar rajumsys commented on July 1, 2024

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.

interceptclients avatar interceptclients commented on July 1, 2024

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.

rajumsys avatar rajumsys commented on July 1, 2024

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.

rajumsys avatar rajumsys commented on July 1, 2024

Cool. Glad to know that helped.

from wordpress-sparkpost.

interceptclients avatar interceptclients commented on July 1, 2024

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.

rajumsys avatar rajumsys commented on July 1, 2024

just return the new template id from the function.

from wordpress-sparkpost.

rajumsys avatar rajumsys commented on July 1, 2024

I updated the above example to make it clearer. Thanks

from wordpress-sparkpost.

interceptclients avatar interceptclients commented on July 1, 2024

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.

rajumsys avatar rajumsys commented on July 1, 2024

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.

interceptclients avatar interceptclients commented on July 1, 2024

Fabulous, you're the BEST!

from wordpress-sparkpost.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.