---
title: How to programmatically sync WP Ultimo domains to a server different from your email server
description: "Use the following code snippets to sync domains to a server different from your [email server](https://wpemailmanager.com/documentation/settings/general-settings/). To sync to your email server, please refer to this [article](https://wpemailmanager.com/documentation/code-snippets/how-to-programmatically-sync-domains-to-your-email-server/). Ensure that: 1. You are using WP Email Manager V 1.0.20.4 +. 2.…"
url: "https://wpemailmanager.com/docs/how-to-programmatically-sync-domains-to-a-server-different-from-your-email-server/"
updated: "2023-04-29"
category: Developers / Code Snippets
---

# How to programmatically sync WP Ultimo domains to a server different from your email server

Use the following code snippets to sync domains to a server different from your [email server](https://wpemailmanager.com/documentation/settings/general-settings/). To sync to your email server, please refer to this [article](https://wpemailmanager.com/documentation/code-snippets/how-to-programmatically-sync-domains-to-your-email-server/).

Ensure that:

1. You are using WP Email Manager V 1.0.20.4 +.
2. You have enabled [WP Ultimo integration](https://wpemailmanager.com/documentation/settings/general-settings/) in the general settings section.

## Domain Syncing With WP Ultimo V2.0+

### Adding Domains

The following code snippet adds a domain to the server when it is added via WP Ultimo's domain mapping functionality in WP Ultimo V2.0+.

```
/**
 * Adds a domain to the server when it is added via WP Ultimo
 *
 * @param string $domain The domain name being mapped.
 * @param int    $site_id ID of the site that is receiving that mapping.
 */
add_action('wu_add_domain', 'wpem_add_wp_ultimo_v2_domain_custom_integration', 10, 2);
function wpem_add_wp_ultimo_v2_domain_custom_integration($domain, $site_id)
{
	/*
	 * Integration Name
     *
	 * Allowed integration name values: aapanel, apiscp, cloudron, cwp, cpanel, cyberpanel, directadmin, enhance, fastpanel, froxlor, interworx, ispconfig, ispmanager, keyhelp, mailbox, mailcheap, mailcow, mailinabox, mailu, modoboa, plesk, poste, spanel, tinycp, twentyi, vestacp, virtualmin or webuzo
	 */
	$integration = '';

	/*
	 * Set up our integration's credentials
	 *
	 * Fill in the appropriate values based on the integration
	 *
	 * @see https://wpemailmanager.com/documentation/installation/wp-config-setup/ for what should be filled in for a given integration
	 */
	$credentials             = new StdClass();
	$credentials->provider   = $integration;
	$credentials->hostname   = '';
	$credentials->port       = '';
	$credentials->username   = '';
	$credentials->password   = '';
	$credentials->api_key    = '';
	$credentials->api_secret = '';

	// Get the integration's API
	$api = wp_email_manager_get_custom_api( $integration, $credentials );

	// Check if WP Ultimo integration is active
	$wp_ultimo_is_active = WP_Email_ManagerIntegrationsWP_UltimoUltimo::get_instance()->is_active;

	if( false == $wp_ultimo_is_active || null == $api )
	{
		return;
	}

	// Add domain to the server
	$api->add_domain($domain);
}
```

### Deleting Domains

The following code snippet deletes a domain from the server when it is deleted via WP Ultimo's domain mapping functionality in WP Ultimo V2.0+.

```
/**
 * Deletes the domain from the server when custom domain is removed from WP Ultimo V2.0+
 *
 * @param $deleted bool
 * @param $domain WP_UltimoModelsDomain
 */
add_action('wu_domain_post_delete', 'wpem_delete_wp_ultimo_v2_domain_custom_integration', 10, 2);
function wpem_delete_wp_ultimo_v2_domain_custom_integration($deleted, $domain)
{
	/*
	 * Integration Name
     *
	 * Allowed integration name values: aapanel, apiscp, cloudron, cwp, cpanel, cyberpanel, directadmin, enhance, fastpanel, froxlor, interworx, ispconfig, ispmanager, keyhelp, mailbox, mailcheap, mailcow, mailinabox, mailu, modoboa, plesk, poste, spanel, tinycp, twentyi, vestacp, virtualmin or webuzo
	 */
	$integration = '';

	/*
	 * Set up our integration's credentials
	 *
	 * Fill in the appropriate values based on the integration
	 *
	 * @see https://wpemailmanager.com/documentation/installation/wp-config-setup/ for what should be filled in for a given integration
	 */
	$credentials             = new StdClass();
	$credentials->provider   = $integration;
	$credentials->hostname   = '';
	$credentials->port       = '';
	$credentials->username   = '';
	$credentials->password   = '';
	$credentials->api_key    = '';
	$credentials->api_secret = '';

	// Get the integration's API
	$api = wp_email_manager_get_custom_api( $integration, $credentials );

	// Check if WP Ultimo integration is active
	$wp_ultimo_is_active = WP_Email_ManagerIntegrationsWP_UltimoUltimo::get_instance()->is_active;

	if(false == $wp_ultimo_is_active || null == $api)
	{
		return;
	}

	if( true == $deleted )
	{
		// Delete the domain from the server
		$api->delete_domain($domain->get_domain());
	}
}
```

## Domain Syncing With WP Ultimo V1.0+

### Adding Domains

The following code snippet adds a domain to the server when it is added via WP Ultimo's domain mapping functionality in WP Ultimo V1.0+.

```
/**
 * Adds a domain to the server when it is added via WP Ultimo V1.0
 *
 * @param MercatorMapping $mapping
 *
 */
add_action('mercator.mapping.created', 'wpem_add_wp_ultimo_v1_domain_custom_integration', 10, 1);
function wpem_add_wp_ultimo_v1_domain_custom_integration($mapping)
{
	/*
	 * Integration Name
     *
	 * Allowed integration name values: aapanel, apiscp, cloudron, cwp, cpanel, cyberpanel, directadmin, enhance, fastpanel, froxlor, interworx, ispconfig, ispmanager, keyhelp, mailbox, mailcheap, mailcow, mailinabox, mailu, modoboa, plesk, poste, spanel, tinycp, twentyi, vestacp, virtualmin or webuzo
	 */
	$integration = '';

	/*
	 * Set up our integration's credentials
	 *
	 * Fill in the appropriate values based on the integration
	 *
	 * @see https://wpemailmanager.com/documentation/installation/wp-config-setup/ for what should be filled in for a given integration
	 */
	$credentials             = new StdClass();
	$credentials->provider   = $integration;
	$credentials->hostname   = '';
	$credentials->port       = '';
	$credentials->username   = '';
	$credentials->password   = '';
	$credentials->api_key    = '';
	$credentials->api_secret = '';

	// Get the integration's API
	$api = wp_email_manager_get_custom_api( $integration, $credentials );

	// Check if WP Ultimo integration is active
	$wp_ultimo_is_active = WP_Email_ManagerIntegrationsWP_UltimoUltimo::get_instance()->is_active;

	if(false == $wp_ultimo_is_active || null == $api)
	{
		return;
	}

	// Add domain to the server
	$api->add_domain($mapping->get_domain());
}
```

### Deleting Domains

The following code snippet deletes a domain from the server when it is deleted via WP Ultimo's domain mapping functionality in WP Ultimo V1.0+.

```
/**
 * Delete a domain from the server when it removed added via WP Ultimo V1.0
 *
 * @param MercatorMapping $mapping
 *
 */
add_action('mercator.mapping.deleted', 'wpem_delete_wp_ultimo_v1_domain_custom_integration', 10, 1);
function wpem_delete_wp_ultimo_v1_domain_custom_integration($mapping)
{
	/*
	 * Integration Name
     *
	 * Allowed integration name values:  aapanel, apiscp, cloudron, cwp, cpanel, cyberpanel, directadmin, enhance, fastpanel, froxlor, interworx, ispconfig, ispmanager, keyhelp, mailbox, mailcheap, mailcow, mailinabox, mailu, modoboa, plesk, poste, spanel, tinycp, twentyi, vestacp, virtualmin or webuzo
	 */
	$integration = '';

	/*
	 * Set up our integration's credentials
	 *
	 * Fill in the appropriate values based on the integration
	 *
	 * @see https://wpemailmanager.com/documentation/installation/wp-config-setup/ for what should be filled in for a given integration
	 */
	$credentials             = new StdClass();
	$credentials->provider   = $integration;
	$credentials->hostname   = '';
	$credentials->port       = '';
	$credentials->username   = '';
	$credentials->password   = '';
	$credentials->api_key    = '';
	$credentials->api_secret = '';

	// Get the integration's API
	$api = wp_email_manager_get_custom_api( $integration, $credentials );

	// Check if WP Ultimo integration is active
	$wp_ultimo_is_active = WP_Email_ManagerIntegrationsWP_UltimoUltimo::get_instance()->is_active;

	if(false == $wp_ultimo_is_active || null == $api)
	{
		return;
	}

	// Delete the domain from the server
	$api->delete_domain($mapping->get_domain());
}
```
