• I have setup Domain Mapping plugin, everything works great.

    Now, I would like to let users switch their domain from frontend (I disabled backend completely for various reasons). I already have code to add/remove DNS records on submitting form, the last step is to add or change the primary domain in the Domain Mapping settings.

    Is there a hook that I could use, or is there any other way to change or add new primary domain without writing to wp_domain_mapping table directly?

    Thanks

    https://www.ads-software.com/plugins/wordpress-mu-domain-mapping/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Ron Rennick

    (@wpmuguru)

    Is there a hook that I could use (etc.)

    No.

    Thread Starter Václav Greif

    (@vasikgreif)

    ?? Ok, short and exact answer…

    I did something like this:

    $wpdb->dmtable = $wpdb->base_prefix . 'domain_mapping';
    
            // if new domain is domain.com, set active status to 0
            if ($new_domain_host == 'domain.com') {
                $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->dmtable} SET active = %d WHERE blog_id = %s", 0, get_current_blog_id()));
            }
            // if record for this blog doesn't exist yet, insert it
            elseif ( null == $wpdb->get_var( $wpdb->prepare( "SELECT domain FROM {$wpdb->dmtable} WHERE blog_id = %d", get_current_blog_id()) )) {
                $wpdb->query( $wpdb->prepare( "INSERT INTO {$wpdb->dmtable} ( blog_id, domain, active ) VALUES ( %d, %s, %d )", get_current_blog_id(), $new_site_url, 1) );
            }
            // else update the record
            else {
                $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->dmtable} SET blog_id = %d, domain = %s, active = %d WHERE blog_id = %s", get_current_blog_id(), $new_site_url, 1, get_current_blog_id()));
            }

    Seems to work fine for what I need…

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add a domain from plugin’ is closed to new replies.