Skip to content

Instantly share code, notes, and snippets.

@seothemes
Created June 10, 2024 04:41
Show Gist options
  • Save seothemes/fcc675d3723b38a25505dc309229663e to your computer and use it in GitHub Desktop.
Save seothemes/fcc675d3723b38a25505dc309229663e to your computer and use it in GitHub Desktop.
Hide directories from wp file editor
<?php
// Hide 'assets' directory from theme file editor.
add_filter( 'theme_scandir_exclusions', static function ( array $exclusions ): array {
global $current_screen;
if ( ! $current_screen || ! in_array( $current_screen->id, [ 'theme-editor-network', 'theme-editor' ] ) ) {
return $exclusions;
}
$exclusions[] = 'assets';
return $exclusions;
} );
// Hide 'assets' directory from plugin file editor.
add_filter( 'plugin_files_exclusions', static function ( array $exclusions ): array {
global $current_screen;
if ( ! $current_screen || ! in_array( $current_screen->id, [ 'plugin-editor-network', 'plugin-editor' ] ) ) {
return $exclusions;
}
$exclusions[] = 'assets';
return $exclusions;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment