WordPress.org

Ready to get started?Download WordPress

Plugin Directory

WordPress MU Domain Mapping

Map any blog/site on a WordPressMU or WordPress 3.X network to an external domain.

Action Hooks

You can now hook into certain parts of the domain_mapping mu-plugin to enable you to extend the features that are built in without the need to modify this plugin. To do this, just create a script within the mu-plugins dir that is called AFTER this plugin (eg, call it domain_mapping_extended.php).

  • dm_echo_updated_msg

This hook is for when you want to add extra messages for your end users when they update their settings, the current usage would be to remove the existing action and replace it with your own as shown within the example further down the page.

  • dm_handle_actions_init

Before we add our own handlers for our users wanting to update their mappings, we can use this action to maybe connect to your datacenter API ready for communication. An example would be to load an API class and connect before we send and recieve XML queries. Once again, see the example down the page. Your function can make use of the $domain variable.

  • dm_handle_actions_add

When an user adds a domain name to their mappings, this action can be used to perform other tasks on your server. An example would be to check the user has already set up the DNS records for the name to correctly point to your server. Your function can make use of the $domain variable.

  • dm_handle_actions_primary

This may or may not be commonly used in most cases but is there just in case. Your function can make use of the $domain variable.

  • dm_handle_actions_del

When an user deletes one of their domain mappings, this action can be used to reverse what dm_handle_actions_add has done. An example would be to remove the domain mapping from your server using your datacenter's API. Your function can make use of the $domain variable.

  • dm_delete_blog_domain_mappings

If the blog is ever deleted and you make use of handle_actions, then this action will enable you to tidy up. An example would be when an user has set up multiple domain mappings and the blog is deleted, your function can remove any mess left behind. Your function can make use of the $domains array (numbered array of domains). NOTE, this will also be called if the user has no mappings, care should be taken in the case of an empty array.

EXAMPLE USAGE

    <pre><code>&lt;?php // Filename: mu-plugins/domain_mapping_extended.php

// NOTE, // This example will not 'just work' for anyone, it is to show basic // usage of dm_echo_updated_msg, dm_handle_actions_init and // dm_handle_actions_add

// We do not need translations but would really like a message when a // users DNS entry is not ready

function dm_echo_extended_updated_msg() { switch( $_GET[ 'updated' ] ) { case "add": $msg = 'You have added a new domain name.'; break; case "exists": $msg = 'That domain name already exists, please try again.'; break; case "primary": $msg = 'New primary domain created - enjoy!'; break; case "del": $msg = 'The domain name has been removed.'; break; case "dnslookup": $msg = 'The domain is not pointing to ' . get_site_option( 'dm_cname' ) . ', please set up your DNS.'; break; } echo "<div class='updated fade'><p>$msg</p></div>"; } // REMOVE THE ORIGINAL MESSAGES remove_action('dm_echo_updated_msg','dm_echo_default_updated_msg'); // REPLACE WITH OUR OWN add_action('dm_echo_updated_msg','dm_echo_extended_updated_msg');

// Prepare to use our Datacenter API

function dm_extended_handle_actions_init($domain) { global $datacenter_api; // There is a good chance we will be accessing the datacentre API require_once(dirname(FILE) ."/classes/xmlAbstract.class.php"); require_once(dirname(FILE) ."/classes/xmlParserClass.php"); require_once(dirname(FILE) ."/classes/datacenterAPIClass.php"); $datacenter_api = new datacenter_api('MY_API_KEY', 'API_TYPE'); } $datacenter_api = null; add_action('dm_handle_actions_init', 'dm_extended_handle_actions_init');

// Check the users DNS is ready to go (we are using the CNAME option) // then add the mapping to the datacenter API

function dm_extended_handle_actions_add($domain) { global $datacenter_api; // Check the domain has the correct CNAME/ANAME record $dmip = gethostbyname(get_site_option( 'dm_cname' )); $urip = gethostbyname($domain); if ($dmip != $urip) { wp_redirect( '?page=domainmapping&updated=dnslookup' ); exit; } $datacenter_api->add_mapping($domain); } add_action('dm_handle_actions_add', 'dm_extended_handle_actions_add'); ?>

Requires: 3.1 or higher
Compatible up to: 3.9.1
Last Updated: 2014-4-17
Downloads: 247,630

Ratings

4 stars
4.5 out of 5 stars

Support

23 of 62 support threads in the last two months have been resolved.

Got something to say? Need help?

Compatibility

+
=
Works!

9 people say it works.
2 people say it's broken.

100,1,1
100,3,3
100,4,4 89,9,8
0,1,0
50,4,2 60,5,3
100,1,1 71,7,5 100,1,1
57,14,8 90,21,19
85,27,23 85,20,17 0,1,0
100,4,4
100,3,3
100,6,6
100,1,1
58,12,7 88,17,15
50,6,3
100,3,3
75,8,6 100,1,1
100,2,2
100,2,2
100,1,1 75,4,3 92,25,23
30,20,6
50,20,10 82,28,23
100,2,2
20,5,1
71,17,12
93,28,26 100,1,1
70,20,14
60,15,9 79,19,15
67,9,6
69,13,9
100,1,1 33,6,2
50,2,1
86,7,6
100,7,7
100,6,6
100,1,1
0,1,0
82,11,9