|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* WPThumb Enhancements Class |
|
4
|
|
|
* Date: 7 Nov 2016 |
|
5
|
|
|
* |
|
6
|
|
|
* Some themes include a filter to override the ORDER of the image editors to be used, |
|
7
|
|
|
* so that the GD library is used as a preference over the Imagick library. |
|
8
|
|
|
* This is acceptable, but WPThumb requires it's own overrides of the |
|
9
|
|
|
* WP_Image_Editor_GD and WP_Image_Editor_Imagick classes (set in wpthumb.php |
|
10
|
|
|
* 'wpthumb_add_image_editors' function). The theme's filter runs after the WPThumb |
|
11
|
|
|
* filter, so the override classes needed by WPThumb are ignored. This stops WPThumb |
|
12
|
|
|
* from working at all. To get around this we need to override the image editors |
|
13
|
|
|
* later (priority 999) and "force" the usage of the WPThumb override classes, |
|
14
|
|
|
* while still preserving the order set by the theme author, or server administrator. |
|
15
|
|
|
* |
|
16
|
|
|
* The hosting provider's decision to use GD over Imagick is usually due to a timeout |
|
17
|
|
|
* that occurs when large images are uploaded to the media library. The PHP setting |
|
18
|
|
|
* for memory on the server could be too low, and this causes Imagick to timeout. |
|
19
|
|
|
* Switching to GD usually fixes the problem, without needing to change memory limits. |
|
20
|
|
|
* |
|
21
|
|
|
*/ |
|
22
|
|
|
if ( ! class_exists( 'FooGallery_WPThumb_Enhancements' ) ) { |
|
23
|
|
|
|
|
24
|
|
|
class FooGallery_WPThumb_Enhancements { |
|
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
function __construct() { |
|
|
|
|
|
|
27
|
|
|
add_filter( 'wp_image_editors', array( $this, 'override_image_editors' ), 999 ); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Overrides the editors to make sure the WPThumb editors are included |
|
32
|
|
|
* |
|
33
|
|
|
* @param $editors |
|
34
|
|
|
* @return array |
|
35
|
|
|
*/ |
|
36
|
|
|
function override_image_editors($editors) { |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
$wpthumb_editors = array(); |
|
39
|
|
|
|
|
40
|
|
|
//replace the default image editors with the WPThumb image editors. |
|
41
|
|
|
// also preserve the order so that certain hosts work as expected |
|
42
|
|
|
foreach ($editors as $editor) { |
|
43
|
|
|
switch ($editor) { |
|
44
|
|
|
case 'WP_Image_Editor_Imagick': |
|
45
|
|
|
$wpthumb_editors[] = 'WP_Thumb_Image_Editor_Imagick'; |
|
46
|
|
|
break; |
|
47
|
|
|
case 'WP_Image_Editor_GD': |
|
48
|
|
|
$wpthumb_editors[] = 'WP_Thumb_Image_Editor_GD'; |
|
49
|
|
|
break; |
|
50
|
|
|
default: |
|
51
|
|
|
$wpthumb_editors[] = $editor; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
//make sure we have a unique list of editors |
|
56
|
|
|
return array_unique( $wpthumb_editors ); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
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.