Ticket #42645: 42645.7.diff
| File 42645.7.diff, 6.3 KB (added by , 6 years ago) |
|---|
-
src/wp-admin/edit-form-blocks.php
184 184 185 185 if ( $editor_styles && current_theme_supports( 'editor-styles' ) ) { 186 186 foreach ( $editor_styles as $style ) { 187 if ( preg_match( '~^(https?:)?//~', $style ) ) { 188 $response = wp_remote_get( $style ); 187 if ( preg_match( '~^(https?:)?//~', $style['file'] ) ) { 188 $style_url = $style['file']; 189 if ( isset( $style['version'] ) && $style['version'] ) { 190 $style_url .= '?ver=' . $style['version']; 191 } 192 $response = wp_remote_get( $style_url ); 189 193 if ( ! is_wp_error( $response ) ) { 190 194 $styles[] = array( 191 195 'css' => wp_remote_retrieve_body( $response ), 192 196 ); 193 197 } 194 198 } else { 195 $file = get_theme_file_path( $style );196 if ( is_file( $ file) ) {199 $file = get_theme_file_path( $style['file'] ); 200 if ( is_file( $style['file'] ) ) { 197 201 $styles[] = array( 198 'css' => file_get_contents( $ file),199 'baseURL' => get_theme_file_uri( $style ),202 'css' => file_get_contents( $style['file'] ), 203 'baseURL' => get_theme_file_uri( $style['file'] ), 200 204 ); 201 205 } 202 206 } -
src/wp-includes/theme.php
1927 1927 * It is a better option to use that class and add any RTL styles to the main stylesheet. 1928 1928 * 1929 1929 * @since 3.0.0 1930 * @since 5.3.0 Add version support. 1930 1931 * 1931 1932 * @global array $editor_styles 1932 1933 * 1933 * @param array|string $stylesheet Optional. Stylesheet name or array thereof, relative to theme root. 1934 * Defaults to 'editor-style.css' 1934 * @param array|string $stylesheet Optional. Stylesheet name or array thereof, 1935 * relative to theme root. Defaults to 1936 * 'editor-style.css' 1937 * @param array|string $version Optional. Stylesheet version or array thereof. 1938 * The versions will be attach to stylesheets 1939 * respectively. 1935 1940 */ 1936 function add_editor_style( $stylesheet = 'editor-style.css' ) {1941 function add_editor_style( $stylesheet = 'editor-style.css', $version = '' ) { 1937 1942 global $editor_styles; 1938 1943 1939 1944 add_theme_support( 'editor-style' ); 1940 1945 1941 1946 $editor_styles = (array) $editor_styles; 1942 1947 $stylesheet = (array) $stylesheet; 1948 $version = (array) $version; 1949 $stylesheets = array(); 1950 1951 for ( $i = 0; $i < count( $stylesheet ); $i++ ) { 1952 $stylesheets[ $i ] = array( 'file' => $stylesheet[ $i ] ); 1953 if ( isset( $version[ $i ] ) && $version[ $i ] ) { 1954 $stylesheets[ $i ]['version'] = $version[ $i ]; 1955 } 1956 } 1943 1957 1944 1958 if ( is_rtl() ) { 1945 1959 $rtl_stylesheet = str_replace( '.css', '-rtl.css', $stylesheet[0] ); 1946 $stylesheet[] = $rtl_stylesheet; 1960 if ( isset( $version[0] ) && $version[0] ) { 1961 $stylesheets[] = array( 1962 'file' => $rtl_stylesheet, 1963 'version' => $version[0], 1964 ); 1965 } else { 1966 $stylesheets[] = array( 'file' => $rtl_stylesheet ); 1967 } 1947 1968 } 1948 1969 1949 $editor_styles = array_merge( $editor_styles, $stylesheet );1970 $editor_styles = array_merge( $editor_styles, $stylesheets ); 1950 1971 } 1951 1972 1952 1973 /** … … 1979 2000 * @return array If registered, a list of editor stylesheet URLs. 1980 2001 */ 1981 2002 function get_editor_stylesheets() { 1982 $stylesheets = array(); 1983 // load editor_style.css if the current theme supports it 1984 if ( ! empty( $GLOBALS['editor_styles'] ) && is_array( $GLOBALS['editor_styles'] ) ) { 1985 $editor_styles = $GLOBALS['editor_styles']; 1986 1987 $editor_styles = array_unique( array_filter( $editor_styles ) ); 1988 $style_uri = get_stylesheet_directory_uri(); 1989 $style_dir = get_stylesheet_directory(); 1990 1991 // Support externally referenced styles (like, say, fonts). 1992 foreach ( $editor_styles as $key => $file ) { 1993 if ( preg_match( '~^(https?:)?//~', $file ) ) { 1994 $stylesheets[] = esc_url_raw( $file ); 1995 unset( $editor_styles[ $key ] ); 1996 } 2003 /** 2004 * Return eary if no editor style is found. 2005 * 2006 * @since 5.3.0 2007 */ 2008 if ( 2009 empty( $GLOBALS['editor_styles'] ) 2010 || ! is_array( $GLOBALS['editor_styles'] ) 2011 ) { 2012 return apply_filters( 'editor_stylesheets', array() ); 2013 } 2014 2015 $stylesheets = array(); 2016 $editor_styles = $GLOBALS['editor_styles']; 2017 2018 $editor_styles = array_filter( 2019 $editor_styles, 2020 function( $item ) { 2021 return ! ! strpos( $item['file'], '.css' ); 1997 2022 } 2023 ); 2024 $style_uri = get_stylesheet_directory_uri(); 2025 $style_dir = get_stylesheet_directory(); 1998 2026 1999 // Look in a parent theme first, that way child theme CSS overrides. 2000 if ( is_child_theme() ) { 2001 $template_uri = get_template_directory_uri(); 2002 $template_dir = get_template_directory(); 2003 2004 foreach ( $editor_styles as $key => $file ) { 2005 if ( $file && file_exists( "$template_dir/$file" ) ) { 2006 $stylesheets[] = "$template_uri/$file"; 2007 } 2008 } 2027 // Support externally referenced styles (like, say, fonts). 2028 foreach ( $editor_styles as $key => $file ) { 2029 if ( preg_match( '~^(https?:)?//~', $file ) ) { 2030 $stylesheets[] = esc_url_raw( $file ); 2031 unset( $editor_styles[ $key ] ); 2009 2032 } 2033 } 2010 2034 2011 foreach ( $editor_styles as $file ) { 2012 if ( $file && file_exists( "$style_dir/$file" ) ) { 2013 $stylesheets[] = "$style_uri/$file"; 2035 // Look in a parent theme first, that way child theme CSS overrides. 2036 if ( is_child_theme() ) { 2037 $template_uri = get_template_directory_uri(); 2038 $template_dir = get_template_directory(); 2039 2040 foreach ( $editor_styles as $key => $style ) { 2041 if ( ! file_exists( $template_dir . '/' . $style['file'] ) ) { 2042 continue; 2043 } 2044 if ( isset( $style['version'] ) && $style['version'] ) { 2045 $stylesheets[] = $template_uri . '/' . $style['file'] . '?ver=' . $style['version']; 2046 } else { 2047 $stylesheets[] = $template_uri . '/' . $style['file']; 2014 2048 } 2015 2049 } 2016 2050 } 2017 2051 2052 foreach ( $editor_styles as $key => $style ) { 2053 if ( ! file_exists( $style_dir . '/' . $style['file'] ) ) { 2054 continue; 2055 } 2056 if ( isset( $style['version'] ) && $style['version'] ) { 2057 $stylesheets[] = $style_uri . '/' . $style['file'] . '?ver=' . $style['version']; 2058 } else { 2059 $stylesheets[] = $style_uri . '/' . $style['file']; 2060 } 2061 } 2062 2018 2063 /** 2019 2064 * Filters the array of stylesheets applied to the editor. 2020 2065 *