Skip to content

Commit 0a2c023

Browse files
committed
fix compatibility with wp show posts
1 parent 900db7b commit 0a2c023

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

inc/compatibilities/wpsp.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
/**
4+
* Class Optml_wpsp
5+
*
6+
* @reason WP Show Posts is using an image resizer that is not compatible with Optimole.
7+
*/
8+
class Optml_wpsp extends Optml_compatibility {
9+
/**
10+
* The last attribute used.
11+
*
12+
* @var array
13+
*/
14+
private static $last_attribute = [];
15+
16+
/**
17+
* Should we load the integration logic.
18+
*
19+
* @return bool Should we load.
20+
*/
21+
public function should_load() {
22+
include_once ABSPATH . 'wp-admin/includes/plugin.php';
23+
24+
return is_plugin_active( 'wp-show-posts/wp-show-posts.php' );
25+
}
26+
27+
/**
28+
* Should we early load the compatibility?
29+
*
30+
* @return bool Whether to load the compatibility or not.
31+
*/
32+
public function should_load_early() {
33+
return true;
34+
}
35+
36+
/**
37+
* Register integration details.
38+
*/
39+
public function register() {
40+
// This is hack based to fix the breaking images, we can reconsider when this is merged https://github.com/tomusborne/wp-show-posts/issues/50
41+
add_filter(
42+
'wpsp_image_attributes',
43+
function ( $attribute ) {
44+
self::$last_attribute = $attribute;
45+
46+
return '';
47+
}
48+
);
49+
add_filter(
50+
'wpsp_default_image_size',
51+
function ( $size ) {
52+
return isset( self::$last_attribute['width'], self::$last_attribute['height'] ) ? [
53+
self::$last_attribute['width'],
54+
self::$last_attribute['height'],
55+
] : 'full';
56+
}
57+
);
58+
}
59+
}

inc/manager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ final class Optml_Manager {
9999
'wpml',
100100
'otter_blocks',
101101
'spectra',
102+
'wpsp',
102103
];
103104
/**
104105
* The current state of the buffer.

0 commit comments

Comments
 (0)