Integrate New Mailer In Connects

ConvertPlus allows you to integrate your own addon for different mailers. Apart from the mailer addons integrated by ConvertPlus, a new mailer could be integrated as stated below.

For your addon to work you need to create a wordpress plugin with defining your class in it – Lets say addon name is MyAddon, the class name would be as shown below –

if(!class_exists('Smile_Mailer_Myaddon')){
	class Smile_Mailer_Myaddon{
		private $slug;
		private $setting;
	}
	new Smile_Mailer_Myaddon;	
}

See to it that the name Smile_Mailer_Myaddon matches.
The variables $slug, $settings are defined in constructor as shown below –

function __construct(){
	require_once('lib/your_api_files.php');
	add_action( 'admin_init', array( $this, 'enqueue_scripts' ) );
	add_action( 'wp_ajax_get_myaddon_data', array($this,'get_myaddon_data' ));
	add_action( 'wp_ajax_update_myaddon_authentication', array($this,'update_myaddon_authentication' ));
	add_action( 'wp_ajax_disconnect_myaddon', array($this,'disconnect_myaddon' ));
	add_action( 'wp_ajax_myaddon_add_subscriber', array($this,'myaddon_add_subscriber' ));
	add_action( 'wp_ajax_nopriv_myaddon_add_subscriber', array($this,'myaddon_add_subscriber' ));
	$this->setting  = array(
		'name' => 'MyAddon',
		'parameters' => array( 'api_key' ),
		'where_to_find_url' => 'https://link_showing_api_key',
		'logo_url' => plugins_url('images/logo.png', __FILE__)
			);
	$this->slug = 'myaddon';
}

Here include your API libraries (if any).

require_once('lib/your_api_files.php');

This action does the basic operations of adding your addon to ConvertPlus Third Party Mailer list dropdown. Also custom javascript files are added in this action.

add_action( 'admin_init', array( $this, 'enqueue_scripts' ) );

These actions does the operation to get lists from mailer, disconnect mailer, add a subscriber, authenticate mailer, etc.

add_action( 'wp_ajax_get_myaddon_data', array($this,'get_myaddon_data' ));
add_action( 'wp_ajax_update_myaddon_authentication', array($this,'update_myaddon_authentication' ));
add_action( 'wp_ajax_disconnect_myaddon', array($this,'disconnect_myaddon' ));
add_action( 'wp_ajax_myaddon_add_subscriber', array($this,'myaddon_add_subscriber' ));
add_action( 'wp_ajax_nopriv_myaddon_add_subscriber', array($this,'myaddon_add_subscriber' ));

This is the most important part. These are the class variables that define the mailer slug and other settings. Please be careful while declaring these variables.

$this->setting  = array(
	'name' => 'MyAddon',
	'parameters' => array( 'api_key' ),
	'where_to_find_url' => 'https://link_showing_api_key',
	'logo_url' => plugins_url('images/logo.png', __FILE__)
);

All the parameters mean as listed below:

Sr. No. Parameter Implication
1. name This is the display name of Your addon in ConvertPlus dropdown
2. parameters These are the authentication parameters needed for your addon like api_key or username & password
3. where_to_find_url This the the mailer document URL showing where the API key could be found.
4. logo_url This is the URL of the logo of your mailer, if this parameter is not set default ConvertPlus logo would be shown on Dashboard. Also you need to place your logo at root_folder/images/ with logo.png as its name. Try keeping the logo with size 150×150 for better view.

This slug should be kept in small cases. All the functions/actions should match this slug. For example:

$this->slug = 'myaddon';

Now add this below code as it is, things would work properly, since this is $settings & $slug, dependent operations:

/*
* Function Name: enqueue_scripts
* Function Description: Add custon scripts
*/
		
function enqueue_scripts() {
	if( function_exists( 'cp_register_addon' ) ) {
		cp_register_addon( $this->slug, $this->setting );
	}
	wp_register_script( $this->slug.'-script', plugins_url('js/' . $this->slug . '-script.js', __FILE__), array('jquery'), '1.1', true );
	wp_enqueue_script( $this->slug.'-script' );
			add_action( 'admin_head', array( $this, 'hook_css' ) );
}

/*
* Function Name: hook_css
* Function Description: Adds background style script for mailer logo.
*/


function hook_css() {
	if( isset( $this->setting['logo_url'] ) ) {
		if( $this->setting['logo_url'] != '' ) {
			$style = '<style>table.bsf-connect-optins td.column-provider.'.$this->slug.'::after {background-image: url("'.$this->setting['logo_url'].'");}.bend-heading-section.bsf-connect-list-header .bend-head-logo.'.$this->slug.'::before {background-image: url("'.$this->setting['logo_url'].'");}</style>';
			echo $style;
		}
	}
			
}

 

Not the solution you are looking for? Check other articles, or open a support ticket.