返回介绍

get_subdirectory_reserved_names()

发布于 2017-09-11 00:15:28 字数 3140 浏览 1069 评论 0 收藏 0

get_subdirectory_reserved_names()

Retrieves a list of reserved site on a sub-directory Multisite install.


description


返回值

(array) $names Array of reserved subdirectory names.


源代码

File: wp-includes/ms-functions.php

function get_subdirectory_reserved_names() {
	$names = array(
		'page', 'comments', 'blog', 'files', 'feed', 'wp-admin',
		'wp-content', 'wp-includes', 'wp-json', 'embed'
	);

	/**
	 * Filters reserved site names on a sub-directory Multisite install.
	 *
	 * @since 3.0.0
	 * @since 4.4.0 'wp-admin', 'wp-content', 'wp-includes', 'wp-json', and 'embed' were added
	 *              to the reserved names list.
	 *
	 * @param array $subdirectory_reserved_names Array of reserved names.
	 */
	return apply_filters( 'subdirectory_reserved_names', $names );
}

更新日志

Versiondescription
4.4.0Introduced.

相关函数

Uses

  • wp-includes/plugin.php: apply_filters()
  • wp-includes/ms-functions.php: subdirectory_reserved_names

Used By

  • wp-includes/ms-functions.php: wpmu_validate_blog_signup()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 1You must log in to vote on the helpfulness of this note Contributed by daniyalahmedk

    Allow “/blog” in multsite network :

    function mod_subdirectory_reserved_names() {
        $names = array(
            'page', 'comments', 'files', 'feed', 'wp-admin',
            'wp-content', 'wp-includes', 'wp-json', 'embed'
        );
    }
    add_filter( "subdirectory_reserved_names", "mod_subdirectory_reserved_names");
  2. Here is better solution to modify this list of reserved names. Solution by daniyalahmedk not working for 2 reasons:

    1. The function not returning anything. There is no return state in the function and WordPress get null as result of this function (not array with words).
    2. Function not accepting args. This means all other plugins/code changes will be replaced.
    
    /**
     * Modify reserved names for sites.
     *
     * @param $names array List of reserved names for sites.
     *
     * @return array Updated list of reserved names for sites.
     */
    function change_subdirectory_reserved_names( $names ) {
    	$position = array_search( 'blog', $names );
    
    	if( $position ) {
    		unset( $names[$position] );
    	}
    
    	return $names;
    }
    add_filter( 'subdirectory_reserved_names', 'change_subdirectory_reserved_names' );
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文