Make WordPress Core


Ignore:
Timestamp:
03/29/2014 10:52:17 AM (12 years ago)
Author:
nacin
Message:

Custom Headers: Simplify and consolidate the querying of custom headers for the customizer.

props mcsf.
see #21785.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/custom-header.php

    r27497 r27849  
    4141     * @access private
    4242     */
    43     var $default_headers = array();
     43    var $default_headers;
    4444
    4545    /**
     
    255255            return;
    256256
     257        if ( is_array( $this->default_headers ) ) {
     258            return;
     259        }
     260
    257261        $this->default_headers = $_wp_default_headers;
    258262        $template_directory_uri = get_template_directory_uri();
     
    262266            $this->default_headers[$header]['thumbnail_url'] =  sprintf( $this->default_headers[$header]['thumbnail_url'], $template_directory_uri, $stylesheet_directory_uri );
    263267        }
    264 
    265268    }
    266269
     
    12291232        update_post_meta( $attachment_id, $key, time() );
    12301233    }
     1234
     1235    public function get_default_header_images() {
     1236        $this->process_default_headers();
     1237
     1238        // Get the default image if there is one.
     1239        $default = get_theme_support( 'custom-header', 'default-image' );
     1240
     1241        if ( ! $default ) { // If not,
     1242            return $this->default_headers; // easy peasy.
     1243        }
     1244
     1245        $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() );
     1246        $already_has_default = false;
     1247
     1248        foreach ( $this->default_headers as $k => $h ) {
     1249            if ( $h['url'] === $default ) {
     1250                $already_has_default = true;
     1251                break;
     1252            }
     1253        }
     1254
     1255        if ( $already_has_default ) {
     1256            return $this->default_headers;
     1257        }
     1258
     1259        // If the one true image isn't included in the default set, prepend it.
     1260        $header_images = array();
     1261        $header_images['default'] = array(
     1262            'url'           => $default,
     1263            'thumbnail_url' => $default,
     1264            'description'   => 'Default'
     1265        );
     1266
     1267        // The rest of the set comes after.
     1268        $header_images = array_merge( $header_images, $this->default_headers );
     1269        return $header_images;
     1270    }
     1271
     1272    public function get_uploaded_header_images() {
     1273        $header_images = get_uploaded_header_images();
     1274        $timestamp_key = '_wp_attachment_custom_header_last_used_' . get_stylesheet();
     1275
     1276        foreach ( $header_images as &$header_image ) {
     1277            $header_image['timestamp'] = get_post_meta( $header_image['attachment_id'], $timestamp_key, true );
     1278        }
     1279
     1280        return $header_images;
     1281    }
    12311282}
Note: See TracChangeset for help on using the changeset viewer.