Skip to content

Commit d0e3652

Browse files
authored
Merge pull request #957 from Codeinwp/fix/jetpack
fix: add compatibility with JetPack
2 parents aa390de + fa2a8f6 commit d0e3652

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

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
@@ -100,6 +100,7 @@ final class Optml_Manager {
100100
'otter_blocks',
101101
'spectra',
102102
'wpsp',
103+
'jetpack',
103104
];
104105
/**
105106
* The current state of the buffer.

0 commit comments

Comments
 (0)