Skip to content

Commit 72052ac

Browse files
authored
release: fixes
- Fix compatibility with WP Show Posts plugin
2 parents 62c6c6d + 15013ce commit 72052ac

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

.github/workflows/test-php.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
run: composer phpcs
2525
phpunit:
2626
name: PHPUnit tests on ${{ matrix.php-versions }}
27-
runs-on: ubuntu-latest
27+
runs-on: ubuntu-22.04
2828
strategy:
2929
fail-fast: false
3030
matrix:
@@ -44,8 +44,6 @@ jobs:
4444
php-version: ${{ matrix.php-version }}
4545
extensions: simplexml, mysql
4646
tools: phpunit-polyfills:1.1
47-
- name: Install Subversion
48-
run: sudo apt-get update && sudo apt-get install -y subversion
4947
- name: Checkout source code
5048
uses: actions/checkout@v4
5149
- name: Install WordPress Test Suite

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 a hack 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)