Opened 12 years ago
Closed 9 years ago
#22924 closed enhancement (fixed)
Add filter to theme editor accepted files
Reported by: | pross | Owned by: | wonderboymusic |
---|---|---|---|
Milestone: | 4.4 | Priority: | normal |
Severity: | normal | Version: | 3.5 |
Component: | Themes | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
Proposing adding a filter to theme-editor.php so theme authors can add to the list of files that are editable. ie html/less/js files.
Hers an example of what could be possible:
add_filter( 'wp_theme_editor_filetypes', 'add_my_filetype', 10, 2 ); function add_my_filetype( $allowed_types, $theme ) { $extra = $theme->get_files( 'less', 1 ); return $allowed_types += $extra; }
Attachments (8)
Change History (24)
#6
@
10 years ago
22924.diff is a refresh of theme-editor.php with docs.
#7
@
9 years ago
- Owner set to wonderboymusic
- Resolution set to fixed
- Status changed from new to closed
In 35134:
#9
follow-up:
↓ 10
@
9 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
Is the intention of the new wp_theme_editor_filetypes
filter to make it possible to bring in arbitrary files or to expand the filetypes? Seems like based on the name alone we might be better off doing an array of file types then looping with $theme->get_files()
on those types, e.g.
(pseudo)
<?php /** * Filter the list of files allowed for editing in the Theme editor. * * @since 4.4.0 * * @param array $file_types List of file types. * @param object $theme The current Theme object. */ $file_types = apply_filters( 'wp_theme_editor_filetypes', array( 'php', 'css' ), $theme ); foreach ( $file_types as $type ) { $allowed_files + $theme->get_files( $type ); } ... if ( $allowed_files ) : if ( $theme->get_files( 'php' ) || $theme->parent() ) : ?>
The hook description also needs a little work, it's super vague.
#10
in reply to:
↑ 9
;
follow-up:
↓ 11
@
9 years ago
Replying to DrewAPicture:
Is the intention of the new
wp_theme_editor_filetypes
filter to make it possible to bring in arbitrary files or to expand the filetypes? Seems like based on the name alone we might be better off doing an array of file types then looping with$theme->get_files()
on those types, e.g.
Original intention was to allow users the ability to edit .less files that were part of a theme.
The theme would add 'less' to the allowed filetypes using the filter.
#11
in reply to:
↑ 10
;
follow-up:
↓ 12
@
9 years ago
Replying to pross:
Replying to DrewAPicture:
Is the intention of the new
wp_theme_editor_filetypes
filter to make it possible to bring in arbitrary files or to expand the filetypes? Seems like based on the name alone we might be better off doing an array of file types then looping with$theme->get_files()
on those types, e.g.
Original intention was to allow users the ability to edit .less files that were part of a theme.
The theme would add 'less' to the allowed filetypes using the filter.
Precisely. The problem is that with this hook name it implies filetypes not files. So if the intention is to actually filter file types, something closer to my solution in comment:9 would probably be better-suited.
#12
in reply to:
↑ 11
;
follow-up:
↓ 13
@
9 years ago
Replying to DrewAPicture:
The problem is that with this hook name it implies filetypes not files. So if the intention is to actually filter file types, something closer to my solution in comment:9 would probably be better-suited.
22924.2.diff implements comment:9. php
and css
cannot be removed, only new types can be added.
One issue with both [35134] and the patch is that new files are added under "Styles" heading, which doesn't make sense (see 22924.png, where I've added txt
as an example).
#13
in reply to:
↑ 12
@
9 years ago
- Keywords commit added
Replying to SergeyBiryukov:
One issue with both [35134] and the patch is that new files are added under "Styles" heading, which doesn't make sense (see 22924.png, where I've added
txt
as an example).
22924.3.diff fixes that. Other types are displayed in their own section, see 22924.3.png.
If new file types are added to the beginning of the array, before php
, that section is displayed first.
This ticket was mentioned in Slack in #core by drew. View the logs.
9 years ago
#15
@
9 years ago
@SergeyBiryukov: 22924.5.diff:
- Removes txt type per your patch
$theme
is aWP_Theme
object- DRYs the base list of types
- Adds an
array_unique()
around the merge
Created a test.less file in my theme, added the patch and example. It worked great, I think this would be a good addition.