1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Simple class to override settings necessary to work with WordPress thumbnails instead of generated ones |
4
|
|
|
*/ |
5
|
|
|
if ( !class_exists( 'JustifiedOverrides' ) ) { |
6
|
|
|
|
7
|
|
|
class JustifiedOverrides { |
|
|
|
|
8
|
|
|
|
9
|
|
|
function __construct() { |
|
|
|
|
10
|
|
|
//override thumbnail resizing |
11
|
|
|
add_filter( 'foogallery_attachment_resize_thumbnail', array( $this, 'get_thumb' ), 99, 3 ); |
12
|
|
|
//add additional parameters to image args |
13
|
|
|
add_filter( 'foogallery_attachment_html_image_attributes', array( $this, 'fill_sizes' ), 99, 3 ); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
function get_thumb($original_image_src, $args, $image) { |
|
|
|
|
17
|
|
|
//of course the height is merely the label of the chosen thumbnail |
18
|
|
|
$thumb_url = $image->sizes[$args['height']]['url']; |
19
|
|
|
return $thumb_url; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
function fill_sizes($attr, $args, $image) { |
|
|
|
|
23
|
|
|
$thumbnail_label = foogallery_gallery_template_setting("thumb_initial"); |
|
|
|
|
24
|
|
|
|
25
|
|
|
//get selected alternate image sizes from settings |
26
|
|
|
$image_sizes = foogallery_gallery_template_setting("thumb_sizes"); |
27
|
|
|
|
28
|
|
|
//create width/height array and string |
29
|
|
|
if (is_array($image_sizes)) { |
30
|
|
|
foreach ($image_sizes as $image_size) { |
31
|
|
|
$size_str[] = '{"width" : "' . $image->sizes[$image_size]['width'] . '", "height" : "' . $image->sizes[$image_size]['height'] . '"}'; |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
if (isset($size_str) && !is_null($size_str)) { |
35
|
|
|
$img_sizes = "[" . implode(',', $size_str) . "]"; |
36
|
|
|
$attr['data-sizes'] = $img_sizes; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return $attr; |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.