Using WordPress ‘ms_file_constants()’ PHP function

The ms_file_constants() WordPress PHP function defines multisite file constants for backward compatibility with legacy file-serving.




  • No parameters

More information

See WordPress Developer Resources: ms_file_constants()

This function is used for backward compatibility purposes and may be deprecated in the future.


Define Multisite File Constants

The following code defines multisite file constants for a WordPress multisite installation.

// Define multisite file constants

Disable File Serving for Multisite

The code below disables file serving for a multisite installation by not calling the ms_file_constants() function.

// Do not define multisite file constants to disable file serving
// ms_file_constants(); // Commented out

Check if Constants are Defined

In this example, we check if the multisite file constants are defined and then define them if they are not.

// Check if multisite file constants are defined
if (!defined('UPLOADBLOGSDIR')) {

Define Constants Manually

In the following code, we manually define multisite file constants instead of using the ms_file_constants() function.

// Manually define multisite file constants
define('UPLOADBLOGSDIR', 'wp-content/blogs.dir');
define('BLOGUPLOADDIR', UPLOADBLOGSDIR . '/' . get_current_blog_id() . '/files/');

Define Constants Conditionally

This example defines multisite file constants only if a specific condition is met, such as a certain plugin being active.

// Check if a specific plugin is active
if (is_plugin_active('my-plugin/my-plugin.php')) {