get_subdirectory_reserved_names() - WordPress 函数参考中文文档

返回介绍

get_subdirectory_reserved_names()

发布于 2017-09-11 字数3140 浏览 931 评论 0

get_subdirectory_reserved_names()

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


描述


返回值

(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 );
}

更新日志

Version 描述
4.4.0 Introduced.

相关函数

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' );
    

上一篇:get_stylesheet_uri()

下一篇:get_submit_button()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!