WordPress.org

Make WordPress Core

Ticket #6531: 6531-theme.diff

File 6531-theme.diff, 2.2 KB (added by WraithKenny, 9 months ago)

Adds filters for theme editor

  • wp-admin/theme-editor.php

    diff --git wp-admin/theme-editor.php wp-admin/theme-editor.php
    index 03b91944ea..24de2991f2 100644
    $file_types = array_unique( array_merge( $file_types, $default_types ) ); 
    8181foreach ( $file_types as $type ) {
    8282        switch ( $type ) {
    8383                case 'php':
    84                         $allowed_files += $theme->get_files( 'php', 1 );
     84                        $allowed_files += $theme->get_files( 'php', apply_filters( 'wp_theme_scandir_depth', 1, 'php', $theme ) );
    8585                        $has_templates = ! empty( $allowed_files );
    8686                        break;
    8787                case 'css':
    88                         $style_files = $theme->get_files( 'css' );
     88                        $style_files = $theme->get_files( 'css', apply_filters( 'wp_theme_scandir_depth', 0, 'css', $theme ) );
    8989                        $allowed_files['style.css'] = $style_files['style.css'];
    9090                        $allowed_files += $style_files;
    9191                        break;
    9292                default:
    93                         $allowed_files += $theme->get_files( $type );
     93                        $allowed_files += $theme->get_files( $type, apply_filters( 'wp_theme_scandir_depth', 0, $type, $theme ) );
    9494                        break;
    9595        }
    9696}
  • wp-includes/class-wp-theme.php

    diff --git wp-includes/class-wp-theme.php wp-includes/class-wp-theme.php
    index 0da9b5ea11..8fe2e9f72c 100644
    final class WP_Theme implements ArrayAccess { 
    468468                        case 'Stylesheet' :
    469469                                return $this->get_stylesheet();
    470470                        case 'Template Files' :
    471                                 return $this->get_files( 'php', 1, true );
     471                                return $this->get_files( 'php', apply_filters('wp_theme_scandir_depth', 1, 'php', $this ), true );
    472472                        case 'Stylesheet Files' :
    473                                 return $this->get_files( 'css', 0, false );
     473                                return $this->get_files( 'css', apply_filters('wp_theme_scandir_depth', 0, 'css', $this ), false );
    474474                        case 'Template Dir' :
    475475                                return $this->get_template_directory();
    476476                        case 'Stylesheet Dir' :
    final class WP_Theme implements ArrayAccess { 
    10031003                if ( ! is_array( $post_templates ) ) {
    10041004                        $post_templates = array();
    10051005
    1006                         $files = (array) $this->get_files( 'php', 1 );
     1006                        $files = (array) $this->get_files( 'php', apply_filters('wp_theme_scandir_depth', 1, $type, $this ) );
    10071007
    10081008                        foreach ( $files as $file => $full_path ) {
    10091009                                if ( ! preg_match( '|Template Name:(.*)$|mi', file_get_contents( $full_path ), $header ) ) {