The editable_extensions WordPress PHP filter allows you to modify the list of file types allowed for editing in the plugin file editor.
Usage
add_filter('editable_extensions', 'my_custom_editable_extensions', 10, 2); function my_custom_editable_extensions($default_types, $plugin) { // your custom code here return $default_types; }
Parameters
$default_types (string[])
: An array of editable plugin file extensions.$plugin (string)
: Path to the plugin file relative to the plugins directory.
More information
See WordPress Developer Resources: editable_extensions
Examples
Allow .json
files to be edited
Enable editing of .json
files in the plugin file editor.
add_filter('editable_extensions', 'allow_json_editing', 10, 2); function allow_json_editing($default_types, $plugin) { $default_types[] = 'json'; return $default_types; }
Disallow .css
files from being edited
Prevent editing of .css
files in the plugin file editor.
add_filter('editable_extensions', 'disallow_css_editing', 10, 2); function disallow_css_editing($default_types, $plugin) { $key = array_search('css', $default_types); if (false !== $key) { unset($default_types[$key]); } return $default_types; }
Add a custom file extension for editing
Allow editing of custom .myext
files in the plugin file editor.
add_filter('editable_extensions', 'allow_custom_extension_editing', 10, 2); function allow_custom_extension_editing($default_types, $plugin) { $default_types[] = 'myext'; return $default_types; }
Filter editable extensions for a specific plugin
Allow editing of .scss
files only for a specific plugin in the plugin file editor.
add_filter('editable_extensions', 'allow_scss_for_specific_plugin', 10, 2); function allow_scss_for_specific_plugin($default_types, $plugin) { if ('my-plugin/my-plugin.php' == $plugin) { $default_types[] = 'scss'; } return $default_types; }
Allow only PHP and JS files to be edited
Restrict the plugin file editor to only allow editing of .php
and .js
files.
add_filter('editable_extensions', 'allow_only_php_js_editing', 10, 2); function allow_only_php_js_editing($default_types, $plugin) { return array('php', 'js'); }