Skip to content
This repository
Browse code

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...
commit 6d039abdf0877be126e06d958c48f8649f502afc 1 parent 48bc924
Justin Tadlock authored

Showing 1 changed file with 13 additions and 3 deletions. Show diff stats Hide diff stats

  1. +13 3 extensions/random-custom-background.php
16 extensions/random-custom-background.php
@@ -153,10 +153,20 @@ public function generate_random_background() {
153 153 /* Set the backgrounds to the $backgrounds variable. */
154 154 $backgrounds = $supports[0];
155 155
  156 + /* Count the number of backgrounds. */
  157 + $count = count( $backgrounds );
  158 +
156 159 /* Generate a random background from the given set of backgrounds. */
157   - srand( (double) microtime() * 1000000 );
158   - $random = rand( 0, count( $backgrounds ) - 1 );
159   - $args = $backgrounds[$random];
  160 + if ( 1 < $count ) {
  161 + srand( (double) microtime() * 1000000 );
  162 + $random = rand( 0, $count - 1 );
  163 + $args = $backgrounds[$random];
  164 + }
  165 +
  166 + /* Get the background arguments if there's just one background. */
  167 + else {
  168 + $args = $backgrounds[0];
  169 + }
160 170
161 171 /* Set the background properties. */
162 172 $this->image = !empty( $args['image'] ) ? $args['image'] : $this->image;

0 comments on commit 6d039ab

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