Permalink
Browse files

Allow for a single background. This could be useful for conditional b…

…ackgrounds. For example, one could have a single background for just Christmas or Thanksgiving day.
  • Loading branch information...
1 parent 48bc924 commit 6d039abdf0877be126e06d958c48f8649f502afc @justintadlock committed Sep 5, 2012
Showing with 13 additions and 3 deletions.
  1. +13 −3 extensions/random-custom-background.php
@@ -153,10 +153,20 @@ public function generate_random_background() {
/* Set the backgrounds to the $backgrounds variable. */
$backgrounds = $supports[0];
+ /* Count the number of backgrounds. */
+ $count = count( $backgrounds );
+
/* Generate a random background from the given set of backgrounds. */
- srand( (double) microtime() * 1000000 );
- $random = rand( 0, count( $backgrounds ) - 1 );
- $args = $backgrounds[$random];
+ if ( 1 < $count ) {
+ srand( (double) microtime() * 1000000 );
+ $random = rand( 0, $count - 1 );
+ $args = $backgrounds[$random];
+ }
+
+ /* Get the background arguments if there's just one background. */
+ else {
+ $args = $backgrounds[0];
+ }
/* Set the background properties. */
$this->image = !empty( $args['image'] ) ? $args['image'] : $this->image;

0 comments on commit 6d039ab

Please sign in to comment.