Skip to content
This repository
Browse code

Add basic support for core custom background feature providing fallba…

…cks for WordPress 3.3. Fixes #29
  • Loading branch information...
commit c2dca5db278753df7d12b4161343675321e7f081 1 parent 0ab04e6
Michael Fields authored February 02, 2013

Showing 1 changed file with 31 additions and 0 deletions. Show diff stats Hide diff stats

  1. 31  functions.php
31  functions.php
@@ -80,6 +80,37 @@ function _s_setup() {
80 80
 add_action( 'after_setup_theme', '_s_setup' );
81 81
 
82 82
 /**
  83
+ * Setup the WordPress core custom background feature.
  84
+ *
  85
+ * Use add_theme_support to register support for WordPress 3.4+
  86
+ * as well as provide backward compatibility for WordPress 3.3
  87
+ * using feature detection of wp_get_theme() which was introduced
  88
+ * in WordPress 3.4.
  89
+ *
  90
+ * @todo Remove the 3.3 support when WordPress 3.6 is released.
  91
+ *
  92
+ * Hooks into the after_setup_theme action.
  93
+ */
  94
+function _s_register_custom_background() {
  95
+	$args = array(
  96
+		'default-color' => 'ffffff',
  97
+		'default-image' => '',
  98
+	);
  99
+
  100
+	$args = apply_filters( '_s_custom_background_args', $args );
  101
+
  102
+	if ( function_exists( 'wp_get_theme' ) ) {
  103
+		add_theme_support( 'custom-background', $args );
  104
+	} else {
  105
+		define( 'BACKGROUND_COLOR', $args['default-color'] );
  106
+		if ( ! empty( $args['default-image'] ) )
  107
+			define( 'BACKGROUND_IMAGE', $args['default-image'] );
  108
+		add_custom_background();
  109
+	}
  110
+}
  111
+add_action( 'after_setup_theme', '_s_register_custom_background' );
  112
+
  113
+/**
83 114
  * Register widgetized area and update sidebar with default widgets
84 115
  *
85 116
  * @since _s 1.0

2 notes on commit c2dca5d

djp424

A great feature to add, looking forward to putting it to use in my new themes!

Michael Fields

Yay!

Please sign in to comment.
Something went wrong with that request. Please try again.