mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01:00
Add wp_default_styles(), convert wp_admin_css(). Props mdawaffe. see #7011
git-svn-id: http://svn.automattic.com/wordpress/trunk@7976 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
1519e51f89
commit
9178934544
@ -29,14 +29,13 @@ get_admin_page_title();
|
||||
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
|
||||
<title><?php bloginfo('name') ?> › <?php echo wp_specialchars( strip_tags( $title ) ); ?> — WordPress</title>
|
||||
<?php
|
||||
|
||||
wp_admin_css( 'css/global' );
|
||||
wp_admin_css();
|
||||
wp_admin_css( 'css/colors' );
|
||||
wp_admin_css( 'css/ie' );
|
||||
|
||||
?>
|
||||
<!--[if gte IE 6]>
|
||||
<?php wp_admin_css( 'css/ie' );
|
||||
?>
|
||||
<![endif]-->
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
addLoadEvent = function(func) {if (typeof jQuery != "undefined") jQuery(document).ready(func); else if (typeof wpOnload!='function'){wpOnload=func;} else {var oldonload=wpOnload; wpOnload=function(){oldonload();func();}}};
|
||||
|
@ -55,7 +55,7 @@ class WP_Scripts extends WP_Dependencies {
|
||||
}
|
||||
|
||||
$src = add_query_arg('ver', $ver, $src);
|
||||
$src = clean_url(apply_filters( 'script_loader_src', $src ));
|
||||
$src = clean_url(apply_filters( 'script_loader_src', $src, $handle ));
|
||||
|
||||
$this->print_scripts_l10n( $handle );
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
class WP_Styles extends WP_Dependencies {
|
||||
var $base_url;
|
||||
var $default_version;
|
||||
var $text_direction = 'ltr';
|
||||
|
||||
function __construct() {
|
||||
do_action_ref_array( 'wp_default_styles', array(&$this) );
|
||||
@ -21,15 +22,25 @@ class WP_Styles extends WP_Dependencies {
|
||||
else
|
||||
$media = 'all';
|
||||
|
||||
$src = $this->registered[$handle]->src;
|
||||
if ( !preg_match('|^https?://|', $src) ) {
|
||||
$src = $this->base_url . $src;
|
||||
$href = $this->_css_href( $this->registered[$handle]->src, $ver, $handle );
|
||||
|
||||
$end_cond = '';
|
||||
if ( isset($this->registered[$handle]->extra['conditional']) && $this->registered[$handle]->extra['conditional'] ) {
|
||||
echo "<!--[if {$this->registered[$handle]->extra['conditional']}]>\n";
|
||||
$end_cond = "<![endif]-->\n";
|
||||
}
|
||||
|
||||
$src = add_query_arg('ver', $ver, $src);
|
||||
$src = clean_url(apply_filters( 'style_loader_src', $src ));
|
||||
echo apply_filters( 'style_loader_tag', "<link rel='stylesheet' href='$href' type='text/css' media='$media' />\n", $handle );
|
||||
if ( 'rtl' === $this->text_direction && isset($this->registered[$handle]->extra['rtl']) && $this->registered[$handle]->extra['rtl'] ) {
|
||||
if ( is_bool( $this->registered[$handle]->extra['rtl'] ) )
|
||||
$rtl_href = str_replace( '.css', '-rtl.css', $href );
|
||||
else
|
||||
$rtl_href = $this->_css_href( $this->registered[$handle]->extra['rtl'], $ver, "$handle-rtl" );
|
||||
|
||||
echo "<link rel='stylesheet' href='$src' type='text/css' media='$media' />\n";
|
||||
echo apply_filters( 'style_loader_tag', "<link rel='stylesheet' href='$rtl_href' type='text/css' media='$media' />\n", $handle );
|
||||
}
|
||||
|
||||
echo $end_cond;
|
||||
|
||||
// Could do something with $this->registered[$handle]->extra here to print out extra CSS rules
|
||||
// echo "<style type='text/css'>\n";
|
||||
@ -46,4 +57,15 @@ class WP_Styles extends WP_Dependencies {
|
||||
$this->to_do = apply_filters( 'print_styles_array', $this->to_do );
|
||||
return $r;
|
||||
}
|
||||
|
||||
function _css_href( $src, $ver, $handle ) {
|
||||
if ( !preg_match('|^https?://|', $src) ) {
|
||||
$src = $this->base_url . $src;
|
||||
}
|
||||
|
||||
$src = add_query_arg('ver', $ver, $src);
|
||||
$src = apply_filters( 'style_loader_src', $src, $handle );
|
||||
return clean_url( $src );
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1131,19 +1131,7 @@ function wp_admin_css_uri( $file = 'wp-admin' ) {
|
||||
if ( defined('WP_INSTALLING') ) {
|
||||
$_file = "./$file.css";
|
||||
} else {
|
||||
if ( 'css/colors' == $file || 'css/colors-rtl' == $file ) {
|
||||
global $_wp_admin_css_colors;
|
||||
$color = get_user_option('admin_color');
|
||||
if ( empty($color) || !isset($_wp_admin_css_colors[$color]) )
|
||||
$color = 'fresh';
|
||||
$color = $_wp_admin_css_colors[$color];
|
||||
$_file = $color->url;
|
||||
$_file = ('css/colors-rtl' == $file) ? str_replace('.css','-rtl.css',$_file) : $_file;
|
||||
} elseif ( 'css/thickbox' == $file ) {
|
||||
$_file = get_option( 'siteurl' ) . "/wp-includes/js/thickbox/thickbox.css";
|
||||
} else {
|
||||
$_file = get_option( 'siteurl' ) . "/wp-admin/$file.css";
|
||||
}
|
||||
$_file = get_option( 'siteurl' ) . "/wp-admin/$file.css";
|
||||
}
|
||||
$_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file );
|
||||
|
||||
@ -1151,12 +1139,23 @@ function wp_admin_css_uri( $file = 'wp-admin' ) {
|
||||
}
|
||||
|
||||
function wp_admin_css( $file = 'wp-admin' ) {
|
||||
global $wp_styles;
|
||||
if ( !is_a($wp_styles, 'WP_Styles') )
|
||||
$wp_styles = new WP_Styles();
|
||||
|
||||
echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . wp_admin_css_uri( $file ) . "' type='text/css' />\n", $file );
|
||||
if ( 'rtl' == get_bloginfo( 'text_direction' ) ) {
|
||||
$rtl = ( 'wp-admin' == $file ) ? 'rtl' : "$file-rtl";
|
||||
echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . wp_admin_css_uri( $rtl ) . "' type='text/css' />\n", $rtl );
|
||||
$handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file;
|
||||
|
||||
if ( $wp_styles->query( $handle ) ) {
|
||||
if ( did_action( 'wp_print_styles' ) ) // we already printed the style queue. Print this one immediately
|
||||
wp_print_styles( $handle );
|
||||
else // Add to style queue
|
||||
wp_enqueue_style( $handle );
|
||||
return;
|
||||
}
|
||||
|
||||
echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . clean_url( wp_admin_css_uri( $file ) ) . "' type='text/css' />\n", $file );
|
||||
if ( 'rtl' == get_bloginfo( 'text_direction' ) )
|
||||
echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . clean_url( wp_admin_css_uri( "$file-rtl" ) ) . "' type='text/css' />\n", "$file-rtl" );
|
||||
}
|
||||
|
||||
function add_thickbox() {
|
||||
|
@ -6,7 +6,7 @@ require( ABSPATH . WPINC . '/functions.wp-scripts.php' );
|
||||
require( ABSPATH . WPINC . '/class.wp-styles.php' );
|
||||
require( ABSPATH . WPINC . '/functions.wp-styles.php' );
|
||||
|
||||
function wp_default_scripts( $scripts ) {
|
||||
function wp_default_scripts( &$scripts ) {
|
||||
$scripts->base_url = get_option( 'siteurl' );
|
||||
$scripts->default_version = get_bloginfo( 'version' );
|
||||
|
||||
@ -203,6 +203,35 @@ function wp_default_scripts( $scripts ) {
|
||||
}
|
||||
}
|
||||
|
||||
function wp_default_styles( &$styles ) {
|
||||
$styles->base_url = get_option( 'siteurl' );
|
||||
$styles->default_version = get_bloginfo( 'version' );
|
||||
$styles->text_direction = 'rtl' == get_bloginfo( 'text_direction' ) ? 'rtl' : 'ltr';
|
||||
|
||||
$rtl_styles = array( 'global', 'colors', 'dashboard', 'ie', 'install', 'login', 'media', 'theme-editor', 'upload', 'widgets' );
|
||||
|
||||
$styles->add( 'wp-admin', '/wp-admin/wp-admin.css' );
|
||||
$styles->add_data( 'wp-admin', 'rtl', '/wp-admin/rtl.css' );
|
||||
|
||||
$styles->add( 'ie', '/wp-admin/css/ie.css' );
|
||||
$styles->add_data( 'ie', 'conditional', 'gte IE 6' );
|
||||
|
||||
$styles->add( 'colors', true ); // Register "meta" stylesheet for admin colors
|
||||
|
||||
$styles->add( 'global', '/wp-admin/css/global.css' );
|
||||
$styles->add( 'media', '/wp-admin/css/media.css' );
|
||||
$styles->add( 'widgets', '/wp-admin/css/widgets.css' );
|
||||
$styles->add( 'dashboard', '/wp-admin/css/dashboard.css' );
|
||||
$styles->add( 'install', '/wp-admin/css/install.css' );
|
||||
$styles->add( 'theme-editor', '/wp-admin/css/theme-editor.css' );
|
||||
$styles->add( 'press-this', '/wp-admin/css/press-this.css' );
|
||||
$styles->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.css' );
|
||||
$styles->add( 'login', '/wp-admin/css/login.css' );
|
||||
|
||||
foreach ( $rtl_styles as $rtl_style )
|
||||
$styles->add_data( $rtl_style, 'rtl', true );
|
||||
}
|
||||
|
||||
function wp_prototype_before_jquery( $js_array ) {
|
||||
if ( false === $jquery = array_search( 'jquery', $js_array ) )
|
||||
return $js_array;
|
||||
@ -232,6 +261,31 @@ function wp_just_in_time_script_localization() {
|
||||
) );
|
||||
}
|
||||
|
||||
function wp_style_loader_src( $src, $handle ) {
|
||||
if ( defined('WP_INSTALLING') )
|
||||
return preg_replace( '#^wp-admin/#', './', $src );
|
||||
|
||||
if ( 'colors' == $handle || 'colors-rtl' == $handle ) {
|
||||
global $_wp_admin_css_colors;
|
||||
$color = get_user_option('admin_color');
|
||||
if ( empty($color) || !isset($_wp_admin_css_colors[$color]) )
|
||||
$color = 'fresh';
|
||||
$color = $_wp_admin_css_colors[$color];
|
||||
$parsed = parse_url( $src );
|
||||
$url = $color->url;
|
||||
if ( isset($parsed['query']) && $parsed['query'] ) {
|
||||
wp_parse_str( $parsed['query'], $qv );
|
||||
$url = add_query_arg( $qv, $url );
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
return $src;
|
||||
}
|
||||
|
||||
add_action( 'wp_default_scripts', 'wp_default_scripts' );
|
||||
add_filter( 'wp_print_scripts', 'wp_just_in_time_script_localization' );
|
||||
add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' );
|
||||
|
||||
add_action( 'wp_default_styles', 'wp_default_styles' );
|
||||
add_filter( 'style_loader_src', 'wp_style_loader_src', 10, 2 );
|
||||
|
Loading…
Reference in New Issue
Block a user