Ticket #18599: 18599.patch

File 18599.patch, 4.7 KB (added by Viper007Bond, 21 months ago)

Introduces new Screenshot URI attribute while maintaining backwards compatibility

  • wp-admin/includes/class-wp-themes-list-table.php

     
    149149        $version = $themes[$theme_name]['Version']; 
    150150        $description = $themes[$theme_name]['Description']; 
    151151        $author = $themes[$theme_name]['Author']; 
    152         $screenshot = $themes[$theme_name]['Screenshot']; 
     152        $screenshot_uri = $themes[$theme_name]['Screenshot URI']; 
    153153        $stylesheet_dir = $themes[$theme_name]['Stylesheet Dir']; 
    154154        $template_dir = $themes[$theme_name]['Template Dir']; 
    155155        $parent_theme = $themes[$theme_name]['Parent Theme']; 
     
    174174        $actions = implode ( ' | ', $actions ); 
    175175?> 
    176176                <a href="<?php echo $preview_link; ?>" class="<?php echo $thickbox_class; ?> screenshot"> 
    177 <?php if ( $screenshot ) : ?> 
    178                         <img src="<?php echo $theme_root_uri . '/' . $stylesheet . '/' . $screenshot; ?>" alt="" /> 
     177<?php if ( $screenshot_uri ) : ?> 
     178                        <img src="<?php echo esc_url( $screenshot_uri ); ?>" alt="" /> 
    179179<?php endif; ?> 
    180180                </a> 
    181181<h3><?php 
  • wp-admin/includes/theme.php

     
    2929        $ct->stylesheet_dir = $themes[$current_theme]['Stylesheet Dir']; 
    3030        $ct->template = $themes[$current_theme]['Template']; 
    3131        $ct->stylesheet = $themes[$current_theme]['Stylesheet']; 
    32         $ct->screenshot = $themes[$current_theme]['Screenshot']; 
     32        $ct->screenshot = $themes[$current_theme]['Screenshot']; // Deprecated 
     33        $ct->screenshot_uri = $themes[$current_theme]['Screenshot URI']; 
    3334        $ct->description = $themes[$current_theme]['Description']; 
    3435        $ct->author = $themes[$current_theme]['Author']; 
    3536        $ct->tags = $themes[$current_theme]['Tags']; 
  • wp-admin/themes.php

     
    8080 
    8181<h3><?php _e('Current Theme'); ?></h3> 
    8282<div id="current-theme"> 
    83 <?php if ( $ct->screenshot ) : ?> 
    84 <img src="<?php echo $ct->theme_root_uri . '/' . $ct->stylesheet . '/' . $ct->screenshot; ?>" alt="<?php _e('Current theme preview'); ?>" /> 
     83<?php if ( $ct->screenshot_uri ) : ?> 
     84<img src="<?php echo esc_url( $ct->screenshot_uri ); ?>" alt="<?php _e('Current theme preview'); ?>" /> 
    8585<?php endif; ?> 
    8686<h4><?php 
    8787        /* translators: 1: theme title, 2: theme version, 3: theme author */ 
  • wp-includes/theme.php

     
    293293                $template    = $theme_data['Template']; 
    294294                $stylesheet  = dirname($theme_file); 
    295295 
    296                 $screenshot = false; 
    297                 foreach ( array('png', 'gif', 'jpg', 'jpeg') as $ext ) { 
    298                         if (file_exists("$theme_root/$stylesheet/screenshot.$ext")) { 
    299                                 $screenshot = "screenshot.$ext"; 
    300                                 break; 
    301                         } 
    302                 } 
    303  
    304296                if ( empty($name) ) { 
    305297                        $name = dirname($theme_file); 
    306298                        $title = $name; 
     
    417409                        } 
    418410                } 
    419411 
     412                list( $screenshot, $screenshot_uri ) = get_theme_screenshot( $stylesheet_dir, $template_dir ); 
     413 
    420414                $theme_roots[$stylesheet] = str_replace( WP_CONTENT_DIR, '', $theme_root ); 
    421415                $wp_themes[$name] = array( 
    422416                        'Name' => $name, 
     
    434428                        'Stylesheet Dir' => $stylesheet_dir, 
    435429                        'Status' => $theme_data['Status'], 
    436430                        'Screenshot' => $screenshot, 
     431                        'Screenshot URI' => $screenshot_uri, 
    437432                        'Tags' => $theme_data['Tags'], 
    438433                        'Theme Root' => $theme_root, 
    439434                        'Theme Root URI' => str_replace( WP_CONTENT_DIR, content_url(), $theme_root ), 
     
    465460} 
    466461 
    467462/** 
     463 * Get a theme's screenshot filename and URI. Checks parent too for child themes. 
     464 * 
     465 * @since 3.3.0 
     466 * 
     467 */ 
     468function get_theme_screenshot( $stylesheet_dir, $template_dir = null ) { 
     469        $extensions = array( 'png', 'gif', 'jpg', 'jpeg' ); 
     470 
     471        $screenshot = $screenshot_uri = false; 
     472 
     473        // Check current theme folder 
     474        foreach ( $extensions as $ext ) { 
     475                $check_path = "$stylesheet_dir/screenshot.$ext"; 
     476                if ( file_exists( $check_path ) ) { 
     477                        return array( 
     478                                "screenshot.$ext", 
     479                                str_replace( WP_CONTENT_DIR, content_url(), $check_path ), 
     480                        ); 
     481                } 
     482        } 
     483 
     484        // Okay, maybe the parent folder has a screenshot 
     485        if ( $template_dir && $template_dir != $stylesheet_dir ) { 
     486                foreach ( $extensions as $ext ) { 
     487                        $check_path = "$template_dir/screenshot.$ext"; 
     488                        if ( file_exists( $check_path ) ) { 
     489                                return array( 
     490                                        false, 
     491                                        str_replace( WP_CONTENT_DIR, content_url(), $check_path ), 
     492                                ); 
     493                        } 
     494                } 
     495        } 
     496 
     497        return array( false, false ); 
     498} 
     499 
     500/** 
    468501 * Retrieve theme roots. 
    469502 * 
    470503 * @since 2.9.0