dmtable = $wpdb->base_prefix . 'domain_mapping'; if( VHOST == 'no' ) { die( 'Sorry, domain mapping only works on virtual host installs.' ); } if( is_site_admin() ) { if($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->dmtable}'") != $wpdb->dmtable) { $wpdb->query( "CREATE TABLE IF NOT EXISTS `{$wpdb->dmtable}` ( `id` bigint(20) NOT NULL auto_increment, `blog_id` bigint(20) NOT NULL, `domain` varchar(255) NOT NULL, `active` tinyint(4) default '1', PRIMARY KEY (`id`), KEY `blog_id` (`blog_id`,`domain`,`active`) );" ); ?>

escape( preg_replace( "/^www\./", "", $_POST[ 'domain' ] ) ); check_admin_referer( 'domain_mapping' ); switch( $_POST[ 'action' ] ) { case "add": if( null == $wpdb->get_row( "SELECT blog_id FROM {$wpdb->dmtable} WHERE domain = '$domain'" ) ) $wpdb->query( "INSERT INTO {$wpdb->dmtable} ( `id` , `blog_id` , `domain` , `active` ) VALUES ( NULL, '" . intval( $wpdb->blogid ) . "', '$domain', '1')" ); break; case "delete": $wpdb->query( "DELETE FROM {$wpdb->dmtable} WHERE domain = '$domain'" ); break; case "ipaddress": if( is_site_admin() ) add_site_option( 'dm_ipaddress', $_POST[ 'ipaddress' ] ); break; } } echo "

Domain Mapping

"; if( !file_exists( ABSPATH . '/wp-content/sunrise.php' ) ) { echo "Please copy sunrise.php to " . ABSPATH . "/wp-content/sunrise.php and uncomment the SUNRISE definition in " . ABSPATH . "wp-config.php"; echo "
"; die(); } if( !defined( 'SUNRISE' ) ) { echo "Please uncomment the line //define( 'SUNRISE', 'on' ); in your " . ABSPATH . "/wp-config.php"; echo ""; die(); } if( is_site_admin() ) { echo '

' . __( 'Site Admin Configuration' ) . '

'; echo "

" . __( "As a site admin on this site you can set the IP address users need to point their DNS A records at. If you don't know what it is, ping this blog to get the IP address." ) . "

"; echo '
'; echo ''; _e( "Server IP Address: " ); echo ""; wp_nonce_field( 'domain_mapping' ); echo ""; echo "

"; } $domains = $wpdb->get_results( "SELECT * FROM {$wpdb->dmtable} WHERE blog_id = '{$wpdb->blogid}'" ); if( is_array( $domains ) && !empty( $domains ) ) { ?>

'; echo $details->domain . " "; echo ''; echo ""; echo ""; wp_nonce_field( 'domain_mapping' ); echo "
"; } ?>
" . __( 'Add new domain' ) . ""; echo '
'; echo ''; echo "http://www./"; wp_nonce_field( 'domain_mapping' ); echo ""; echo "

"; echo "

" . __( 'If your domain name includes a hostname like "blog" or some other prefix before the actual domain name you will need to add a CNAME for that hostname in your DNS pointing at this blog URL. "www" does not count because it will be removed from the domain name.' ) . "

"; echo "

" . __( 'If you want to redirect a domain you will need to add a DNS "A" record pointing at the IP address of this server: ' ) . "" . get_site_option( 'dm_ipaddress', 'IP not set by admin yet.' ) . "

"; echo ""; } function domain_mapping_siteurl( $setting ) { global $wpdb; if( is_admin() ) return $setting; $s = $wpdb->suppress_errors(); $domain = $wpdb->get_var( "SELECT domain FROM {$wpdb->dmtable} WHERE blog_id = '{$wpdb->blogid}'" ); $wpdb->suppress_errors( $s ); $protocol = ( 'on' == strtolower($_SERVER['HTTPS']) ) ? 'https://' : 'http://'; if( $domain ) return $protocol . $domain; return $setting; } add_action( 'pre_option_siteurl', 'domain_mapping_siteurl' ); add_action( 'pre_option_home', 'domain_mapping_siteurl' ); ?>