函数文档

wp_get_theme_file_editable_extensions()

💡 云策文档标注

概述

wp_get_theme_file_editable_extensions() 函数用于获取指定主题的可编辑文件扩展名列表。它返回一个数组,包含默认支持的文件类型,并允许通过过滤器进行自定义。

关键要点

  • 函数接受一个 WP_Theme 对象作为参数,返回字符串数组表示可编辑的文件扩展名。
  • 默认包含多种文件类型,如 css、js、php、html、json、xml 等。
  • 可通过 wp_theme_editor_filetypes 过滤器修改或扩展可编辑文件类型列表。
  • 函数确保默认类型始终包含在返回数组中,即使过滤器修改了列表。

代码示例

function wp_get_theme_file_editable_extensions( $theme ) {

	$default_types = array(
		'bash',
		'conf',
		'css',
		'diff',
		'htm',
		'html',
		'http',
		'inc',
		'include',
		'js',
		'json',
		'jsx',
		'less',
		'md',
		'patch',
		'php',
		'php3',
		'php4',
		'php5',
		'php7',
		'phps',
		'phtml',
		'sass',
		'scss',
		'sh',
		'sql',
		'svg',
		'text',
		'txt',
		'xml',
		'yaml',
		'yml',
	);

	/**
	 * Filters the list of file types allowed for editing in the theme file editor.
	 *
	 * @since 4.4.0
	 *
	 * @param string[] $default_types An array of editable theme file extensions.
	 * @param WP_Theme $theme         The active theme object.
	 */
	$file_types = apply_filters( 'wp_theme_editor_filetypes', $default_types, $theme );

	// Ensure that default types are still there.
	return array_unique( array_merge( $file_types, $default_types ) );
}

📄 原文内容

Gets the list of file extensions that are editable for a given theme.

Parameters

$themeWP_Themerequired
Theme object.

Return

string[] Array of editable file extensions.

Source

function wp_get_theme_file_editable_extensions( $theme ) {

	$default_types = array(
		'bash',
		'conf',
		'css',
		'diff',
		'htm',
		'html',
		'http',
		'inc',
		'include',
		'js',
		'json',
		'jsx',
		'less',
		'md',
		'patch',
		'php',
		'php3',
		'php4',
		'php5',
		'php7',
		'phps',
		'phtml',
		'sass',
		'scss',
		'sh',
		'sql',
		'svg',
		'text',
		'txt',
		'xml',
		'yaml',
		'yml',
	);

	/**
	 * Filters the list of file types allowed for editing in the theme file editor.
	 *
	 * @since 4.4.0
	 *
	 * @param string[] $default_types An array of editable theme file extensions.
	 * @param WP_Theme $theme         The active theme object.
	 */
	$file_types = apply_filters( 'wp_theme_editor_filetypes', $default_types, $theme );

	// Ensure that default types are still there.
	return array_unique( array_merge( $file_types, $default_types ) );
}

Hooks

apply_filters( ‘wp_theme_editor_filetypes’, string[] $default_types, WP_Theme $theme )

Filters the list of file types allowed for editing in the theme file editor.

Changelog

Version Description
4.9.0 Introduced.