| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Class Optml_divi_builder |
| 5 |
* |
| 6 |
* @reason Adding selectors for background lazyload |
| 7 |
*/ |
| 8 |
class Optml_divi_builder extends Optml_compatibility { |
| 9 |
|
| 10 |
|
| 11 |
/** |
| 12 |
* Should we load the integration logic. |
| 13 |
* |
| 14 |
* @return bool Should we load. |
| 15 |
*/ |
| 16 |
public function should_load() { |
| 17 |
return ( |
| 18 |
strcmp( wp_get_theme(), 'Divi' ) === 0 || |
| 19 |
is_plugin_active( 'divi-builder/divi-builder.php' ) |
| 20 |
); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Register integration details. |
| 25 |
*/ |
| 26 |
public function register() { |
| 27 |
|
| 28 |
add_action( 'et_core_static_file_created', [ $this, 'optimize_divi_static_files' ] ); |
| 29 |
|
| 30 |
add_action( 'optml_settings_updated', [ $this, 'clear_divi_static_files' ] ); |
| 31 |
|
| 32 |
add_filter( |
| 33 |
'optml_lazyload_bg_selectors', |
| 34 |
function ( $all_watchers ) { |
| 35 |
$all_watchers[] = '.et_pb_slides > .et_pb_slide'; |
| 36 |
$all_watchers[] = '.et_parallax_bg'; |
| 37 |
$all_watchers[] = '.et_pb_video_overlay'; |
| 38 |
$all_watchers[] = '.et_pb_module:not([class*="et_pb_blog"])'; |
| 39 |
$all_watchers[] = '.et_pb_row'; |
| 40 |
$all_watchers[] = '.et_pb_section.et_pb_section_1'; |
| 41 |
$all_watchers[] = '.et_pb_with_background'; |
| 42 |
return $all_watchers; |
| 43 |
} |
| 44 |
); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Replace image urls upon divi's static css files creation |
| 49 |
* |
| 50 |
* @param ET_Core_PageResource $page_resource ET_Core_PageResource object. |
| 51 |
* @return void |
| 52 |
*/ |
| 53 |
public function optimize_divi_static_files( $page_resource ) { |
| 54 |
if ( class_exists( 'ET_Core_PageResource' ) && null !== ET_Core_PageResource::$wpfs ) { |
| 55 |
if ( isset( $page_resource->path ) ) { |
| 56 |
$data = $page_resource->get_data( 'file' ); |
| 57 |
|
| 58 |
if ( ! empty( $data ) ) { |
| 59 |
$data = Optml_Main::instance()->manager->replace_content( $data, true ); |
| 60 |
ET_Core_PageResource::$wpfs->put_contents( $page_resource->path, $data, 0644 ); |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Clear divi static files when plugin settings are changed |
| 68 |
* |
| 69 |
* @return void |
| 70 |
*/ |
| 71 |
public function clear_divi_static_files() { |
| 72 |
|
| 73 |
if ( class_exists( 'ET_Core_PageResource' ) && method_exists( ET_Core_PageResource::class, 'remove_static_resources' ) ) { |
| 74 |
// same call as in et_core_page_resource_auto_clear but that function is not declared at this point |
| 75 |
ET_Core_PageResource::remove_static_resources( 'all', 'all' ); |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Should we early load the compatibility? |
| 81 |
* |
| 82 |
* @return bool Whether to load the compatibility or not. |
| 83 |
*/ |
| 84 |
public function should_load_early() { |
| 85 |
return true; |
| 86 |
} |
| 87 |
} |
| 88 |
|