WordPress.org

Ready to get started?Download WordPress

Forums

WP SendGrid
[resolved] Request: Add filter for manipulating arguments (4 posts)

  1. jacobcoens
    Member
    Posted 1 year ago #

    Hi,

    I would like to have the possibility to manipulate the arguments for send an e-mail. For this, in includes/wp-mail.php you could add the following just before sending the email (line #209 in plugin version 1.0.1):

    $args = apply_filters( 'wp_sendgrid_args', $args );

    This would enable me to disable the subscription tracking for a specific website that uses our company-wide SendGrid account by using the code below:

    /**
     * Disables SendGrid subscription tracking
     */
    function filter_wp_sendgrid_args( $args ) {
    	$headers = array();
    	$headers['filters']['subscriptiontrack']['settings']['enable'] = 0;
    	$args['x-smtpapi'] = json_encode($headers, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
    
    	return $args;
    }
    
    /**
     * Disable SendGrid subscription tracking
     */
    add_filter( 'wp_sendgrid_args', 'filter_wp_sendgrid_args' );

    http://wordpress.org/extend/plugins/wp-sendgrid/

  2. Will Anderson
    Member
    Plugin Author

    Posted 1 year ago #

    I actually just now saw this request, but as luck would have it, I just released a new version of the plugin that adds that filter. I had a similar request over on GitHub, which prompted me to add the filter.

    When you get a chance, check that you can do what you're wanting with version 2.0 and let me know if it works. If so, I'll resolve this thread.

  3. Will Anderson
    Member
    Plugin Author

    Posted 1 year ago #

    Actually, I forgot to mention. You can also use the 'wp_sendgrid_xsmtpapi' filter to get at the X-SMTPAPI array directly. Then just do something like the following:

    /**
     * Disables SendGrid subscription tracking
     */
    function filter_xsmtpapi( $xsmtpapi ) {
    	$xsmtpapi['filters']['subscriptiontrack']['settings']['enable'] = 0;
    	return $xsmtpapi;
    }
    
    /**
     * Disable SendGrid subscription tracking
     */
    add_filter( 'wp_sendgrid_xsmtpapi', 'filter_xsmtpapi' );

    Even easier :)

  4. Will Anderson
    Member
    Plugin Author

    Posted 1 year ago #

    Closing this thread. Feel free to reopen if this solution doesn't solve your problem.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.