WPMU VHOST Constant

来自WordPress中文文档
跳转至: 导航搜索

Description

When installing WordPress MU (WPMU), an administrator can choose to use sub-domains or sub-directories for blog addresses. This presents a challenge for WordPress Plugin and Theme developers. How can a Plugin of Theme function determine if WordPress MU is using sub-domains or sub-directories?

The VHOST constant stores whether WordPress MU is using sub-domains for blog addresses. If an administrator chooses to use sub-domains, VHOST contains a value of yes. If the administrator chooses to use sub-directories, VHOST is set with a value of no.

Usage

A WordPress Plugin or Theme function can access the value of VHOST using the PHP constant function. br %%%?php constant( VHOST ); ?%%%

Example

The VHOST constant could be used within a plugin to control a logical test. The code below will print a different message depending on whether WPMU is using sub-domains or sub-directories.

pre

   if( constant( VHOST ) == 'yes' )
       echo I'm using sub-domains for blog addresses!;
   else
       echo I'm using sub-folders for blog addresses.;

/pre

References

For more information on the PHP Constant VHOST used in WordPress MU, see: