| @@ -12,9 +12,9 @@ | ||
| 12 | 12 | * Should we load the integration logic. |
| 13 | 13 | * |
| 14 | 14 | * @return bool Should we load. |
| 15 | 15 | */ |
| 16 | - function should_load() { | |
| 16 | + public function should_load() { | |
| 17 | 17 | return ( |
| 18 | 18 | strcmp( wp_get_theme(), 'Divi' ) === 0 || |
| 19 | 19 | is_plugin_active( 'divi-builder/divi-builder.php' ) |
| 20 | 20 | ); |
| @@ -23,8 +23,13 @@ | ||
| 23 | 23 | /** |
| 24 | 24 | * Register integration details. |
| 25 | 25 | */ |
| 26 | 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 | + | |
| 27 | 32 | add_filter( |
| 28 | 33 | 'optml_lazyload_bg_selectors', |
| 29 | 34 | function ( $all_watchers ) { |
| 30 | 35 | $all_watchers[] = '.et_pb_slides > .et_pb_slide'; |
| @@ -29,10 +34,11 @@ | ||
| 29 | 34 | function ( $all_watchers ) { |
| 30 | 35 | $all_watchers[] = '.et_pb_slides > .et_pb_slide'; |
| 31 | 36 | $all_watchers[] = '.et_parallax_bg'; |
| 32 | 37 | $all_watchers[] = '.et_pb_video_overlay'; |
| 33 | - $all_watchers[] = '.et_pb_module:not(.et_pb_blog_grid_wrapper)'; | |
| 38 | + $all_watchers[] = '.et_pb_module:not([class*="et_pb_blog"])'; | |
| 34 | 39 | $all_watchers[] = '.et_pb_row'; |
| 40 | + $all_watchers[] = '.et_pb_section.et_pb_section_1'; | |
| 35 | 41 | $all_watchers[] = '.et_pb_with_background'; |
| 36 | 42 | return $all_watchers; |
| 37 | 43 | } |
| 38 | 44 | ); |
| @@ -37,5 +43,45 @@ | ||
| 37 | 43 | } |
| 38 | 44 | ); |
| 39 | 45 | } |
| 40 | 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 | + } | |
| 41 | 87 | } |