| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Class Optml_thrive. |
| 5 |
* |
| 6 |
* @reason @reason Adding selectors for background lazyload |
| 7 |
*/ |
| 8 |
class Optml_thrive extends Optml_compatibility { |
| 9 |
|
| 10 |
|
| 11 |
/** |
| 12 |
* Should we load the integration logic. |
| 13 |
* |
| 14 |
* @return bool Should we load. |
| 15 |
*/ |
| 16 |
function should_load() { |
| 17 |
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 18 |
|
| 19 |
return is_plugin_active( 'thrive-visual-editor/thrive-visual-editor.php' ); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Register integration details. |
| 24 |
*/ |
| 25 |
public function register() { |
| 26 |
add_filter( |
| 27 |
'optml_lazyload_bg_selectors', |
| 28 |
function ( $all_watchers ) { |
| 29 |
$all_watchers[] = '.tve-content-box-background'; |
| 30 |
$all_watchers[] = '.tve-page-section-out'; |
| 31 |
$all_watchers[] = '.thrv_text_element'; |
| 32 |
|
| 33 |
return $all_watchers; |
| 34 |
} |
| 35 |
); |
| 36 |
if ( Optml_Main::instance()->admin->settings->get( 'offload_media' ) === 'enabled' ) { |
| 37 |
add_action( 'optml_updated_post', [$this, 'update_trive_postmeta'], 1, 1 ); |
| 38 |
} |
| 39 |
|
| 40 |
} |
| 41 |
/** |
| 42 |
* Update tve_updated_post meta with the correct status for images: offloaded/rollback. |
| 43 |
* |
| 44 |
* @param int $post_id The post id to be updated. |
| 45 |
*/ |
| 46 |
public function update_trive_postmeta( $post_id ) { |
| 47 |
|
| 48 |
$post_meta = tve_get_post_meta( $post_id, 'tve_updated_post' ); |
| 49 |
|
| 50 |
$content = Optml_Media_Offload::instance()->filter_uploaded_images( ['post_content' => $post_meta ] ); |
| 51 |
|
| 52 |
tve_update_post_meta( $post_id, 'tve_updated_post', $content['post_content'] ); |
| 53 |
} |
| 54 |
/** |
| 55 |
* Should we early load the compatibility? |
| 56 |
* |
| 57 |
* @return bool Whether to load the compatibility or not. |
| 58 |
*/ |
| 59 |
public function should_load_early() { |
| 60 |
return true; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
|