Ticket #42645: 42645.6.diff
| File 42645.6.diff, 6.1 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 1934 * @param array|string $stylesheet Optional. Stylesheet name or array thereof, relative to theme root. 1934 1935 * Defaults to 'editor-style.css' 1936 * @param array|string $version Optional. Stylesheet version or array thereof. 1937 * The versions will be attach to stylesheets 1938 * respectively. 1935 1939 */ 1936 function add_editor_style( $stylesheet = 'editor-style.css' ) {1940 function add_editor_style( $stylesheet = 'editor-style.css', $version = '' ) { 1937 1941 global $editor_styles; 1938 1942 1939 1943 add_theme_support( 'editor-style' ); 1940 1944 1941 1945 $editor_styles = (array) $editor_styles; 1942 1946 $stylesheet = (array) $stylesheet; 1947 $version = (array) $version; 1948 $stylesheets = array(); 1949 1950 for ( $i = 0; $i < count( $stylesheet ); $i++ ) { 1951 $stylesheets[ $i ] = array( 'file' => $stylesheet[ $i ] ); 1952 if ( isset( $version[ $i ] ) && $version[ $i ] ) { 1953 $stylesheets[ $i ]['version'] = $version[ $i ]; 1954 } 1955 } 1943 1956 1944 1957 if ( is_rtl() ) { 1945 1958 $rtl_stylesheet = str_replace( '.css', '-rtl.css', $stylesheet[0] ); 1946 $stylesheet[] = $rtl_stylesheet; 1959 if ( isset( $version[0] ) && $version[0] ) { 1960 $stylesheets[] = array( 1961 'file' => $rtl_stylesheet, 1962 'version' => $version[0], 1963 ); 1964 } else { 1965 $stylesheets[] = array( 'file' => $rtl_stylesheet ); 1966 } 1947 1967 } 1948 1968 1949 $editor_styles = array_merge( $editor_styles, $stylesheet );1969 $editor_styles = array_merge( $editor_styles, $stylesheets ); 1950 1970 } 1951 1971 1952 1972 /** … … 1979 1999 * @return array If registered, a list of editor stylesheet URLs. 1980 2000 */ 1981 2001 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 } 2002 /** 2003 * Return eary if no editor style is found. 2004 * 2005 * @since 5.3.0 2006 */ 2007 if ( 2008 empty( $GLOBALS['editor_styles'] ) 2009 || ! is_array( $GLOBALS['editor_styles'] ) 2010 ) { 2011 return apply_filters( 'editor_stylesheets', array() ); 2012 } 2013 2014 $stylesheets = array(); 2015 $editor_styles = $GLOBALS['editor_styles']; 2016 2017 $editor_styles = array_filter( 2018 $editor_styles, 2019 function( $item ) { 2020 return ! ! strpos( $item['file'], '.css' ); 1997 2021 } 2022 ); 2023 $style_uri = get_stylesheet_directory_uri(); 2024 $style_dir = get_stylesheet_directory(); 1998 2025 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 } 2026 // Support externally referenced styles (like, say, fonts). 2027 foreach ( $editor_styles as $key => $file ) { 2028 if ( preg_match( '~^(https?:)?//~', $file ) ) { 2029 $stylesheets[] = esc_url_raw( $file ); 2030 unset( $editor_styles[ $key ] ); 2009 2031 } 2032 } 2010 2033 2011 foreach ( $editor_styles as $file ) { 2012 if ( $file && file_exists( "$style_dir/$file" ) ) { 2013 $stylesheets[] = "$style_uri/$file"; 2034 // Look in a parent theme first, that way child theme CSS overrides. 2035 if ( is_child_theme() ) { 2036 $template_uri = get_template_directory_uri(); 2037 $template_dir = get_template_directory(); 2038 2039 foreach ( $editor_styles as $key => $style ) { 2040 if ( ! file_exists( $template_dir . '/' . $style['file'] ) ) { 2041 continue; 2042 } 2043 if ( isset( $style['version'] ) && $style['version'] ) { 2044 $stylesheets[] = $template_uri . '/' . $style['file'] . '?ver=' . $style['version']; 2045 } else { 2046 $stylesheets[] = $template_uri . '/' . $style['file']; 2014 2047 } 2015 2048 } 2016 2049 } 2017 2050 2051 foreach ( $editor_styles as $key => $style ) { 2052 if ( ! file_exists( $style_dir . '/' . $style['file'] ) ) { 2053 continue; 2054 } 2055 if ( isset( $style['version'] ) && $style['version'] ) { 2056 $stylesheets[] = $style_uri . '/' . $style['file'] . '?ver=' . $style['version']; 2057 } else { 2058 $stylesheets[] = $style_uri . '/' . $style['file']; 2059 } 2060 } 2061 2018 2062 /** 2019 2063 * Filters the array of stylesheets applied to the editor. 2020 2064 *