* The theme name that the administrator has currently set the front end theme
* as.
*
- * For all extensive purposes, the template name and the stylesheet name are
+ * For all intents and purposes, the template name and the stylesheet name are
* going to be the same for most cases.
*
* @since 1.5.0
// Try prepending as the theme directory could be relative to the content directory
$directory = WP_CONTENT_DIR . '/' . $directory;
// If this directory does not exist, return and do not register
- if ( ! file_exists( $directory ) )
+ if ( ! file_exists( $directory ) ) {
return false;
+ }
}
- $wp_theme_directories[] = $directory;
+ if ( ! is_array( $wp_theme_directories ) ) {
+ $wp_theme_directories = array();
+ }
+
+ $untrailed = untrailingslashit( $directory );
+ if ( ! empty( $untrailed ) && ! in_array( $untrailed, $wp_theme_directories ) ) {
+ $wp_theme_directories[] = $untrailed;
+ }
return true;
}
return true;
}
+/**
+ * Retrieve any registered editor stylesheets
+ *
+ * @since 4.0.0
+ *
+ * @global $editor_styles Registered editor stylesheets
+ *
+ * @return array If registered, a list of editor stylesheet URLs.
+ */
+function get_editor_stylesheets() {
+ $stylesheets = array();
+ // load editor_style.css if the current theme supports it
+ if ( ! empty( $GLOBALS['editor_styles'] ) && is_array( $GLOBALS['editor_styles'] ) ) {
+ $editor_styles = $GLOBALS['editor_styles'];
+
+ $editor_styles = array_unique( array_filter( $editor_styles ) );
+ $style_uri = get_stylesheet_directory_uri();
+ $style_dir = get_stylesheet_directory();
+
+ // Support externally referenced styles (like, say, fonts).
+ foreach ( $editor_styles as $key => $file ) {
+ if ( preg_match( '~^(https?:)?//~', $file ) ) {
+ $stylesheets[] = esc_url_raw( $file );
+ unset( $editor_styles[ $key ] );
+ }
+ }
+
+ // Look in a parent theme first, that way child theme CSS overrides.
+ if ( is_child_theme() ) {
+ $template_uri = get_template_directory_uri();
+ $template_dir = get_template_directory();
+
+ foreach ( $editor_styles as $key => $file ) {
+ if ( $file && file_exists( "$template_dir/$file" ) ) {
+ $stylesheets[] = "$template_uri/$file";
+ }
+ }
+ }
+
+ foreach ( $editor_styles as $file ) {
+ if ( $file && file_exists( "$style_dir/$file" ) ) {
+ $stylesheets[] = "$style_uri/$file";
+ }
+ }
+ }
+ return $stylesheets;
+}
+
/**
* Allows a theme to register its support of a certain feature
*
case 'custom-header-uploads' :
return add_theme_support( 'custom-header', array( 'uploads' => true ) );
- break;
case 'custom-header' :
if ( ! is_array( $args ) )
if ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) )
return $_wp_theme_features[ $feature ][0][ $args[0] ];
return false;
- break;
+
default :
return $_wp_theme_features[ $feature ];
- break;
}
}
return true;
$content_type = $args[0];
return in_array( $content_type, $_wp_theme_features[$feature][0] );
- break;
case 'html5':
case 'post-formats':
$type = $args[0];
return in_array( $type, $_wp_theme_features[$feature][0] );
- break;
case 'custom-header':
case 'custom-background' :
// an array to add_theme_support()
$header_support = $args[0];
return ( isset( $_wp_theme_features[$feature][0][$header_support] ) && $_wp_theme_features[$feature][0][$header_support] );
- break;
}
/**
'url' => esc_url( admin_url( 'customize.php' ) ),
'isCrossDomain' => $cross_domain,
'browser' => $browser,
+ 'l10n' => array(
+ 'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ),
+ ),
);
$script = 'var _wpCustomizeLoaderSettings = ' . json_encode( $settings ) . ';';
</script>
<?php
}
+
+/**
+ * Whether the site is being previewed in the Customizer.
+ *
+ * @since 4.0.0
+ *
+ * @global WP_Customize_Manager $wp_customize Customizer instance.
+ *
+ * @return bool True if the site is being previewed in the Customizer, false otherwise.
+ */
+function is_customize_preview() {
+ global $wp_customize;
+
+ return is_a( $wp_customize, 'WP_Customize_Manager' ) && $wp_customize->is_preview();
+}