Ticket #6380: 6380-style.diff

File 6380-style.diff, 2.2 KB (added by andy, 5 years ago)
Line 
1Index: wp-includes/media.php
2===================================================================
3--- wp-includes/media.php       (revision 7557)
4+++ wp-includes/media.php       (working copy)
5@@ -340,7 +340,7 @@
6        if ( $output != '' )
7                return $output;
8               
9-       extract(shortcode_atts(array(
10+       extract(shortcode_atts(apply_filters('gallery_defaults', array(
11                'orderby'    => 'menu_order ASC, ID ASC',
12                'id'         => $post->ID,
13                'itemtag'    => 'dl',
14@@ -348,7 +348,7 @@
15                'captiontag' => 'dd',
16                'columns'    => 3,
17                'size'       => 'thumbnail',
18-       ), $attr));
19+       )), $attr));
20 
21        $id = intval($id);
22        $orderby = addslashes($orderby);
23@@ -369,30 +369,14 @@
24        $captiontag = tag_escape($captiontag);
25        $columns = intval($columns);
26        $itemwidth = $columns > 0 ? floor(100/$columns) : 100;
27-       
28-       $output = apply_filters('gallery_style', "
29-               <style type='text/css'>
30-                       .gallery {
31-                               margin: auto;
32-                       }
33-                       .gallery-item {
34-                               float: left;
35-                               margin-top: 10px;
36-                               text-align: center;
37-                               width: {$itemwidth}%;                   }
38-                       .gallery img {
39-                               border: 2px solid #cfcfcf;
40-                       }
41-                       .gallery-caption {
42-                               margin-left: 0;
43-                       }
44-               </style>
45+
46+       $output = "
47                <!-- see gallery_shortcode() in wp-includes/media.php -->
48-               <div class='gallery'>");
49+               <div class='gallery'>";
50 
51        foreach ( $attachments as $id => $attachment ) {
52                $link = wp_get_attachment_link($id, $size, true);
53-               $output .= "<{$itemtag} class='gallery-item'>";
54+               $output .= "<{$itemtag} class='gallery-item' style='width:{$itemwidth}%'>";
55                $output .= "
56                        <{$icontag} class='gallery-icon'>
57                                $link
58@@ -415,6 +399,45 @@
59        return $output;
60 }
61 
62+function gallery_style() {
63+?>
64+
65+<style type='text/css'>
66+       .gallery {
67+               margin: auto;
68+       }
69+       .gallery-item {
70+               float: left;
71+               margin-top: 10px;
72+               text-align: center;
73+       }
74+       .gallery img {
75+               border: 2px solid #cfcfcf;
76+       }
77+       .gallery-caption {
78+               margin-left: 0;
79+       }
80+</style>
81+
82+<?php
83+}
84+
85+function gallery_scan() {
86+       global $posts;
87+
88+       if ( !is_array($posts) )
89+               return;
90+
91+       foreach ( $posts as $post ) {
92+               if ( false !== strpos($post->post_content, '[gallery') ) {
93+                       add_action('wp_head', 'gallery_style');
94+                       break;
95+               }
96+       }
97+}
98+
99+add_action('template_redirect', 'gallery_scan');
100+
101 function previous_image_link() {
102        adjacent_image_link(true);
103 }