函数文档

wp_get_plugin_file_editable_extensions()

💡 云策文档标注

概述

wp_get_plugin_file_editable_extensions() 函数用于获取插件中可编辑文件的扩展名列表。它接受插件文件路径作为参数,返回一个包含默认扩展名的数组,并可通过 'editable_extensions' 过滤器进行自定义。

关键要点

  • 函数返回一个字符串数组,包含如 'php'、'css'、'js'、'json' 等可编辑文件扩展名。
  • 参数 $plugin 是必需的,表示相对于插件目录的插件文件路径。
  • 使用 apply_filters('editable_extensions', $default_types, $plugin) 允许开发者通过过滤器修改可编辑扩展名列表。
  • 该函数从 WordPress 4.9.0 版本开始引入。

代码示例

function wp_get_plugin_file_editable_extensions( $plugin ) {

	$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 plugin file editor.
	 *
	 * @since 2.8.0
	 * @since 4.9.0 Added the `$plugin` parameter.
	 *
	 * @param string[] $default_types An array of editable plugin file extensions.
	 * @param string   $plugin        Path to the plugin file relative to the plugins directory.
	 */
	$file_types = (array) apply_filters( 'editable_extensions', $default_types, $plugin );

	return $file_types;
}

📄 原文内容

Gets the list of file extensions that are editable in plugins.

Parameters

$pluginstringrequired
Path to the plugin file relative to the plugins directory.

Return

string[] Array of editable file extensions.

Source

function wp_get_plugin_file_editable_extensions( $plugin ) {

	$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 plugin file editor.
	 *
	 * @since 2.8.0
	 * @since 4.9.0 Added the `$plugin` parameter.
	 *
	 * @param string[] $default_types An array of editable plugin file extensions.
	 * @param string   $plugin        Path to the plugin file relative to the plugins directory.
	 */
	$file_types = (array) apply_filters( 'editable_extensions', $default_types, $plugin );

	return $file_types;
}

Hooks

apply_filters( ‘editable_extensions’, string[] $default_types, string $plugin )

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

Changelog

Version Description
4.9.0 Introduced.