Home Forums Plugins 9MAIL – WordPress Email Templates Designer Support of 3rd type / custom email tempaltes

Support of 3rd type / custom email tempaltes

  • Author
    Posts
  • #161205

    Ido Kobelkowsky
    Participant

    I went ahead and modified a few lines in your plugin so it can support integration with other email, ( since your plugin is great, but misses just a bit to be awsome! )

    my request if you find it proper and useful integrate it into your base code, so future versions will include it (since there are no other hooks that I can use to obtain this currently )

    so, the intention is to use wp_mail, and add template: header for the plugin to use the header

    
    
    add_filter( 'emtmpl_user_emails', function( $emails ) {
    	$emails[ 'my_custom_template' ] = esc_html__( 'This is my custom template', 'domain' );
    	return( $emails );
    } );
    
    wp_mail( 'johndoe@domain.com','{site_title} This is our email subject with shortcodes', 'Content here but it doesnt matter since we use the template', [ 'template: my_custom_template' ] );
    

    for that i had modified a few lines in your email-trigger.php file in the use_default_email function

    this is the adjusted function code ( around lines 515 ), marked the new code in START: END

    
    public function use_default_email( $args ) {
    		$use_default_tmpl = false;
    
    		if ( ! $this->rendered ) {
    			if ( $this->check_ignore( $args['message'] ) ) {
    				$args['message'] = str_replace( $this->ignore_key, '', $args['message'] );
    
    				return $args;
    			}
    			
    			// START: Adding Support for dynamic template choosing from wp_mail via headers
    			$headers = is_array( $args[ 'headers' ] ) ? $args[ 'headers' ] : explode( "\n", str_replace( "\r\n", "\n", $args[ 'headers' ] ) );
    			foreach( $headers as $header ) {
    				list( $name, $content ) = explode( ':', trim( $header ), 2 );
    				if ( strtolower( trim( $name ) ) == 'template' ) {
    					$template = strtolower( trim( $content ) );
    					break;
    				}
    			}
    			
    			$template = $this->find_template( isset( $template ) && $template ? $template : 'default' );
    			// $template = $this->find_template( 'default' );
    			// END
    			
    			if ( ! empty( $template ) ) {
    				$message = $this->render_email_html( $template->ID, $args['message'] );
    
    				if ( $message ) {
    					$this->rendered   = true;
    					$use_default_tmpl = true;
    					$args['message']  = $message;
    				}
    			}
    		}
    
    		if ( $this->rendered ) {
    			// START: wrapped shortcodes with filter in order to provide support for additional shortcodes
    			$re              = apply_filters( 'emtmpl_common_shortcodes', Utils::common_shortcodes() );
    			// END
    			$args['message'] = str_replace( array_keys( $re ), array_values( $re ), $args['message'] );
    			$args['message'] = Utils::minify_html( $args['message'] );
    			
    			// START: Changed to support replacing of shortcodes inside subject, since we already are adding support for filters on shortcodes
    			//if ( ! $use_default_tmpl ) { // Disabled if so it can support changing of shortcodes always
    				$args['subject'] = str_replace( array_keys( $re ), array_values( $re ), $this->email_subject );
    			//}
    			// END
    			
    			add_filter( 'wp_mail_content_type', [ $this, 'replace_content_type' ] );
    		}
    
    		$this->rendered = false; //Reset
    
    		return $args;
    	}
    

You must be logged in to see replies to this topic. Click here to login or register