| 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 |
} |
| 67 |
|