函数文档

allow_subdirectory_install()

💡 云策文档标注

概述

allow_subdirectory_install() 函数用于检查是否允许在 WordPress 多站点网络中启用子目录安装功能。它通过过滤器、常量或数据库查询来返回布尔值。

关键要点

  • 函数返回布尔值,指示是否允许子目录安装。
  • 首先检查 apply_filters('allow_subdirectory_install', false) 过滤器,允许开发者自定义。
  • 其次检查 ALLOW_SUBDIRECTORY_INSTALL 常量,若定义且为 true 则返回 true。
  • 最后通过 $wpdb->get_row() 查询数据库,但正文中查询不完整,可能涉及检查现有内容。
  • 相关 Hook:apply_filters('allow_subdirectory_install', bool $allow),用于过滤是否启用子目录安装功能。
  • 函数自 WordPress 3.0.0 版本引入。

📄 原文内容

Allow subdirectory installation.

Return

bool Whether subdirectory installation is allowed

Source

function allow_subdirectory_install() {
	global $wpdb;

	/**
	 * Filters whether to enable the subdirectory installation feature in Multisite.
	 *
	 * @since 3.0.0
	 *
	 * @param bool $allow Whether to enable the subdirectory installation feature in Multisite.
	 *                    Default false.
	 */
	if ( apply_filters( 'allow_subdirectory_install', false ) ) {
		return true;
	}

	if ( defined( 'ALLOW_SUBDIRECTORY_INSTALL' ) && ALLOW_SUBDIRECTORY_INSTALL ) {
		return true;
	}

	$post = $wpdb->get_row( "SELECT ID FROM $wpdb->posts WHERE post_date < DATE_SUB(NOW(), INTERVAL 1 MONTH) AND post_status = 'publish'" );
	if ( empty( $post ) ) {
		return true;
	}

	return false;
}

Hooks

apply_filters( ‘allow_subdirectory_install’, bool $allow )

Filters whether to enable the subdirectory installation feature in Multisite.

Changelog

Version Description
3.0.0 Introduced.