Support » Plugin: WordPress MU Domain Mapping » [Plugin: WordPress MU Domain Mapping] IDN Support

  • Resolved hever

    (@hever)


    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/

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

    (@wpmuguru)

    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.

    Thread Starter hever

    (@hever)

    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)

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: WordPress MU Domain Mapping] IDN Support’ is closed to new replies.