Skip to content

Commit 3986b1e

Browse files
authored
Merge branch 'development' into fix/jetengine-comp
2 parents 9bbafa5 + d0e3652 commit 3986b1e

File tree

4 files changed

+78
-15
lines changed

4 files changed

+78
-15
lines changed

assets/src/dashboard/parts/connected/settings/Compression.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
} from '@wordpress/components';
2323

2424
import { useSelect } from '@wordpress/data';
25+
import { useEffect } from '@wordpress/element';
2526

2627
/**
2728
* Internal dependencies.
@@ -46,7 +47,6 @@ const Compression = ({
4647
getSampleRate,
4748
isLoading
4849
} = select( 'optimole' );
49-
5050
return {
5151
sampleImages: getSampleRate(),
5252
isLoading: isLoading()
@@ -167,6 +167,13 @@ const Compression = ({
167167
data.compression_mode = value;
168168
setSettings( data );
169169
};
170+
171+
useEffect( () => {
172+
if ( showSample ) {
173+
loadSample();
174+
}
175+
}, [ showSample ]);
176+
170177
return (
171178
<>
172179

assets/src/dashboard/parts/connected/settings/index.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Lazyload from './Lazyload';
1010
import Exclusions from './Exclusions';
1111
import OffloadMedia from './OffloadMedia';
1212
import CloudLibrary from './CloudLibrary';
13-
import { sampleRate, saveSettings } from '../../../utils/api';
13+
import { saveSettings } from '../../../utils/api';
1414
import { toggleDamSidebarLink } from '../../../utils/helpers';
1515

1616
const Settings = ({
@@ -59,18 +59,7 @@ const Settings = ({
5959
localStorage.setItem( 'optimole_settings_visits', visits ? parseInt( visits ) + 1 : 1 );
6060
}, [ tab ]);
6161

62-
const loadSample = () => {
63-
if ( ! showSample ) {
64-
setIsSampleLoading( true );
65-
66-
sampleRate(
67-
{
68-
quality: settings.quality
69-
},
70-
() => setIsSampleLoading( false )
71-
);
72-
}
73-
62+
const toggleShowSample = () => {
7463
setShowSample( ! showSample );
7564
};
7665

@@ -165,7 +154,7 @@ const Settings = ({
165154
<Button
166155
variant="default"
167156
disabled={ isLoading }
168-
onClick={ loadSample }
157+
onClick={ toggleShowSample }
169158
>
170159
{ optimoleDashboardApp.strings.options_strings.view_sample_image }
171160
</Button>

inc/compatibilities/jetpack.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
/**
4+
* Class Optml_jetpack
5+
*
6+
* @reason Add support for Jetpack plugin custom endpoints.
7+
*/
8+
class Optml_jetpack extends Optml_compatibility {
9+
10+
/**
11+
* Should we load the integration logic.
12+
*
13+
* @return bool Should we load.
14+
*/
15+
public function should_load() {
16+
include_once ABSPATH . 'wp-admin/includes/plugin.php';
17+
18+
return is_plugin_active( 'jetpack/jetpack.php' );
19+
}
20+
21+
/**
22+
* Register integration details.
23+
*
24+
* @return void
25+
*/
26+
public function register() {
27+
add_filter(
28+
'jetpack_sync_before_send_jetpack_published_post',
29+
function ( $data ) {
30+
if ( ! is_array( $data ) ) {
31+
return $data;
32+
}
33+
34+
foreach ( $data as &$value ) {
35+
if ( ! $value instanceof \WP_Post ) {
36+
continue;
37+
}
38+
39+
if ( ! empty( $value->post_content ) ) {
40+
$value->post_content = Optml_Main::instance()->manager->replace_content( $value->post_content );
41+
}
42+
43+
if ( ! empty( $value->post_excerpt ) ) {
44+
$value->post_excerpt = Optml_Main::instance()->manager->replace_content( $value->post_excerpt );
45+
}
46+
47+
if ( isset( $value->featured_image ) && ! empty( $value->featured_image ) ) {
48+
$value->featured_image = apply_filters( 'optml_content_url', $value->featured_image );
49+
}
50+
}
51+
52+
return $data;
53+
},
54+
10
55+
);
56+
}
57+
58+
/**
59+
* Should we early load the compatibility?
60+
*
61+
* @return bool Whether to load the compatibility or not.
62+
*/
63+
public function should_load_early() {
64+
return true;
65+
}
66+
}

inc/manager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ final class Optml_Manager {
101101
'spectra',
102102
'wpsp',
103103
'jetengine',
104+
'jetpack',
104105
];
105106
/**
106107
* The current state of the buffer.

0 commit comments

Comments
 (0)