How to trigger function call when a Custom Domain is Added for a site?

Hi guys!

How can I trigger a PHP function to run immediately before or after a site is mapped?

Hoping there's a WordPress "hook" or some way to add this to functions.php without impacting the plugin directly. :slight_smile:

The goal is that when a user goes to Tools -> "Domain Mapping" and enters the custom domain and clicks "Add" we would fire a PHP function.

That PHP function would make a simple API call which activates that custom domain in our DNS service that manages our domains.

Thanks!

  • aecnu
    • WP Unicorn

    Greetings Jennifer,

    Thank you for this great question and a significant item to bring up.

    How can I trigger a PHP function to run immediately before or after a site is mapped?

    I have no idea and this certainly does not fall within our support venue certainly being custom coding.

    However, I will see if I can get our lead developer in here with his invaluable insight and advice as to what a solution may be.

    Though this may take a bit longer then a normal ticket, I will try to get him in here asap.

    Cheers, Joe

  • Jennifer
    • The Incredible Code Injector

    Hi Aaron, thanks for the answer.

    The safe way to do this would be for the plugin to have a few simple hooks, i.e. before and after the domain is mapped. :slight_smile:

    Would you please take a look at this page - Donncha's Domain Mapping Plugin seems to have the precise type of hooks we're referring to, explained on this page:
    http://wordpress.org/extend/plugins/wordpress-mu-domain-mapping/other_notes/

    Actually what we're trying to do WITH this type of hook is exactly what he's showing in this example. We use CloudFlare for our DNS servers, and we're just trying to make an API call to the CloudFlare API to create the new domain in their DNS servers as soon as someone maps it.

    Could you please add this support to the WPMUdev domain mapping plugin? it would be a very useful feature.

    Thanks!

  • aecnu
    • WP Unicorn

    Greetings Jennifer,

    Thank you for your additional input, it is greatly appreciated.

    Though Aaron is NOT the lead developer to this plugin, I asked him to come in here and give you an answer to your query to get you on your way with what you originally asked.

    Now this ticket has taken a twist in the feature request zone which indeed will involve the lead developer and a totally different section of the forum.

    I will indeed move this ticket to the applicable feature requests forum and notify the lead developer of the request itself.

    Thank you for being a WPMU Dev Community Member!

    Cheers, Joe

  • Barry
    • DEV MAN’s Mascot

    Hi, sorry it took a while, but I've managed to get this included in the first pass of our rewrite of the plugin. There are now two hooks that you can use:

    do_action( 'domainmapping_added_domain', strtolower($domain), $this->db->blogid );

    and

    do_action( 'domainmapping_deleted_domain', strtolower($domain), $this->db->blogid );

    that are fired at the relevant points - to use simply add an add_action and check the parameters passed for the information - e.g.

    add_action( 'domainmapping_deleted_domain', 'my_function', 10, 2 );

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.