Skip to:
Content

BuddyPress.org

Changeset 3589


Ignore:
Timestamp:
12/27/2010 06:01:55 PM (14 years ago)
Author:
djpaul
Message:

Ensure custom background colour overrides default background image if no custom background image is set. Fixes #2971

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-themes/bp-default/functions.php

    r3588 r3589  
    6060
    6161    // This theme allows users to set a custom background
    62     add_custom_background();
     62    add_custom_background( 'bp_dtheme_custom_background_style' );
    6363
    6464    // Changeable header section starts here
     
    197197endif;
    198198
     199if ( !function_exists( 'bp_dtheme_custom_background_style' ) ) :
     200/**
     201 * The style for the custom background image or colour.
     202 *
     203 * Referenced via add_custom_background() in bp_dtheme_setup().
     204 *
     205 * @see _custom_background_cb()
     206 * @since 1.3
     207 */
     208function bp_dtheme_custom_background_style() {
     209    $background = get_background_image();
     210    $color = get_background_color();
     211    if ( ! $background && ! $color )
     212        return;
     213
     214    $style = $color ? "background-color: #$color;" : '';
     215
     216    if ( $style && !$background ) {
     217        $style .= ' background-image: none;';
     218
     219    } elseif ( $background ) {
     220        $image = " background-image: url('$background');";
     221
     222        $repeat = get_theme_mod( 'background_repeat', 'repeat' );
     223        if ( ! in_array( $repeat, array( 'no-repeat', 'repeat-x', 'repeat-y', 'repeat' ) ) )
     224            $repeat = 'repeat';
     225        $repeat = " background-repeat: $repeat;";
     226
     227        $position = get_theme_mod( 'background_position_x', 'left' );
     228        if ( ! in_array( $position, array( 'center', 'right', 'left' ) ) )
     229            $position = 'left';
     230        $position = " background-position: top $position;";
     231
     232        $attachment = get_theme_mod( 'background_attachment', 'scroll' );
     233        if ( ! in_array( $attachment, array( 'fixed', 'scroll' ) ) )
     234            $attachment = 'scroll';
     235        $attachment = " background-attachment: $attachment;";
     236
     237        $style .= $image . $repeat . $position . $attachment;
     238    }
     239?>
     240    <style type="text/css">
     241        body { <?php echo trim( $style ); ?> }
     242    </style>
     243<?php
     244}
     245endif;
     246
    199247if ( !function_exists( 'bp_dtheme_header_style' ) ) :
    200248/**
Note: See TracChangeset for help on using the changeset viewer.