File tree Expand file tree Collapse file tree 4 files changed +78
-15
lines changed
assets/src/dashboard/parts/connected/settings Expand file tree Collapse file tree 4 files changed +78
-15
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import {
22
22
} from '@wordpress/components' ;
23
23
24
24
import { useSelect } from '@wordpress/data' ;
25
+ import { useEffect } from '@wordpress/element' ;
25
26
26
27
/**
27
28
* Internal dependencies.
@@ -46,7 +47,6 @@ const Compression = ({
46
47
getSampleRate,
47
48
isLoading
48
49
} = select ( 'optimole' ) ;
49
-
50
50
return {
51
51
sampleImages : getSampleRate ( ) ,
52
52
isLoading : isLoading ( )
@@ -167,6 +167,13 @@ const Compression = ({
167
167
data . compression_mode = value ;
168
168
setSettings ( data ) ;
169
169
} ;
170
+
171
+ useEffect ( ( ) => {
172
+ if ( showSample ) {
173
+ loadSample ( ) ;
174
+ }
175
+ } , [ showSample ] ) ;
176
+
170
177
return (
171
178
< >
172
179
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import Lazyload from './Lazyload';
10
10
import Exclusions from './Exclusions' ;
11
11
import OffloadMedia from './OffloadMedia' ;
12
12
import CloudLibrary from './CloudLibrary' ;
13
- import { sampleRate , saveSettings } from '../../../utils/api' ;
13
+ import { saveSettings } from '../../../utils/api' ;
14
14
import { toggleDamSidebarLink } from '../../../utils/helpers' ;
15
15
16
16
const Settings = ( {
@@ -59,18 +59,7 @@ const Settings = ({
59
59
localStorage . setItem ( 'optimole_settings_visits' , visits ? parseInt ( visits ) + 1 : 1 ) ;
60
60
} , [ tab ] ) ;
61
61
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 = ( ) => {
74
63
setShowSample ( ! showSample ) ;
75
64
} ;
76
65
@@ -165,7 +154,7 @@ const Settings = ({
165
154
< Button
166
155
variant = "default"
167
156
disabled = { isLoading }
168
- onClick = { loadSample }
157
+ onClick = { toggleShowSample }
169
158
>
170
159
{ optimoleDashboardApp . strings . options_strings . view_sample_image }
171
160
</ Button >
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -101,6 +101,7 @@ final class Optml_Manager {
101
101
'spectra ' ,
102
102
'wpsp ' ,
103
103
'jetengine ' ,
104
+ 'jetpack ' ,
104
105
];
105
106
/**
106
107
* The current state of the buffer.
You can’t perform that action at this time.
0 commit comments