WordPress.org

Ready to get started?Download WordPress

Forums

WordPress MU Domain Mapping
[resolved] IDN Support (3 posts)

  1. hever
    Member
    Posted 2 years ago #

    Hello,

    I needed IDN Support for international domain names for your plugin, so I implemented it. It would be great if you could merge this into the official plugin.

    It was really easy:

    1. Include the following IDN Converter (seems stable and is also used in the IDNA WP plugin [http://wordpress.org/extend/plugins/idna/])
    http://www.phpclasses.org/package/1509-PHP-Convert-from-and-to-IDNA-Punycode-domain-names.html

    2. Apply 2 minor changes in redirect_to_mapped_domain():
    a. require_once ... the converter class
    b. strtolower() and $IDN->encode() the $url and $current_blog->domain before the comparison.

    This is the complete code:

    function redirect_to_mapped_domain() {
    	global $current_blog, $wpdb;
    
        if( ! class_exists('idna_convert') ) require_once(dirname(__FILE__) . '/idna_convert.class.php');
        $IDN = new idna_convert();
    
    	if ( !isset( $_SERVER[ 'HTTPS' ] ) )
    		$_SERVER[ 'HTTPS' ] = "off";
    	$protocol = ( 'on' == strtolower($_SERVER['HTTPS']) ) ? 'https://' : 'http://';
    	$url = domain_mapping_siteurl( false );
    	if ( $url && strtolower($IDN->encode($url)) != strtolower(untrailingslashit( $protocol . $IDN->encode($current_blog->domain) . $current_blog->path )) ) {
    		$redirect = get_site_option( 'dm_301_redirect' ) ? '301' : '302';
    		if ( ( defined( 'VHOST' ) && constant( "VHOST" ) != 'yes' ) || ( defined( 'SUBDOMAIN_INSTALL' ) && constant( 'SUBDOMAIN_INSTALL' ) == false ) ) {
    			$_SERVER[ 'REQUEST_URI' ] = str_replace( $current_blog->path, '/', $_SERVER[ 'REQUEST_URI' ] );
    		}
    		header( "Location: {$url}{$_SERVER[ 'REQUEST_URI' ]}", true, $redirect );
    		exit;
    	}
    }

    The IDN WP Plugin doesn't check if class_exists('idna_convert'). So here could be problems but I'll report that to them as well.

    Thanks!

    http://wordpress.org/extend/plugins/wordpress-mu-domain-mapping/

  2. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 2 years ago #

    Actually, you can build a separate plugin to handle that. Something along the lines of

    function hever_idn_rehook_redirect() {
    remove_action( 'template_redirect', 'redirect_to_mapped_domain' );
    add_action( 'template_redirect', 'hever_redirect_to_mapped_domain' );
    }
    add_action( 'plugins_loaded', 'hever_idn_rehook_redirect' );

    And rename the function you have above to hever_redirect_to_mapped_domain.

    If you do that & put the plugin up on wordpress.org/extend, hit my contact form at http://ronandandrea.com/contact/ and I'll add a note to the DM readme.

  3. hever
    Member
    Posted 2 years ago #

    Hi Ron!

    But IDN support is a great and in fact an important feature. In my opinion it's a bit more like a bugfix than a feature because using Domains with special characters is not possible at the moment.

    Perhaps it's also a good idea to merge it into the IDN WP Module? Then the external IDN script would be maintained in one place, as the whole WordPress IDN Support...

    I don't think having an own plugin for this or for each other plugin that needs IDN Support is really reasonable. I'll try to contact the IDN Plugin developer as well. (http://wordpress.org/support/topic/plugin-idna-idn-support-for-wordpress-mu-domain-mapping-plugin)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic