author | Anthony Ly <anthonyly.com@gmail.com> |
Wed, 19 Dec 2012 17:46:52 -0800 | |
changeset 204 | 09a1c134465b |
parent 194 | 32102edaa81b |
permissions | -rw-r--r-- |
136 | 1 |
<?php |
2 |
/** |
|
3 |
* WordPress API for media display. |
|
4 |
* |
|
5 |
* @package WordPress |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
6 |
* @subpackage Media |
136 | 7 |
*/ |
8 |
||
9 |
/** |
|
10 |
* Scale down the default size of an image. |
|
11 |
* |
|
12 |
* This is so that the image is a better fit for the editor and theme. |
|
13 |
* |
|
14 |
* The $size parameter accepts either an array or a string. The supported string |
|
15 |
* values are 'thumb' or 'thumbnail' for the given thumbnail size or defaults at |
|
16 |
* 128 width and 96 height in pixels. Also supported for the string value is |
|
17 |
* 'medium' and 'full'. The 'full' isn't actually supported, but any value other |
|
18 |
* than the supported will result in the content_width size or 500 if that is |
|
19 |
* not set. |
|
20 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
21 |
* Finally, there is a filter named 'editor_max_image_size', that will be called |
136 | 22 |
* on the calculated array for width and height, respectively. The second |
23 |
* parameter will be the value that was in the $size parameter. The returned |
|
24 |
* type for the hook is an array with the width as the first element and the |
|
25 |
* height as the second element. |
|
26 |
* |
|
27 |
* @since 2.5.0 |
|
28 |
* @uses wp_constrain_dimensions() This function passes the widths and the heights. |
|
29 |
* |
|
30 |
* @param int $width Width of the image |
|
31 |
* @param int $height Height of the image |
|
32 |
* @param string|array $size Size of what the result image should be. |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
33 |
* @param context Could be 'display' (like in a theme) or 'edit' (like inserting into an editor) |
136 | 34 |
* @return array Width and height of what the result image should resize to. |
35 |
*/ |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
36 |
function image_constrain_size_for_editor($width, $height, $size = 'medium', $context = null ) { |
136 | 37 |
global $content_width, $_wp_additional_image_sizes; |
38 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
39 |
if ( ! $context ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
40 |
$context = is_admin() ? 'edit' : 'display'; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
41 |
|
136 | 42 |
if ( is_array($size) ) { |
43 |
$max_width = $size[0]; |
|
44 |
$max_height = $size[1]; |
|
45 |
} |
|
46 |
elseif ( $size == 'thumb' || $size == 'thumbnail' ) { |
|
47 |
$max_width = intval(get_option('thumbnail_size_w')); |
|
48 |
$max_height = intval(get_option('thumbnail_size_h')); |
|
49 |
// last chance thumbnail size defaults |
|
50 |
if ( !$max_width && !$max_height ) { |
|
51 |
$max_width = 128; |
|
52 |
$max_height = 96; |
|
53 |
} |
|
54 |
} |
|
55 |
elseif ( $size == 'medium' ) { |
|
56 |
$max_width = intval(get_option('medium_size_w')); |
|
57 |
$max_height = intval(get_option('medium_size_h')); |
|
58 |
// if no width is set, default to the theme content width if available |
|
59 |
} |
|
60 |
elseif ( $size == 'large' ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
61 |
// We're inserting a large size image into the editor. If it's a really |
136 | 62 |
// big image we'll scale it down to fit reasonably within the editor |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
63 |
// itself, and within the theme's content width if it's known. The user |
136 | 64 |
// can resize it in the editor if they wish. |
65 |
$max_width = intval(get_option('large_size_w')); |
|
66 |
$max_height = intval(get_option('large_size_h')); |
|
67 |
if ( intval($content_width) > 0 ) |
|
68 |
$max_width = min( intval($content_width), $max_width ); |
|
69 |
} elseif ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ) ) ) { |
|
70 |
$max_width = intval( $_wp_additional_image_sizes[$size]['width'] ); |
|
71 |
$max_height = intval( $_wp_additional_image_sizes[$size]['height'] ); |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
72 |
if ( intval($content_width) > 0 && 'edit' == $context ) // Only in admin. Assume that theme authors know what they're doing. |
136 | 73 |
$max_width = min( intval($content_width), $max_width ); |
74 |
} |
|
75 |
// $size == 'full' has no constraint |
|
76 |
else { |
|
77 |
$max_width = $width; |
|
78 |
$max_height = $height; |
|
79 |
} |
|
80 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
81 |
list( $max_width, $max_height ) = apply_filters( 'editor_max_image_size', array( $max_width, $max_height ), $size, $context ); |
136 | 82 |
|
83 |
return wp_constrain_dimensions( $width, $height, $max_width, $max_height ); |
|
84 |
} |
|
85 |
||
86 |
/** |
|
87 |
* Retrieve width and height attributes using given width and height values. |
|
88 |
* |
|
89 |
* Both attributes are required in the sense that both parameters must have a |
|
90 |
* value, but are optional in that if you set them to false or null, then they |
|
91 |
* will not be added to the returned string. |
|
92 |
* |
|
93 |
* You can set the value using a string, but it will only take numeric values. |
|
94 |
* If you wish to put 'px' after the numbers, then it will be stripped out of |
|
95 |
* the return. |
|
96 |
* |
|
97 |
* @since 2.5.0 |
|
98 |
* |
|
99 |
* @param int|string $width Optional. Width attribute value. |
|
100 |
* @param int|string $height Optional. Height attribute value. |
|
101 |
* @return string HTML attributes for width and, or height. |
|
102 |
*/ |
|
103 |
function image_hwstring($width, $height) { |
|
104 |
$out = ''; |
|
105 |
if ($width) |
|
106 |
$out .= 'width="'.intval($width).'" '; |
|
107 |
if ($height) |
|
108 |
$out .= 'height="'.intval($height).'" '; |
|
109 |
return $out; |
|
110 |
} |
|
111 |
||
112 |
/** |
|
113 |
* Scale an image to fit a particular size (such as 'thumb' or 'medium'). |
|
114 |
* |
|
115 |
* Array with image url, width, height, and whether is intermediate size, in |
|
116 |
* that order is returned on success is returned. $is_intermediate is true if |
|
117 |
* $url is a resized image, false if it is the original. |
|
118 |
* |
|
119 |
* The URL might be the original image, or it might be a resized version. This |
|
120 |
* function won't create a new resized copy, it will just return an already |
|
121 |
* resized one if it exists. |
|
122 |
* |
|
123 |
* A plugin may use the 'image_downsize' filter to hook into and offer image |
|
124 |
* resizing services for images. The hook must return an array with the same |
|
125 |
* elements that are returned in the function. The first element being the URL |
|
126 |
* to the new image that was resized. |
|
127 |
* |
|
128 |
* @since 2.5.0 |
|
129 |
* @uses apply_filters() Calls 'image_downsize' on $id and $size to provide |
|
130 |
* resize services. |
|
131 |
* |
|
132 |
* @param int $id Attachment ID for image. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
133 |
* @param array|string $size Optional, default is 'medium'. Size of image, either array or string. |
136 | 134 |
* @return bool|array False on failure, array on success. |
135 |
*/ |
|
136 |
function image_downsize($id, $size = 'medium') { |
|
137 |
||
138 |
if ( !wp_attachment_is_image($id) ) |
|
139 |
return false; |
|
140 |
||
141 |
$img_url = wp_get_attachment_url($id); |
|
142 |
$meta = wp_get_attachment_metadata($id); |
|
143 |
$width = $height = 0; |
|
144 |
$is_intermediate = false; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
145 |
$img_url_basename = wp_basename($img_url); |
136 | 146 |
|
147 |
// plugins can use this to provide resize services |
|
148 |
if ( $out = apply_filters('image_downsize', false, $id, $size) ) |
|
149 |
return $out; |
|
150 |
||
151 |
// try for a new style intermediate size |
|
152 |
if ( $intermediate = image_get_intermediate_size($id, $size) ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
153 |
$img_url = str_replace($img_url_basename, $intermediate['file'], $img_url); |
136 | 154 |
$width = $intermediate['width']; |
155 |
$height = $intermediate['height']; |
|
156 |
$is_intermediate = true; |
|
157 |
} |
|
158 |
elseif ( $size == 'thumbnail' ) { |
|
159 |
// fall back to the old thumbnail |
|
160 |
if ( ($thumb_file = wp_get_attachment_thumb_file($id)) && $info = getimagesize($thumb_file) ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
161 |
$img_url = str_replace($img_url_basename, wp_basename($thumb_file), $img_url); |
136 | 162 |
$width = $info[0]; |
163 |
$height = $info[1]; |
|
164 |
$is_intermediate = true; |
|
165 |
} |
|
166 |
} |
|
167 |
if ( !$width && !$height && isset($meta['width'], $meta['height']) ) { |
|
168 |
// any other type: use the real image |
|
169 |
$width = $meta['width']; |
|
170 |
$height = $meta['height']; |
|
171 |
} |
|
172 |
||
173 |
if ( $img_url) { |
|
174 |
// we have the actual image size, but might need to further constrain it if content_width is narrower |
|
175 |
list( $width, $height ) = image_constrain_size_for_editor( $width, $height, $size ); |
|
176 |
||
177 |
return array( $img_url, $width, $height, $is_intermediate ); |
|
178 |
} |
|
179 |
return false; |
|
180 |
||
181 |
} |
|
182 |
||
183 |
/** |
|
184 |
* Registers a new image size |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
185 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
186 |
* @since 2.9.0 |
136 | 187 |
*/ |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
188 |
function add_image_size( $name, $width = 0, $height = 0, $crop = false ) { |
136 | 189 |
global $_wp_additional_image_sizes; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
190 |
$_wp_additional_image_sizes[$name] = array( 'width' => absint( $width ), 'height' => absint( $height ), 'crop' => (bool) $crop ); |
136 | 191 |
} |
192 |
||
193 |
/** |
|
194 |
* Registers an image size for the post thumbnail |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
195 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
196 |
* @since 2.9.0 |
136 | 197 |
*/ |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
198 |
function set_post_thumbnail_size( $width = 0, $height = 0, $crop = false ) { |
136 | 199 |
add_image_size( 'post-thumbnail', $width, $height, $crop ); |
200 |
} |
|
201 |
||
202 |
/** |
|
203 |
* An <img src /> tag for an image attachment, scaling it down if requested. |
|
204 |
* |
|
205 |
* The filter 'get_image_tag_class' allows for changing the class name for the |
|
206 |
* image without having to use regular expressions on the HTML content. The |
|
207 |
* parameters are: what WordPress will use for the class, the Attachment ID, |
|
208 |
* image align value, and the size the image should be. |
|
209 |
* |
|
210 |
* The second filter 'get_image_tag' has the HTML content, which can then be |
|
211 |
* further manipulated by a plugin to change all attribute values and even HTML |
|
212 |
* content. |
|
213 |
* |
|
214 |
* @since 2.5.0 |
|
215 |
* |
|
216 |
* @uses apply_filters() The 'get_image_tag_class' filter is the IMG element |
|
217 |
* class attribute. |
|
218 |
* @uses apply_filters() The 'get_image_tag' filter is the full IMG element with |
|
219 |
* all attributes. |
|
220 |
* |
|
221 |
* @param int $id Attachment ID. |
|
222 |
* @param string $alt Image Description for the alt attribute. |
|
223 |
* @param string $title Image Description for the title attribute. |
|
224 |
* @param string $align Part of the class name for aligning the image. |
|
225 |
* @param string $size Optional. Default is 'medium'. |
|
226 |
* @return string HTML IMG element for given image attachment |
|
227 |
*/ |
|
228 |
function get_image_tag($id, $alt, $title, $align, $size='medium') { |
|
229 |
||
230 |
list( $img_src, $width, $height ) = image_downsize($id, $size); |
|
231 |
$hwstring = image_hwstring($width, $height); |
|
232 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
233 |
$title = $title ? 'title="' . esc_attr( $title ) . '" ' : ''; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
234 |
|
136 | 235 |
$class = 'align' . esc_attr($align) .' size-' . esc_attr($size) . ' wp-image-' . $id; |
236 |
$class = apply_filters('get_image_tag_class', $class, $id, $align, $size); |
|
237 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
238 |
$html = '<img src="' . esc_attr($img_src) . '" alt="' . esc_attr($alt) . '" ' . $title . $hwstring . 'class="' . $class . '" />'; |
136 | 239 |
|
240 |
$html = apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size ); |
|
241 |
||
242 |
return $html; |
|
243 |
} |
|
244 |
||
245 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
246 |
* Calculates the new dimensions for a downsampled image. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
247 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
248 |
* If either width or height are empty, no constraint is applied on |
136 | 249 |
* that dimension. |
250 |
* |
|
251 |
* @since 2.5.0 |
|
252 |
* |
|
253 |
* @param int $current_width Current width of the image. |
|
254 |
* @param int $current_height Current height of the image. |
|
255 |
* @param int $max_width Optional. Maximum wanted width. |
|
256 |
* @param int $max_height Optional. Maximum wanted height. |
|
257 |
* @return array First item is the width, the second item is the height. |
|
258 |
*/ |
|
259 |
function wp_constrain_dimensions( $current_width, $current_height, $max_width=0, $max_height=0 ) { |
|
260 |
if ( !$max_width and !$max_height ) |
|
261 |
return array( $current_width, $current_height ); |
|
262 |
||
263 |
$width_ratio = $height_ratio = 1.0; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
264 |
$did_width = $did_height = false; |
136 | 265 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
266 |
if ( $max_width > 0 && $current_width > 0 && $current_width > $max_width ) { |
136 | 267 |
$width_ratio = $max_width / $current_width; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
268 |
$did_width = true; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
269 |
} |
136 | 270 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
271 |
if ( $max_height > 0 && $current_height > 0 && $current_height > $max_height ) { |
136 | 272 |
$height_ratio = $max_height / $current_height; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
273 |
$did_height = true; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
274 |
} |
136 | 275 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
276 |
// Calculate the larger/smaller ratios |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
277 |
$smaller_ratio = min( $width_ratio, $height_ratio ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
278 |
$larger_ratio = max( $width_ratio, $height_ratio ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
279 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
280 |
if ( intval( $current_width * $larger_ratio ) > $max_width || intval( $current_height * $larger_ratio ) > $max_height ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
281 |
// The larger ratio is too big. It would result in an overflow. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
282 |
$ratio = $smaller_ratio; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
283 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
284 |
// The larger ratio fits, and is likely to be a more "snug" fit. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
285 |
$ratio = $larger_ratio; |
136 | 286 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
287 |
$w = intval( $current_width * $ratio ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
288 |
$h = intval( $current_height * $ratio ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
289 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
290 |
// Sometimes, due to rounding, we'll end up with a result like this: 465x700 in a 177x177 box is 117x176... a pixel short |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
291 |
// We also have issues with recursive calls resulting in an ever-changing result. Constraining to the result of a constraint should yield the original result. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
292 |
// Thus we look for dimensions that are one pixel shy of the max value and bump them up |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
293 |
if ( $did_width && $w == $max_width - 1 ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
294 |
$w = $max_width; // Round it up |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
295 |
if ( $did_height && $h == $max_height - 1 ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
296 |
$h = $max_height; // Round it up |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
297 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
298 |
return array( $w, $h ); |
136 | 299 |
} |
300 |
||
301 |
/** |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
302 |
* Retrieve calculated resized dimensions for use in WP_Image_Editor. |
136 | 303 |
* |
304 |
* Calculate dimensions and coordinates for a resized image that fits within a |
|
305 |
* specified width and height. If $crop is true, the largest matching central |
|
306 |
* portion of the image will be cropped out and resized to the required size. |
|
307 |
* |
|
308 |
* @since 2.5.0 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
309 |
* @uses apply_filters() Calls 'image_resize_dimensions' on $orig_w, $orig_h, $dest_w, $dest_h and |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
310 |
* $crop to provide custom resize dimensions. |
136 | 311 |
* |
312 |
* @param int $orig_w Original width. |
|
313 |
* @param int $orig_h Original height. |
|
314 |
* @param int $dest_w New width. |
|
315 |
* @param int $dest_h New height. |
|
316 |
* @param bool $crop Optional, default is false. Whether to crop image or resize. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
317 |
* @return bool|array False on failure. Returned array matches parameters for imagecopyresampled() PHP function. |
136 | 318 |
*/ |
319 |
function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false) { |
|
320 |
||
321 |
if ($orig_w <= 0 || $orig_h <= 0) |
|
322 |
return false; |
|
323 |
// at least one of dest_w or dest_h must be specific |
|
324 |
if ($dest_w <= 0 && $dest_h <= 0) |
|
325 |
return false; |
|
326 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
327 |
// plugins can use this to provide custom resize dimensions |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
328 |
$output = apply_filters( 'image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
329 |
if ( null !== $output ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
330 |
return $output; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
331 |
|
136 | 332 |
if ( $crop ) { |
333 |
// crop the largest possible portion of the original image that we can size to $dest_w x $dest_h |
|
334 |
$aspect_ratio = $orig_w / $orig_h; |
|
335 |
$new_w = min($dest_w, $orig_w); |
|
336 |
$new_h = min($dest_h, $orig_h); |
|
337 |
||
338 |
if ( !$new_w ) { |
|
339 |
$new_w = intval($new_h * $aspect_ratio); |
|
340 |
} |
|
341 |
||
342 |
if ( !$new_h ) { |
|
343 |
$new_h = intval($new_w / $aspect_ratio); |
|
344 |
} |
|
345 |
||
346 |
$size_ratio = max($new_w / $orig_w, $new_h / $orig_h); |
|
347 |
||
348 |
$crop_w = round($new_w / $size_ratio); |
|
349 |
$crop_h = round($new_h / $size_ratio); |
|
350 |
||
351 |
$s_x = floor( ($orig_w - $crop_w) / 2 ); |
|
352 |
$s_y = floor( ($orig_h - $crop_h) / 2 ); |
|
353 |
} else { |
|
354 |
// don't crop, just resize using $dest_w x $dest_h as a maximum bounding box |
|
355 |
$crop_w = $orig_w; |
|
356 |
$crop_h = $orig_h; |
|
357 |
||
358 |
$s_x = 0; |
|
359 |
$s_y = 0; |
|
360 |
||
361 |
list( $new_w, $new_h ) = wp_constrain_dimensions( $orig_w, $orig_h, $dest_w, $dest_h ); |
|
362 |
} |
|
363 |
||
364 |
// if the resulting image would be the same size or larger we don't want to resize it |
|
365 |
if ( $new_w >= $orig_w && $new_h >= $orig_h ) |
|
366 |
return false; |
|
367 |
||
368 |
// the return array matches the parameters to imagecopyresampled() |
|
369 |
// int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h |
|
370 |
return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h ); |
|
371 |
||
372 |
} |
|
373 |
||
374 |
/** |
|
375 |
* Resize an image to make a thumbnail or intermediate size. |
|
376 |
* |
|
377 |
* The returned array has the file size, the image width, and image height. The |
|
378 |
* filter 'image_make_intermediate_size' can be used to hook in and change the |
|
379 |
* values of the returned array. The only parameter is the resized file path. |
|
380 |
* |
|
381 |
* @since 2.5.0 |
|
382 |
* |
|
383 |
* @param string $file File path. |
|
384 |
* @param int $width Image width. |
|
385 |
* @param int $height Image height. |
|
386 |
* @param bool $crop Optional, default is false. Whether to crop image to specified height and width or resize. |
|
387 |
* @return bool|array False, if no image was created. Metadata array on success. |
|
388 |
*/ |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
389 |
function image_make_intermediate_size( $file, $width, $height, $crop = false ) { |
136 | 390 |
if ( $width || $height ) { |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
391 |
$editor = wp_get_image_editor( $file ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
392 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
393 |
if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
394 |
return false; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
395 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
396 |
$resized_file = $editor->save(); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
397 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
398 |
if ( ! is_wp_error( $resized_file ) && $resized_file ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
399 |
unset( $resized_file['path'] ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
400 |
return $resized_file; |
136 | 401 |
} |
402 |
} |
|
403 |
return false; |
|
404 |
} |
|
405 |
||
406 |
/** |
|
407 |
* Retrieve the image's intermediate size (resized) path, width, and height. |
|
408 |
* |
|
409 |
* The $size parameter can be an array with the width and height respectively. |
|
410 |
* If the size matches the 'sizes' metadata array for width and height, then it |
|
411 |
* will be used. If there is no direct match, then the nearest image size larger |
|
412 |
* than the specified size will be used. If nothing is found, then the function |
|
413 |
* will break out and return false. |
|
414 |
* |
|
415 |
* The metadata 'sizes' is used for compatible sizes that can be used for the |
|
416 |
* parameter $size value. |
|
417 |
* |
|
418 |
* The url path will be given, when the $size parameter is a string. |
|
419 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
420 |
* If you are passing an array for the $size, you should consider using |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
421 |
* add_image_size() so that a cropped version is generated. It's much more |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
422 |
* efficient than having to find the closest-sized image and then having the |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
423 |
* browser scale down the image. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
424 |
* |
136 | 425 |
* @since 2.5.0 |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
426 |
* @see add_image_size() |
136 | 427 |
* |
428 |
* @param int $post_id Attachment ID for image. |
|
429 |
* @param array|string $size Optional, default is 'thumbnail'. Size of image, either array or string. |
|
430 |
* @return bool|array False on failure or array of file path, width, and height on success. |
|
431 |
*/ |
|
432 |
function image_get_intermediate_size($post_id, $size='thumbnail') { |
|
433 |
if ( !is_array( $imagedata = wp_get_attachment_metadata( $post_id ) ) ) |
|
434 |
return false; |
|
435 |
||
436 |
// get the best one for a specified set of dimensions |
|
437 |
if ( is_array($size) && !empty($imagedata['sizes']) ) { |
|
438 |
foreach ( $imagedata['sizes'] as $_size => $data ) { |
|
439 |
// already cropped to width or height; so use this size |
|
440 |
if ( ( $data['width'] == $size[0] && $data['height'] <= $size[1] ) || ( $data['height'] == $size[1] && $data['width'] <= $size[0] ) ) { |
|
441 |
$file = $data['file']; |
|
442 |
list($width, $height) = image_constrain_size_for_editor( $data['width'], $data['height'], $size ); |
|
443 |
return compact( 'file', 'width', 'height' ); |
|
444 |
} |
|
445 |
// add to lookup table: area => size |
|
446 |
$areas[$data['width'] * $data['height']] = $_size; |
|
447 |
} |
|
448 |
if ( !$size || !empty($areas) ) { |
|
449 |
// find for the smallest image not smaller than the desired size |
|
450 |
ksort($areas); |
|
451 |
foreach ( $areas as $_size ) { |
|
452 |
$data = $imagedata['sizes'][$_size]; |
|
453 |
if ( $data['width'] >= $size[0] || $data['height'] >= $size[1] ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
454 |
// Skip images with unexpectedly divergent aspect ratios (crops) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
455 |
// First, we calculate what size the original image would be if constrained to a box the size of the current image in the loop |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
456 |
$maybe_cropped = image_resize_dimensions($imagedata['width'], $imagedata['height'], $data['width'], $data['height'], false ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
457 |
// If the size doesn't match within one pixel, then it is of a different aspect ratio, so we skip it, unless it's the thumbnail size |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
458 |
if ( 'thumbnail' != $_size && ( !$maybe_cropped || ( $maybe_cropped[4] != $data['width'] && $maybe_cropped[4] + 1 != $data['width'] ) || ( $maybe_cropped[5] != $data['height'] && $maybe_cropped[5] + 1 != $data['height'] ) ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
459 |
continue; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
460 |
// If we're still here, then we're going to use this size |
136 | 461 |
$file = $data['file']; |
462 |
list($width, $height) = image_constrain_size_for_editor( $data['width'], $data['height'], $size ); |
|
463 |
return compact( 'file', 'width', 'height' ); |
|
464 |
} |
|
465 |
} |
|
466 |
} |
|
467 |
} |
|
468 |
||
469 |
if ( is_array($size) || empty($size) || empty($imagedata['sizes'][$size]) ) |
|
470 |
return false; |
|
471 |
||
472 |
$data = $imagedata['sizes'][$size]; |
|
473 |
// include the full filesystem path of the intermediate file |
|
474 |
if ( empty($data['path']) && !empty($data['file']) ) { |
|
475 |
$file_url = wp_get_attachment_url($post_id); |
|
476 |
$data['path'] = path_join( dirname($imagedata['file']), $data['file'] ); |
|
477 |
$data['url'] = path_join( dirname($file_url), $data['file'] ); |
|
478 |
} |
|
479 |
return $data; |
|
480 |
} |
|
481 |
||
482 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
483 |
* Get the available image sizes |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
484 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
485 |
* @return array Returns a filtered array of image size strings |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
486 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
487 |
function get_intermediate_image_sizes() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
488 |
global $_wp_additional_image_sizes; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
489 |
$image_sizes = array('thumbnail', 'medium', 'large'); // Standard sizes |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
490 |
if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
491 |
$image_sizes = array_merge( $image_sizes, array_keys( $_wp_additional_image_sizes ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
492 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
493 |
return apply_filters( 'intermediate_image_sizes', $image_sizes ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
494 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
495 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
496 |
/** |
136 | 497 |
* Retrieve an image to represent an attachment. |
498 |
* |
|
499 |
* A mime icon for files, thumbnail or intermediate size for images. |
|
500 |
* |
|
501 |
* @since 2.5.0 |
|
502 |
* |
|
503 |
* @param int $attachment_id Image attachment ID. |
|
504 |
* @param string $size Optional, default is 'thumbnail'. |
|
505 |
* @param bool $icon Optional, default is false. Whether it is an icon. |
|
506 |
* @return bool|array Returns an array (url, width, height), or false, if no image is available. |
|
507 |
*/ |
|
508 |
function wp_get_attachment_image_src($attachment_id, $size='thumbnail', $icon = false) { |
|
509 |
||
510 |
// get a thumbnail or intermediate image if there is one |
|
511 |
if ( $image = image_downsize($attachment_id, $size) ) |
|
512 |
return $image; |
|
513 |
||
514 |
$src = false; |
|
515 |
||
516 |
if ( $icon && $src = wp_mime_type_icon($attachment_id) ) { |
|
517 |
$icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/crystal' ); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
518 |
$src_file = $icon_dir . '/' . wp_basename($src); |
136 | 519 |
@list($width, $height) = getimagesize($src_file); |
520 |
} |
|
521 |
if ( $src && $width && $height ) |
|
522 |
return array( $src, $width, $height ); |
|
523 |
return false; |
|
524 |
} |
|
525 |
||
526 |
/** |
|
527 |
* Get an HTML img element representing an image attachment |
|
528 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
529 |
* While $size will accept an array, it is better to register a size with |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
530 |
* add_image_size() so that a cropped version is generated. It's much more |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
531 |
* efficient than having to find the closest-sized image and then having the |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
532 |
* browser scale down the image. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
533 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
534 |
* @see add_image_size() |
136 | 535 |
* @uses apply_filters() Calls 'wp_get_attachment_image_attributes' hook on attributes array |
536 |
* @uses wp_get_attachment_image_src() Gets attachment file URL and dimensions |
|
537 |
* @since 2.5.0 |
|
538 |
* |
|
539 |
* @param int $attachment_id Image attachment ID. |
|
540 |
* @param string $size Optional, default is 'thumbnail'. |
|
541 |
* @param bool $icon Optional, default is false. Whether it is an icon. |
|
542 |
* @return string HTML img element or empty string on failure. |
|
543 |
*/ |
|
544 |
function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = false, $attr = '') { |
|
545 |
||
546 |
$html = ''; |
|
547 |
$image = wp_get_attachment_image_src($attachment_id, $size, $icon); |
|
548 |
if ( $image ) { |
|
549 |
list($src, $width, $height) = $image; |
|
550 |
$hwstring = image_hwstring($width, $height); |
|
551 |
if ( is_array($size) ) |
|
552 |
$size = join('x', $size); |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
553 |
$attachment = get_post($attachment_id); |
136 | 554 |
$default_attr = array( |
555 |
'src' => $src, |
|
556 |
'class' => "attachment-$size", |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
557 |
'alt' => trim(strip_tags( get_post_meta($attachment_id, '_wp_attachment_image_alt', true) )), // Use Alt field first |
136 | 558 |
); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
559 |
if ( empty($default_attr['alt']) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
560 |
$default_attr['alt'] = trim(strip_tags( $attachment->post_excerpt )); // If not, Use the Caption |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
561 |
if ( empty($default_attr['alt']) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
562 |
$default_attr['alt'] = trim(strip_tags( $attachment->post_title )); // Finally, use the title |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
563 |
|
136 | 564 |
$attr = wp_parse_args($attr, $default_attr); |
565 |
$attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment ); |
|
566 |
$attr = array_map( 'esc_attr', $attr ); |
|
567 |
$html = rtrim("<img $hwstring"); |
|
568 |
foreach ( $attr as $name => $value ) { |
|
569 |
$html .= " $name=" . '"' . $value . '"'; |
|
570 |
} |
|
571 |
$html .= ' />'; |
|
572 |
} |
|
573 |
||
574 |
return $html; |
|
575 |
} |
|
576 |
||
577 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
578 |
* Adds a 'wp-post-image' class to post thumbnails |
136 | 579 |
* Uses the begin_fetch_post_thumbnail_html and end_fetch_post_thumbnail_html action hooks to |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
580 |
* dynamically add/remove itself so as to only filter post thumbnails |
136 | 581 |
* |
582 |
* @since 2.9.0 |
|
583 |
* @param array $attr Attributes including src, class, alt, title |
|
584 |
* @return array |
|
585 |
*/ |
|
586 |
function _wp_post_thumbnail_class_filter( $attr ) { |
|
587 |
$attr['class'] .= ' wp-post-image'; |
|
588 |
return $attr; |
|
589 |
} |
|
590 |
||
591 |
/** |
|
592 |
* Adds _wp_post_thumbnail_class_filter to the wp_get_attachment_image_attributes filter |
|
593 |
* |
|
594 |
* @since 2.9.0 |
|
595 |
*/ |
|
596 |
function _wp_post_thumbnail_class_filter_add( $attr ) { |
|
597 |
add_filter( 'wp_get_attachment_image_attributes', '_wp_post_thumbnail_class_filter' ); |
|
598 |
} |
|
599 |
||
600 |
/** |
|
601 |
* Removes _wp_post_thumbnail_class_filter from the wp_get_attachment_image_attributes filter |
|
602 |
* |
|
603 |
* @since 2.9.0 |
|
604 |
*/ |
|
605 |
function _wp_post_thumbnail_class_filter_remove( $attr ) { |
|
606 |
remove_filter( 'wp_get_attachment_image_attributes', '_wp_post_thumbnail_class_filter' ); |
|
607 |
} |
|
608 |
||
609 |
add_shortcode('wp_caption', 'img_caption_shortcode'); |
|
610 |
add_shortcode('caption', 'img_caption_shortcode'); |
|
611 |
||
612 |
/** |
|
613 |
* The Caption shortcode. |
|
614 |
* |
|
615 |
* Allows a plugin to replace the content that would otherwise be returned. The |
|
616 |
* filter is 'img_caption_shortcode' and passes an empty string, the attr |
|
617 |
* parameter and the content parameter values. |
|
618 |
* |
|
619 |
* The supported attributes for the shortcode are 'id', 'align', 'width', and |
|
620 |
* 'caption'. |
|
621 |
* |
|
622 |
* @since 2.6.0 |
|
623 |
* |
|
624 |
* @param array $attr Attributes attributed to the shortcode. |
|
625 |
* @param string $content Optional. Shortcode content. |
|
626 |
* @return string |
|
627 |
*/ |
|
628 |
function img_caption_shortcode($attr, $content = null) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
629 |
// New-style shortcode with the caption inside the shortcode with the link and image tags. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
630 |
if ( ! isset( $attr['caption'] ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
631 |
if ( preg_match( '#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
632 |
$content = $matches[1]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
633 |
$attr['caption'] = trim( $matches[2] ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
634 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
635 |
} |
136 | 636 |
|
637 |
// Allow plugins/themes to override the default caption template. |
|
638 |
$output = apply_filters('img_caption_shortcode', '', $attr, $content); |
|
639 |
if ( $output != '' ) |
|
640 |
return $output; |
|
641 |
||
642 |
extract(shortcode_atts(array( |
|
643 |
'id' => '', |
|
644 |
'align' => 'alignnone', |
|
645 |
'width' => '', |
|
646 |
'caption' => '' |
|
647 |
), $attr)); |
|
648 |
||
649 |
if ( 1 > (int) $width || empty($caption) ) |
|
650 |
return $content; |
|
651 |
||
652 |
if ( $id ) $id = 'id="' . esc_attr($id) . '" '; |
|
653 |
||
654 |
return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="width: ' . (10 + (int) $width) . 'px">' |
|
655 |
. do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>'; |
|
656 |
} |
|
657 |
||
658 |
add_shortcode('gallery', 'gallery_shortcode'); |
|
659 |
||
660 |
/** |
|
661 |
* The Gallery shortcode. |
|
662 |
* |
|
663 |
* This implements the functionality of the Gallery Shortcode for displaying |
|
664 |
* WordPress images on a post. |
|
665 |
* |
|
666 |
* @since 2.5.0 |
|
667 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
668 |
* @param array $attr Attributes of the shortcode. |
136 | 669 |
* @return string HTML content to display gallery. |
670 |
*/ |
|
671 |
function gallery_shortcode($attr) { |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
672 |
$post = get_post(); |
136 | 673 |
|
674 |
static $instance = 0; |
|
675 |
$instance++; |
|
676 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
677 |
if ( ! empty( $attr['ids'] ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
678 |
// 'ids' is explicitly ordered, unless you specify otherwise. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
679 |
if ( empty( $attr['orderby'] ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
680 |
$attr['orderby'] = 'post__in'; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
681 |
$attr['include'] = $attr['ids']; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
682 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
683 |
|
136 | 684 |
// Allow plugins/themes to override the default gallery template. |
685 |
$output = apply_filters('post_gallery', '', $attr); |
|
686 |
if ( $output != '' ) |
|
687 |
return $output; |
|
688 |
||
689 |
// We're trusting author input, so let's at least make sure it looks like a valid orderby statement |
|
690 |
if ( isset( $attr['orderby'] ) ) { |
|
691 |
$attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] ); |
|
692 |
if ( !$attr['orderby'] ) |
|
693 |
unset( $attr['orderby'] ); |
|
694 |
} |
|
695 |
||
696 |
extract(shortcode_atts(array( |
|
697 |
'order' => 'ASC', |
|
698 |
'orderby' => 'menu_order ID', |
|
699 |
'id' => $post->ID, |
|
700 |
'itemtag' => 'dl', |
|
701 |
'icontag' => 'dt', |
|
702 |
'captiontag' => 'dd', |
|
703 |
'columns' => 3, |
|
704 |
'size' => 'thumbnail', |
|
705 |
'include' => '', |
|
706 |
'exclude' => '' |
|
707 |
), $attr)); |
|
708 |
||
709 |
$id = intval($id); |
|
710 |
if ( 'RAND' == $order ) |
|
711 |
$orderby = 'none'; |
|
712 |
||
713 |
if ( !empty($include) ) { |
|
714 |
$_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); |
|
715 |
||
716 |
$attachments = array(); |
|
717 |
foreach ( $_attachments as $key => $val ) { |
|
718 |
$attachments[$val->ID] = $_attachments[$key]; |
|
719 |
} |
|
720 |
} elseif ( !empty($exclude) ) { |
|
721 |
$attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); |
|
722 |
} else { |
|
723 |
$attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); |
|
724 |
} |
|
725 |
||
726 |
if ( empty($attachments) ) |
|
727 |
return ''; |
|
728 |
||
729 |
if ( is_feed() ) { |
|
730 |
$output = "\n"; |
|
731 |
foreach ( $attachments as $att_id => $attachment ) |
|
732 |
$output .= wp_get_attachment_link($att_id, $size, true) . "\n"; |
|
733 |
return $output; |
|
734 |
} |
|
735 |
||
736 |
$itemtag = tag_escape($itemtag); |
|
737 |
$captiontag = tag_escape($captiontag); |
|
738 |
$columns = intval($columns); |
|
739 |
$itemwidth = $columns > 0 ? floor(100/$columns) : 100; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
740 |
$float = is_rtl() ? 'right' : 'left'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
741 |
|
136 | 742 |
$selector = "gallery-{$instance}"; |
743 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
744 |
$gallery_style = $gallery_div = ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
745 |
if ( apply_filters( 'use_default_gallery_style', true ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
746 |
$gallery_style = " |
136 | 747 |
<style type='text/css'> |
748 |
#{$selector} { |
|
749 |
margin: auto; |
|
750 |
} |
|
751 |
#{$selector} .gallery-item { |
|
752 |
float: {$float}; |
|
753 |
margin-top: 10px; |
|
754 |
text-align: center; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
755 |
width: {$itemwidth}%; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
756 |
} |
136 | 757 |
#{$selector} img { |
758 |
border: 2px solid #cfcfcf; |
|
759 |
} |
|
760 |
#{$selector} .gallery-caption { |
|
761 |
margin-left: 0; |
|
762 |
} |
|
763 |
</style> |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
764 |
<!-- see gallery_shortcode() in wp-includes/media.php -->"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
765 |
$size_class = sanitize_html_class( $size ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
766 |
$gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
767 |
$output = apply_filters( 'gallery_style', $gallery_style . "\n\t\t" . $gallery_div ); |
136 | 768 |
|
769 |
$i = 0; |
|
770 |
foreach ( $attachments as $id => $attachment ) { |
|
771 |
$link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false); |
|
772 |
||
773 |
$output .= "<{$itemtag} class='gallery-item'>"; |
|
774 |
$output .= " |
|
775 |
<{$icontag} class='gallery-icon'> |
|
776 |
$link |
|
777 |
</{$icontag}>"; |
|
778 |
if ( $captiontag && trim($attachment->post_excerpt) ) { |
|
779 |
$output .= " |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
780 |
<{$captiontag} class='wp-caption-text gallery-caption'> |
136 | 781 |
" . wptexturize($attachment->post_excerpt) . " |
782 |
</{$captiontag}>"; |
|
783 |
} |
|
784 |
$output .= "</{$itemtag}>"; |
|
785 |
if ( $columns > 0 && ++$i % $columns == 0 ) |
|
786 |
$output .= '<br style="clear: both" />'; |
|
787 |
} |
|
788 |
||
789 |
$output .= " |
|
790 |
<br style='clear: both;' /> |
|
791 |
</div>\n"; |
|
792 |
||
793 |
return $output; |
|
794 |
} |
|
795 |
||
796 |
/** |
|
797 |
* Display previous image link that has the same post parent. |
|
798 |
* |
|
799 |
* @since 2.5.0 |
|
800 |
* @param string $size Optional, default is 'thumbnail'. Size of image, either array or string. 0 or 'none' will default to post_title or $text; |
|
801 |
* @param string $text Optional, default is false. If included, link will reflect $text variable. |
|
802 |
* @return string HTML content. |
|
803 |
*/ |
|
804 |
function previous_image_link($size = 'thumbnail', $text = false) { |
|
805 |
adjacent_image_link(true, $size, $text); |
|
806 |
} |
|
807 |
||
808 |
/** |
|
809 |
* Display next image link that has the same post parent. |
|
810 |
* |
|
811 |
* @since 2.5.0 |
|
812 |
* @param string $size Optional, default is 'thumbnail'. Size of image, either array or string. 0 or 'none' will default to post_title or $text; |
|
813 |
* @param string $text Optional, default is false. If included, link will reflect $text variable. |
|
814 |
* @return string HTML content. |
|
815 |
*/ |
|
816 |
function next_image_link($size = 'thumbnail', $text = false) { |
|
817 |
adjacent_image_link(false, $size, $text); |
|
818 |
} |
|
819 |
||
820 |
/** |
|
821 |
* Display next or previous image link that has the same post parent. |
|
822 |
* |
|
823 |
* Retrieves the current attachment object from the $post global. |
|
824 |
* |
|
825 |
* @since 2.5.0 |
|
826 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
827 |
* @param bool $prev Optional. Default is true to display previous link, false for next. |
136 | 828 |
*/ |
829 |
function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false) { |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
830 |
$post = get_post(); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
831 |
$attachments = array_values( get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) ) ); |
136 | 832 |
|
833 |
foreach ( $attachments as $k => $attachment ) |
|
834 |
if ( $attachment->ID == $post->ID ) |
|
835 |
break; |
|
836 |
||
837 |
$k = $prev ? $k - 1 : $k + 1; |
|
838 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
839 |
$output = $attachment_id = null; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
840 |
if ( isset( $attachments[ $k ] ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
841 |
$attachment_id = $attachments[ $k ]->ID; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
842 |
$output = wp_get_attachment_link( $attachment_id, $size, true, false, $text ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
843 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
844 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
845 |
$adjacent = $prev ? 'previous' : 'next'; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
846 |
echo apply_filters( "{$adjacent}_image_link", $output, $attachment_id, $size, $text ); |
136 | 847 |
} |
848 |
||
849 |
/** |
|
850 |
* Retrieve taxonomies attached to the attachment. |
|
851 |
* |
|
852 |
* @since 2.5.0 |
|
853 |
* |
|
854 |
* @param int|array|object $attachment Attachment ID, Attachment data array, or Attachment data object. |
|
855 |
* @return array Empty array on failure. List of taxonomies on success. |
|
856 |
*/ |
|
857 |
function get_attachment_taxonomies($attachment) { |
|
858 |
if ( is_int( $attachment ) ) |
|
859 |
$attachment = get_post($attachment); |
|
860 |
else if ( is_array($attachment) ) |
|
861 |
$attachment = (object) $attachment; |
|
862 |
||
863 |
if ( ! is_object($attachment) ) |
|
864 |
return array(); |
|
865 |
||
866 |
$filename = basename($attachment->guid); |
|
867 |
||
868 |
$objects = array('attachment'); |
|
869 |
||
870 |
if ( false !== strpos($filename, '.') ) |
|
871 |
$objects[] = 'attachment:' . substr($filename, strrpos($filename, '.') + 1); |
|
872 |
if ( !empty($attachment->post_mime_type) ) { |
|
873 |
$objects[] = 'attachment:' . $attachment->post_mime_type; |
|
874 |
if ( false !== strpos($attachment->post_mime_type, '/') ) |
|
875 |
foreach ( explode('/', $attachment->post_mime_type) as $token ) |
|
876 |
if ( !empty($token) ) |
|
877 |
$objects[] = "attachment:$token"; |
|
878 |
} |
|
879 |
||
880 |
$taxonomies = array(); |
|
881 |
foreach ( $objects as $object ) |
|
882 |
if ( $taxes = get_object_taxonomies($object) ) |
|
883 |
$taxonomies = array_merge($taxonomies, $taxes); |
|
884 |
||
885 |
return array_unique($taxonomies); |
|
886 |
} |
|
887 |
||
888 |
/** |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
889 |
* Return all of the taxonomy names that are registered for attachments. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
890 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
891 |
* Handles mime-type-specific taxonomies such as attachment:image and attachment:video. |
136 | 892 |
* |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
893 |
* @since 3.5.0 |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
894 |
* @see get_attachment_taxonomies() |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
895 |
* @uses get_taxonomies() |
136 | 896 |
* |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
897 |
* @param string $output The type of output to return, either taxonomy 'names' or 'objects'. 'names' is the default. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
898 |
* @return array The names of all taxonomy of $object_type. |
136 | 899 |
*/ |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
900 |
function get_taxonomies_for_attachments( $output = 'names' ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
901 |
$taxonomies = array(); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
902 |
foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
903 |
foreach ( $taxonomy->object_type as $object_type ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
904 |
if ( 'attachment' == $object_type || 0 === strpos( $object_type, 'attachment:' ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
905 |
if ( 'names' == $output ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
906 |
$taxonomies[] = $taxonomy->name; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
907 |
else |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
908 |
$taxonomies[ $taxonomy->name ] = $taxonomy; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
909 |
break; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
910 |
} |
136 | 911 |
} |
912 |
} |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
913 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
914 |
return $taxonomies; |
136 | 915 |
} |
916 |
||
917 |
/** |
|
918 |
* Create new GD image resource with transparency support |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
919 |
* @TODO: Deprecate if possible. |
136 | 920 |
* |
921 |
* @since 2.9.0 |
|
922 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
923 |
* @param int $width Image width |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
924 |
* @param int $height Image height |
136 | 925 |
* @return image resource |
926 |
*/ |
|
927 |
function wp_imagecreatetruecolor($width, $height) { |
|
928 |
$img = imagecreatetruecolor($width, $height); |
|
929 |
if ( is_resource($img) && function_exists('imagealphablending') && function_exists('imagesavealpha') ) { |
|
930 |
imagealphablending($img, false); |
|
931 |
imagesavealpha($img, true); |
|
932 |
} |
|
933 |
return $img; |
|
934 |
} |
|
935 |
||
936 |
/** |
|
937 |
* Register an embed handler. This function should probably only be used for sites that do not support oEmbed. |
|
938 |
* |
|
939 |
* @since 2.9.0 |
|
940 |
* @see WP_Embed::register_handler() |
|
941 |
*/ |
|
942 |
function wp_embed_register_handler( $id, $regex, $callback, $priority = 10 ) { |
|
943 |
global $wp_embed; |
|
944 |
$wp_embed->register_handler( $id, $regex, $callback, $priority ); |
|
945 |
} |
|
946 |
||
947 |
/** |
|
948 |
* Unregister a previously registered embed handler. |
|
949 |
* |
|
950 |
* @since 2.9.0 |
|
951 |
* @see WP_Embed::unregister_handler() |
|
952 |
*/ |
|
953 |
function wp_embed_unregister_handler( $id, $priority = 10 ) { |
|
954 |
global $wp_embed; |
|
955 |
$wp_embed->unregister_handler( $id, $priority ); |
|
956 |
} |
|
957 |
||
958 |
/** |
|
959 |
* Create default array of embed parameters. |
|
960 |
* |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
961 |
* The width defaults to the content width as specified by the theme. If the |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
962 |
* theme does not specify a content width, then 500px is used. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
963 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
964 |
* The default height is 1.5 times the width, or 1000px, whichever is smaller. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
965 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
966 |
* The 'embed_defaults' filter can be used to adjust either of these values. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
967 |
* |
136 | 968 |
* @since 2.9.0 |
969 |
* |
|
970 |
* @return array Default embed parameters. |
|
971 |
*/ |
|
972 |
function wp_embed_defaults() { |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
973 |
if ( ! empty( $GLOBALS['content_width'] ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
974 |
$width = (int) $GLOBALS['content_width']; |
136 | 975 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
976 |
if ( empty( $width ) ) |
136 | 977 |
$width = 500; |
978 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
979 |
$height = min( ceil( $width * 1.5 ), 1000 ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
980 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
981 |
return apply_filters( 'embed_defaults', compact( 'width', 'height' ) ); |
136 | 982 |
} |
983 |
||
984 |
/** |
|
985 |
* Based on a supplied width/height example, return the biggest possible dimensions based on the max width/height. |
|
986 |
* |
|
987 |
* @since 2.9.0 |
|
988 |
* @uses wp_constrain_dimensions() This function passes the widths and the heights. |
|
989 |
* |
|
990 |
* @param int $example_width The width of an example embed. |
|
991 |
* @param int $example_height The height of an example embed. |
|
992 |
* @param int $max_width The maximum allowed width. |
|
993 |
* @param int $max_height The maximum allowed height. |
|
994 |
* @return array The maximum possible width and height based on the example ratio. |
|
995 |
*/ |
|
996 |
function wp_expand_dimensions( $example_width, $example_height, $max_width, $max_height ) { |
|
997 |
$example_width = (int) $example_width; |
|
998 |
$example_height = (int) $example_height; |
|
999 |
$max_width = (int) $max_width; |
|
1000 |
$max_height = (int) $max_height; |
|
1001 |
||
1002 |
return wp_constrain_dimensions( $example_width * 1000000, $example_height * 1000000, $max_width, $max_height ); |
|
1003 |
} |
|
1004 |
||
1005 |
/** |
|
1006 |
* Attempts to fetch the embed HTML for a provided URL using oEmbed. |
|
1007 |
* |
|
1008 |
* @since 2.9.0 |
|
1009 |
* @see WP_oEmbed |
|
1010 |
* |
|
1011 |
* @uses _wp_oembed_get_object() |
|
1012 |
* @uses WP_oEmbed::get_html() |
|
1013 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1014 |
* @param string $url The URL that should be embedded. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1015 |
* @param array $args Additional arguments and parameters. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1016 |
* @return bool|string False on failure or the embed HTML on success. |
136 | 1017 |
*/ |
1018 |
function wp_oembed_get( $url, $args = '' ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1019 |
require_once( ABSPATH . WPINC . '/class-oembed.php' ); |
136 | 1020 |
$oembed = _wp_oembed_get_object(); |
1021 |
return $oembed->get_html( $url, $args ); |
|
1022 |
} |
|
1023 |
||
1024 |
/** |
|
1025 |
* Adds a URL format and oEmbed provider URL pair. |
|
1026 |
* |
|
1027 |
* @since 2.9.0 |
|
1028 |
* @see WP_oEmbed |
|
1029 |
* |
|
1030 |
* @uses _wp_oembed_get_object() |
|
1031 |
* |
|
1032 |
* @param string $format The format of URL that this provider can handle. You can use asterisks as wildcards. |
|
1033 |
* @param string $provider The URL to the oEmbed provider. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1034 |
* @param boolean $regex Whether the $format parameter is in a regex format. |
136 | 1035 |
*/ |
1036 |
function wp_oembed_add_provider( $format, $provider, $regex = false ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1037 |
require_once( ABSPATH . WPINC . '/class-oembed.php' ); |
136 | 1038 |
$oembed = _wp_oembed_get_object(); |
1039 |
$oembed->providers[$format] = array( $provider, $regex ); |
|
1040 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1041 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1042 |
/** |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1043 |
* Removes an oEmbed provider. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1044 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1045 |
* @since 3.5 |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1046 |
* @see WP_oEmbed |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1047 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1048 |
* @uses _wp_oembed_get_object() |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1049 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1050 |
* @param string $format The URL format for the oEmbed provider to remove. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1051 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1052 |
function wp_oembed_remove_provider( $format ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1053 |
require_once( ABSPATH . WPINC . '/class-oembed.php' ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1054 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1055 |
$oembed = _wp_oembed_get_object(); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1056 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1057 |
if ( isset( $oembed->providers[ $format ] ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1058 |
unset( $oembed->providers[ $format ] ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1059 |
return true; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1060 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1061 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1062 |
return false; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1063 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1064 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1065 |
/** |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1066 |
* Determines if default embed handlers should be loaded. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1067 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1068 |
* Checks to make sure that the embeds library hasn't already been loaded. If |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1069 |
* it hasn't, then it will load the embeds library. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1070 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1071 |
* @since 2.9.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1072 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1073 |
function wp_maybe_load_embeds() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1074 |
if ( ! apply_filters( 'load_default_embeds', true ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1075 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1076 |
wp_embed_register_handler( 'googlevideo', '#http://video\.google\.([A-Za-z.]{2,5})/videoplay\?docid=([\d-]+)(.*?)#i', 'wp_embed_handler_googlevideo' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1077 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1078 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1079 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1080 |
* The Google Video embed handler callback. Google Video does not support oEmbed. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1081 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1082 |
* @see WP_Embed::register_handler() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1083 |
* @see WP_Embed::shortcode() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1084 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1085 |
* @param array $matches The regex matches from the provided regex when calling {@link wp_embed_register_handler()}. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1086 |
* @param array $attr Embed attributes. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1087 |
* @param string $url The original URL that was matched by the regex. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1088 |
* @param array $rawattr The original unmodified attributes. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1089 |
* @return string The embed HTML. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1090 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1091 |
function wp_embed_handler_googlevideo( $matches, $attr, $url, $rawattr ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1092 |
// If the user supplied a fixed width AND height, use it |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1093 |
if ( !empty($rawattr['width']) && !empty($rawattr['height']) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1094 |
$width = (int) $rawattr['width']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1095 |
$height = (int) $rawattr['height']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1096 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1097 |
list( $width, $height ) = wp_expand_dimensions( 425, 344, $attr['width'], $attr['height'] ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1098 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1099 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1100 |
return apply_filters( 'embed_googlevideo', '<embed type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docid=' . esc_attr($matches[2]) . '&hl=en&fs=true" style="width:' . esc_attr($width) . 'px;height:' . esc_attr($height) . 'px" allowFullScreen="true" allowScriptAccess="always" />', $matches, $attr, $url, $rawattr ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1101 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1102 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1103 |
/** |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1104 |
* {@internal Missing Short Description}} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1105 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1106 |
* @since 2.3.0 |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1107 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1108 |
* @param unknown_type $size |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1109 |
* @return unknown |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1110 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1111 |
function wp_convert_hr_to_bytes( $size ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1112 |
$size = strtolower( $size ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1113 |
$bytes = (int) $size; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1114 |
if ( strpos( $size, 'k' ) !== false ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1115 |
$bytes = intval( $size ) * 1024; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1116 |
elseif ( strpos( $size, 'm' ) !== false ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1117 |
$bytes = intval($size) * 1024 * 1024; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1118 |
elseif ( strpos( $size, 'g' ) !== false ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1119 |
$bytes = intval( $size ) * 1024 * 1024 * 1024; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1120 |
return $bytes; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1121 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1122 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1123 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1124 |
* {@internal Missing Short Description}} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1125 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1126 |
* @since 2.3.0 |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1127 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1128 |
* @param unknown_type $bytes |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1129 |
* @return unknown |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1130 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1131 |
function wp_convert_bytes_to_hr( $bytes ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1132 |
$units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB' ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1133 |
$log = log( $bytes, 1024 ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1134 |
$power = (int) $log; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1135 |
$size = pow( 1024, $log - $power ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1136 |
return $size . $units[$power]; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1137 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1138 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1139 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1140 |
* {@internal Missing Short Description}} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1141 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1142 |
* @since 2.5.0 |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1143 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1144 |
* @return unknown |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1145 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1146 |
function wp_max_upload_size() { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1147 |
$u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1148 |
$p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1149 |
$bytes = apply_filters( 'upload_size_limit', min( $u_bytes, $p_bytes ), $u_bytes, $p_bytes ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1150 |
return $bytes; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1151 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1152 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1153 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1154 |
* Returns a WP_Image_Editor instance and loads file into it. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1155 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1156 |
* @since 3.5.0 |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1157 |
* @access public |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1158 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1159 |
* @param string $path Path to file to load |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1160 |
* @param array $args Additional data. Accepts { 'mime_type'=>string, 'methods'=>{string, string, ...} } |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1161 |
* @return WP_Image_Editor|WP_Error |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1162 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1163 |
function wp_get_image_editor( $path, $args = array() ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1164 |
$args['path'] = $path; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1165 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1166 |
if ( ! isset( $args['mime_type'] ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1167 |
$file_info = wp_check_filetype( $args['path'] ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1168 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1169 |
// If $file_info['type'] is false, then we let the editor attempt to |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1170 |
// figure out the file type, rather than forcing a failure based on extension. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1171 |
if ( isset( $file_info ) && $file_info['type'] ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1172 |
$args['mime_type'] = $file_info['type']; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1173 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1174 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1175 |
$implementation = _wp_image_editor_choose( $args ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1176 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1177 |
if ( $implementation ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1178 |
$editor = new $implementation( $path ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1179 |
$loaded = $editor->load(); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1180 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1181 |
if ( is_wp_error( $loaded ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1182 |
return $loaded; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1183 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1184 |
return $editor; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1185 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1186 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1187 |
return new WP_Error( 'image_no_editor', __('No editor could be selected.') ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1188 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1189 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1190 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1191 |
* Tests whether there is an editor that supports a given mime type or methods. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1192 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1193 |
* @since 3.5.0 |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1194 |
* @access public |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1195 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1196 |
* @param string|array $args Array of requirements. Accepts { 'mime_type'=>string, 'methods'=>{string, string, ...} } |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1197 |
* @return boolean true if an eligible editor is found; false otherwise |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1198 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1199 |
function wp_image_editor_supports( $args = array() ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1200 |
return (bool) _wp_image_editor_choose( $args ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1201 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1202 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1203 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1204 |
* Tests which editors are capable of supporting the request. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1205 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1206 |
* @since 3.5.0 |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1207 |
* @access private |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1208 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1209 |
* @param array $args Additional data. Accepts { 'mime_type'=>string, 'methods'=>{string, string, ...} } |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1210 |
* @return string|bool Class name for the first editor that claims to support the request. False if no editor claims to support the request. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1211 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1212 |
function _wp_image_editor_choose( $args = array() ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1213 |
require_once ABSPATH . WPINC . '/class-wp-image-editor.php'; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1214 |
require_once ABSPATH . WPINC . '/class-wp-image-editor-gd.php'; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1215 |
require_once ABSPATH . WPINC . '/class-wp-image-editor-imagick.php'; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1216 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1217 |
$implementations = apply_filters( 'wp_image_editors', |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1218 |
array( 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD' ) ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1219 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1220 |
foreach ( $implementations as $implementation ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1221 |
if ( ! call_user_func( array( $implementation, 'test' ), $args ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1222 |
continue; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1223 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1224 |
if ( isset( $args['mime_type'] ) && |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1225 |
! call_user_func( |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1226 |
array( $implementation, 'supports_mime_type' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1227 |
$args['mime_type'] ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1228 |
continue; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1229 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1230 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1231 |
if ( isset( $args['methods'] ) && |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1232 |
array_diff( $args['methods'], get_class_methods( $implementation ) ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1233 |
continue; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1234 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1235 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1236 |
return $implementation; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1237 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1238 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1239 |
return false; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1240 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1241 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1242 |
/** |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1243 |
* Prints default plupload arguments. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1244 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1245 |
* @since 3.4.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1246 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1247 |
function wp_plupload_default_settings() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1248 |
global $wp_scripts; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1249 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1250 |
$data = $wp_scripts->get_data( 'wp-plupload', 'data' ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1251 |
if ( $data && false !== strpos( $data, '_wpPluploadSettings' ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1252 |
return; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1253 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1254 |
$max_upload_size = wp_max_upload_size(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1255 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1256 |
$defaults = array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1257 |
'runtimes' => 'html5,silverlight,flash,html4', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1258 |
'file_data_name' => 'async-upload', // key passed to $_FILE. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1259 |
'multiple_queues' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1260 |
'max_file_size' => $max_upload_size . 'b', |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1261 |
'url' => admin_url( 'async-upload.php', 'relative' ), |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1262 |
'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1263 |
'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1264 |
'filters' => array( array( 'title' => __( 'Allowed Files' ), 'extensions' => '*') ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1265 |
'multipart' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1266 |
'urlstream_upload' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1267 |
); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1268 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1269 |
// Multi-file uploading doesn't currently work in iOS Safari, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1270 |
// single-file allows the built-in camera to be used as source for images |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1271 |
if ( wp_is_mobile() ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1272 |
$defaults['multi_selection'] = false; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1273 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1274 |
$defaults = apply_filters( 'plupload_default_settings', $defaults ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1275 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1276 |
$params = array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1277 |
'action' => 'upload-attachment', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1278 |
); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1279 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1280 |
$params = apply_filters( 'plupload_default_params', $params ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1281 |
$params['_wpnonce'] = wp_create_nonce( 'media-form' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1282 |
$defaults['multipart_params'] = $params; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1283 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1284 |
$settings = array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1285 |
'defaults' => $defaults, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1286 |
'browser' => array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1287 |
'mobile' => wp_is_mobile(), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1288 |
'supported' => _device_can_upload(), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1289 |
), |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1290 |
'limitExceeded' => is_multisite() && ! is_upload_space_available() |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1291 |
); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1292 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1293 |
$script = 'var _wpPluploadSettings = ' . json_encode( $settings ) . ';'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1294 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1295 |
if ( $data ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1296 |
$script = "$data\n$script"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1297 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1298 |
$wp_scripts->add_data( 'wp-plupload', 'data', $script ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1299 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1300 |
add_action( 'customize_controls_enqueue_scripts', 'wp_plupload_default_settings' ); |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1301 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1302 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1303 |
* Prepares an attachment post object for JS, where it is expected |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1304 |
* to be JSON-encoded and fit into an Attachment model. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1305 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1306 |
* @since 3.5.0 |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1307 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1308 |
* @param mixed $attachment Attachment ID or object. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1309 |
* @return array Array of attachment details. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1310 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1311 |
function wp_prepare_attachment_for_js( $attachment ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1312 |
if ( ! $attachment = get_post( $attachment ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1313 |
return; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1314 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1315 |
if ( 'attachment' != $attachment->post_type ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1316 |
return; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1317 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1318 |
$meta = wp_get_attachment_metadata( $attachment->ID ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1319 |
if ( false !== strpos( $attachment->post_mime_type, '/' ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1320 |
list( $type, $subtype ) = explode( '/', $attachment->post_mime_type ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1321 |
else |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1322 |
list( $type, $subtype ) = array( $attachment->post_mime_type, '' ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1323 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1324 |
$attachment_url = wp_get_attachment_url( $attachment->ID ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1325 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1326 |
$response = array( |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1327 |
'id' => $attachment->ID, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1328 |
'title' => $attachment->post_title, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1329 |
'filename' => basename( $attachment->guid ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1330 |
'url' => $attachment_url, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1331 |
'link' => get_attachment_link( $attachment->ID ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1332 |
'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1333 |
'author' => $attachment->post_author, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1334 |
'description' => $attachment->post_content, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1335 |
'caption' => $attachment->post_excerpt, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1336 |
'name' => $attachment->post_name, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1337 |
'status' => $attachment->post_status, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1338 |
'uploadedTo' => $attachment->post_parent, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1339 |
'date' => strtotime( $attachment->post_date_gmt ) * 1000, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1340 |
'modified' => strtotime( $attachment->post_modified_gmt ) * 1000, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1341 |
'menuOrder' => $attachment->menu_order, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1342 |
'mime' => $attachment->post_mime_type, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1343 |
'type' => $type, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1344 |
'subtype' => $subtype, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1345 |
'icon' => wp_mime_type_icon( $attachment->ID ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1346 |
'dateFormatted' => mysql2date( get_option('date_format'), $attachment->post_date ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1347 |
'nonces' => array( |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1348 |
'update' => false, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1349 |
'delete' => false, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1350 |
), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1351 |
'editLink' => false, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1352 |
); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1353 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1354 |
if ( current_user_can( 'edit_post', $attachment->ID ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1355 |
$response['nonces']['update'] = wp_create_nonce( 'update-post_' . $attachment->ID ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1356 |
$response['editLink'] = get_edit_post_link( $attachment->ID, 'raw' ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1357 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1358 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1359 |
if ( current_user_can( 'delete_post', $attachment->ID ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1360 |
$response['nonces']['delete'] = wp_create_nonce( 'delete-post_' . $attachment->ID ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1361 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1362 |
if ( $meta && 'image' === $type ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1363 |
$sizes = array(); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1364 |
$possible_sizes = apply_filters( 'image_size_names_choose', array( |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1365 |
'thumbnail' => __('Thumbnail'), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1366 |
'medium' => __('Medium'), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1367 |
'large' => __('Large'), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1368 |
'full' => __('Full Size'), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1369 |
) ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1370 |
unset( $possible_sizes['full'] ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1371 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1372 |
// Loop through all potential sizes that may be chosen. Try to do this with some efficiency. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1373 |
// First: run the image_downsize filter. If it returns something, we can use its data. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1374 |
// If the filter does not return something, then image_downsize() is just an expensive |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1375 |
// way to check the image metadata, which we do second. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1376 |
foreach ( $possible_sizes as $size => $label ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1377 |
if ( $downsize = apply_filters( 'image_downsize', false, $attachment->ID, $size ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1378 |
if ( ! $downsize[3] ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1379 |
continue; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1380 |
$sizes[ $size ] = array( |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1381 |
'height' => $downsize[2], |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1382 |
'width' => $downsize[1], |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1383 |
'url' => $downsize[0], |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1384 |
'orientation' => $downsize[2] > $downsize[1] ? 'portrait' : 'landscape', |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1385 |
); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1386 |
} elseif ( isset( $meta['sizes'][ $size ] ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1387 |
if ( ! isset( $base_url ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1388 |
$base_url = str_replace( wp_basename( $attachment_url ), '', $attachment_url ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1389 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1390 |
// Nothing from the filter, so consult image metadata if we have it. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1391 |
$size_meta = $meta['sizes'][ $size ]; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1392 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1393 |
// We have the actual image size, but might need to further constrain it if content_width is narrower. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1394 |
// This is not necessary for thumbnails and medium size. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1395 |
if ( 'thumbnail' == $size || 'medium' == $size ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1396 |
$width = $size_meta['width']; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1397 |
$height = $size_meta['height']; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1398 |
} else { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1399 |
list( $width, $height ) = image_constrain_size_for_editor( $size_meta['width'], $size_meta['height'], $size, 'edit' ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1400 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1401 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1402 |
$sizes[ $size ] = array( |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1403 |
'height' => $height, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1404 |
'width' => $width, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1405 |
'url' => $base_url . $size_meta['file'], |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1406 |
'orientation' => $height > $width ? 'portrait' : 'landscape', |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1407 |
); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1408 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1409 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1410 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1411 |
$sizes['full'] = array( |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1412 |
'height' => $meta['height'], |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1413 |
'width' => $meta['width'], |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1414 |
'url' => $attachment_url, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1415 |
'orientation' => $meta['height'] > $meta['width'] ? 'portrait' : 'landscape', |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1416 |
); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1417 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1418 |
$response = array_merge( $response, array( 'sizes' => $sizes ), $sizes['full'] ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1419 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1420 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1421 |
if ( function_exists('get_compat_media_markup') ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1422 |
$response['compat'] = get_compat_media_markup( $attachment->ID, array( 'in_modal' => true ) ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1423 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1424 |
return apply_filters( 'wp_prepare_attachment_for_js', $response, $attachment, $meta ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1425 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1426 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1427 |
/** |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1428 |
* Enqueues all scripts, styles, settings, and templates necessary to use |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1429 |
* all media JS APIs. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1430 |
* |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1431 |
* @since 3.5.0 |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1432 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1433 |
function wp_enqueue_media( $args = array() ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1434 |
$defaults = array( |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1435 |
'post' => null, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1436 |
); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1437 |
$args = wp_parse_args( $args, $defaults ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1438 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1439 |
// We're going to pass the old thickbox media tabs to `media_upload_tabs` |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1440 |
// to ensure plugins will work. We will then unset those tabs. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1441 |
$tabs = array( |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1442 |
// handler action suffix => tab label |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1443 |
'type' => '', |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1444 |
'type_url' => '', |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1445 |
'gallery' => '', |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1446 |
'library' => '', |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1447 |
); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1448 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1449 |
$tabs = apply_filters( 'media_upload_tabs', $tabs ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1450 |
unset( $tabs['type'], $tabs['type_url'], $tabs['gallery'], $tabs['library'] ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1451 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1452 |
$settings = array( |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1453 |
'tabs' => $tabs, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1454 |
'tabUrl' => add_query_arg( array( 'chromeless' => true ), admin_url('media-upload.php') ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1455 |
'mimeTypes' => wp_list_pluck( get_post_mime_types(), 0 ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1456 |
'captions' => ! apply_filters( 'disable_captions', '' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1457 |
'nonce' => array( |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1458 |
'sendToEditor' => wp_create_nonce( 'media-send-to-editor' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1459 |
), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1460 |
'post' => array( |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1461 |
'id' => 0, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1462 |
), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1463 |
); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1464 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1465 |
$post = null; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1466 |
if ( isset( $args['post'] ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1467 |
$post = get_post( $args['post'] ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1468 |
$settings['post'] = array( |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1469 |
'id' => $post->ID, |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1470 |
'nonce' => wp_create_nonce( 'update-post_' . $post->ID ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1471 |
); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1472 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1473 |
if ( current_theme_supports( 'post-thumbnails', $post->post_type ) && post_type_supports( $post->post_type, 'thumbnail' ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1474 |
$featured_image_id = get_post_meta( $post->ID, '_thumbnail_id', true ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1475 |
$settings['post']['featuredImageId'] = $featured_image_id ? $featured_image_id : -1; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1476 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1477 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1478 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1479 |
$hier = $post && is_post_type_hierarchical( $post->post_type ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1480 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1481 |
$strings = array( |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1482 |
// Generic |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1483 |
'url' => __( 'URL' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1484 |
'addMedia' => __( 'Add Media' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1485 |
'search' => __( 'Search' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1486 |
'select' => __( 'Select' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1487 |
'cancel' => __( 'Cancel' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1488 |
/* translators: This is a would-be plural string used in the media manager. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1489 |
If there is not a word you can use in your language to avoid issues with the |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1490 |
lack of plural support here, turn it into "selected: %d" then translate it. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1491 |
*/ |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1492 |
'selected' => __( '%d selected' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1493 |
'dragInfo' => __( 'Drag and drop to reorder images.' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1494 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1495 |
// Upload |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1496 |
'uploadFilesTitle' => __( 'Upload Files' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1497 |
'uploadImagesTitle' => __( 'Upload Images' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1498 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1499 |
// Library |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1500 |
'mediaLibraryTitle' => __( 'Media Library' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1501 |
'insertMediaTitle' => __( 'Insert Media' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1502 |
'createNewGallery' => __( 'Create a new gallery' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1503 |
'returnToLibrary' => __( '← Return to library' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1504 |
'allMediaItems' => __( 'All media items' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1505 |
'noItemsFound' => __( 'No items found.' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1506 |
'insertIntoPost' => $hier ? __( 'Insert into page' ) : __( 'Insert into post' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1507 |
'uploadedToThisPost' => $hier ? __( 'Uploaded to this page' ) : __( 'Uploaded to this post' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1508 |
'warnDelete' => __( "You are about to permanently delete this item.\n 'Cancel' to stop, 'OK' to delete." ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1509 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1510 |
// From URL |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1511 |
'insertFromUrlTitle' => __( 'Insert from URL' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1512 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1513 |
// Featured Images |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1514 |
'setFeaturedImageTitle' => __( 'Set Featured Image' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1515 |
'setFeaturedImage' => __( 'Set featured image' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1516 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1517 |
// Gallery |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1518 |
'createGalleryTitle' => __( 'Create Gallery' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1519 |
'editGalleryTitle' => __( 'Edit Gallery' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1520 |
'cancelGalleryTitle' => __( '← Cancel Gallery' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1521 |
'insertGallery' => __( 'Insert gallery' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1522 |
'updateGallery' => __( 'Update gallery' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1523 |
'addToGallery' => __( 'Add to gallery' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1524 |
'addToGalleryTitle' => __( 'Add to Gallery' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1525 |
'reverseOrder' => __( 'Reverse order' ), |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1526 |
); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1527 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1528 |
$settings = apply_filters( 'media_view_settings', $settings, $post ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1529 |
$strings = apply_filters( 'media_view_strings', $strings, $post ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1530 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1531 |
$strings['settings'] = $settings; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1532 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1533 |
wp_localize_script( 'media-views', '_wpMediaViewsL10n', $strings ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1534 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1535 |
wp_enqueue_script( 'media-editor' ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1536 |
wp_enqueue_style( 'media-views' ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1537 |
wp_plupload_default_settings(); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1538 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1539 |
require_once ABSPATH . WPINC . '/media-template.php'; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1540 |
add_action( 'admin_footer', 'wp_print_media_templates' ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1541 |
add_action( 'wp_footer', 'wp_print_media_templates' ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1542 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1543 |
do_action( 'wp_enqueue_media' ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1544 |
} |