Make WordPress Core

Ticket #17240: 17240-random-image.diff

File 17240-random-image.diff, 2.9 KB (added by lancewillett, 14 years ago)
  • wp-includes/theme.php

     
    14301430
    14311431        $url = get_theme_mod( 'header_image', $default );
    14321432
     1433        // If random option is on, choose one from registered images
     1434        if ( 'random-image' == $url ) {
     1435                global $_wp_default_headers;
     1436                if ( !isset( $_wp_default_headers ) || empty( $_wp_default_headers ) )
     1437                        return;
     1438                if ( 0 < count( $_wp_default_headers ) ) {
     1439                        $random_image = array_rand( $_wp_default_headers );
     1440                        $url = sprintf( $_wp_default_headers[$random_image]['url'], get_template_directory_uri(), get_stylesheet_directory_uri() );
     1441                }
     1442        }
     1443
    14331444        if ( is_ssl() )
    14341445                $url = str_replace( 'http://', 'https://', $url );
    14351446        else
  • wp-admin/custom-header.php

     
    199199                        }
    200200                }
    201201
    202                 if ( isset($_POST['default-header']) ) {
     202                if ( isset( $_POST['default-header'] ) ) {
    203203                        check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
    204204                        $this->process_default_headers();
    205                         if ( isset($this->default_headers[$_POST['default-header']]) )
    206                                 set_theme_mod('header_image', esc_url($this->default_headers[$_POST['default-header']]['url']));
     205                        if ( 'random-image' == $_POST['default-header'] )
     206                                set_theme_mod( 'header_image', 'random-image' );
     207                        if ( isset( $this->default_headers[$_POST['default-header']] ) )
     208                                set_theme_mod( 'header_image', esc_url( $this->default_headers[$_POST['default-header']]['url'] ) );
    207209                }
    208210        }
    209211
     
    240242                        $header_url = $header['url'];
    241243                        $header_desc = $header['description'];
    242244                        echo '<div class="default-header">';
    243                         echo '<label><input name="default-header" type="radio" value="' . esc_attr($header_key) . '" ' . checked($header_url, get_theme_mod( 'header_image' ), false) . ' />';
    244                         echo '<img src="' . $header_thumbnail . '" alt="' . esc_attr($header_desc) .'" title="' . esc_attr($header_desc) .'" /></label>';
     245                        echo '<label><input name="default-header" type="radio" value="' . esc_attr( $header_key ) . '" ' . checked( $header_url, get_theme_mod( 'header_image' ), false ) . ' />';
     246                        echo '<img src="' . $header_thumbnail . '" alt="' . esc_attr( $header_desc ) .'" title="' . esc_attr( $header_desc ) .'" /></label>';
    245247                        echo '</div>';
    246248                }
     249                // Show random image option
     250                if ( 0 < count( $this->default_headers ) ) {
     251                        echo '<div class="default-header">';
     252                        echo '<label><input name="default-header" type="radio" value="random-image"' . checked( 'random-image', get_theme_mod( 'header_image' ), false ) . ' />';
     253                        echo __( '<strong>Random:</strong> Show a different image on each page.' );
     254                        echo '</label>';
     255                        echo '</div>';
     256                }
    247257                echo '<div class="clear"></div></div>';
    248258        }
    249259