Make WordPress Core

Changeset 13041


Ignore:
Timestamp:
02/09/2010 08:37:12 PM (15 years ago)
Author:
ryan
Message:

First pass at custom background support. Needs UI love. see #12186

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-content/themes/twentyten/functions.php

    r13029 r13041  
    2929// and thus ends the changeable header business
    3030
     31add_custom_background();
    3132
    3233// This theme needs post thumbnails
  • trunk/wp-includes/theme.php

    r13032 r13041  
    13361336
    13371337/**
     1338 * Retrieve background image for custom background.
     1339 *
     1340 * @since 3.0.0
     1341 *
     1342 * @return string
     1343 */
     1344function get_background_image() {
     1345    $default =  defined('BACKGROUND_IMAGE') ? BACKGROUND_IMAGE : '';
     1346
     1347    return get_theme_mod('background_image', $default);
     1348}
     1349
     1350/**
     1351 * Display background image path.
     1352 *
     1353 * @since 3.0.0
     1354 */
     1355function background_image() {
     1356    echo get_background_image();
     1357}
     1358
     1359/**
     1360 * Add callbacks for background image display.
     1361 *
     1362 * The parameter $header_callback callback will be required to display the
     1363 * content for the 'wp_head' action. The parameter $admin_header_callback
     1364 * callback will be added to Custom_Background class and that will be added
     1365 * to the 'admin_menu' action.
     1366 *
     1367 * @since 3.0.0
     1368 * @uses Custom_Background Sets up for $admin_header_callback for administration panel display.
     1369 *
     1370 * @param callback $header_callback Call on 'wp_head' action.
     1371 * @param callback $admin_header_callback Call on custom background administration screen.
     1372 * @param callback $admin_image_div_callback Output a custom background image div on the custom background administration screen. Optional.
     1373 */
     1374function add_custom_background($header_callback = '', $admin_header_callback = '', $admin_image_div_callback = '') {
     1375    if ( empty($header_callback) )
     1376        $header_callback = '_custom_background_cb';
     1377
     1378    add_action('wp_head', $header_callback);
     1379
     1380    if ( ! is_admin() )
     1381        return;
     1382    require_once(ABSPATH . 'wp-admin/custom-background.php');
     1383    $GLOBALS['custom_background'] =& new Custom_Background($admin_header_callback, $admin_image_div_callback);
     1384    add_action('admin_menu', array(&$GLOBALS['custom_background'], 'init'));
     1385}
     1386
     1387/**
     1388 * Default custom background callback.
     1389 *
     1390 * @since 3.0.0
     1391 * @see add_custom_background()
     1392 * @access protected
     1393 */
     1394function _custom_background_cb() {
     1395    $background = get_background_image();
     1396
     1397    if ( !$background )
     1398        return;
     1399
     1400    $repeat = get_theme_mod('background_repeat');
     1401    $repeat = $repeat ? '' : ' no-repeat';
     1402?>
     1403<style type="text/css">
     1404body {
     1405    background: url('<?php background_image(); ?>') fixed <?php echo $repeat ?>;
     1406}
     1407</style>
     1408<?php
     1409}
     1410
     1411/**
    13381412 * Allows a theme to register its support of a certain feature
    13391413 *
Note: See TracChangeset for help on using the changeset viewer.