Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions inc/compatibilities/beaver_builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,18 @@ function ( $all_watchers ) {
return $all_watchers;
}
);
add_filter( 'fl_builder_render_css', [ Optml_Main::instance()->manager, 'replace_content' ], PHP_INT_MAX, 1 );
add_filter( 'fl_builder_render_js', [ Optml_Main::instance()->manager, 'replace_content' ], PHP_INT_MAX, 1 );
add_filter( 'fl_builder_render_css', [ $this, 'replace_static_content' ], PHP_INT_MAX, 1 );
add_filter( 'fl_builder_render_js', [ $this, 'replace_static_content' ], PHP_INT_MAX, 1 );
}

/**
* Replace urls in static content.
*
* @param string $content Content to replace.
*
* @return string Altered content.
*/
public function replace_static_content( $content ) {
return Optml_Main::instance()->manager->replace_content( $content, true );
}
}
2 changes: 1 addition & 1 deletion inc/compatibilities/divi_builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function optimize_divi_static_files( $page_resource ) {
$data = $page_resource->get_data( 'file' );

if ( ! empty( $data ) ) {
$data = Optml_Main::instance()->manager->replace_content( $data );
$data = Optml_Main::instance()->manager->replace_content( $data, true );
ET_Core_PageResource::$wpfs->put_contents( $page_resource->path, $data, 0644 );
}
}
Expand Down
2 changes: 1 addition & 1 deletion inc/compatibilities/elementor_builder_late.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function replace_meta( $metadata, $object_id, $meta_key, $single ) {
return $metadata;
}

return Optml_Main::instance()->manager->replace_content( $current_meta );
return Optml_Main::instance()->manager->replace_content( $current_meta, true );
}

// Return original if the check does not pass
Expand Down
6 changes: 3 additions & 3 deletions inc/compatibilities/facetwp.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function api_replacement_filter( $output, $data ) {
$output = json_decode( $output );

if ( isset( $output->template ) ) {
$output->template = Optml_Main::instance()->manager->replace_content( $output->template );
$output->template = Optml_Main::instance()->manager->replace_content( $output->template, true );
}

// Ignore invalid UTF-8 characters in PHP 7.2+
Expand All @@ -48,7 +48,7 @@ public function api_replacement_filter( $output, $data ) {
} else {
$output = json_encode( $output, JSON_INVALID_UTF8_IGNORE );
}
$output = Optml_Main::instance()->manager->replace_content( $output );
$output = Optml_Main::instance()->manager->replace_content( $output, true );
return $output;
}
/**
Expand All @@ -65,7 +65,7 @@ public function api_replacement_action( $output ) {
if ( ! isset( $output['template'] ) || ! function_exists( 'FWP' ) ) {
return;
}
$output['template'] = Optml_Main::instance()->manager->replace_content( $output['template'] );
$output['template'] = Optml_Main::instance()->manager->replace_content( $output['template'], true );
FWP()->request->output = $output;
}
/**
Expand Down
7 changes: 6 additions & 1 deletion inc/compatibilities/yith_quick_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ public function should_load() {
*/
public function register() {
Optml_Url_Replacer::instance()->init();
add_filter( 'woocommerce_single_product_image_thumbnail_html', [ Optml_Main::instance()->manager, 'replace_content' ] );
add_filter(
'woocommerce_single_product_image_thumbnail_html',
function ( $html ) {
return Optml_Main::instance()->manager->replace_content( $html, true );
}
);
}

/**
Expand Down
29 changes: 17 additions & 12 deletions inc/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,15 +409,16 @@ public function register_after_setup() {
* Filter raw HTML content for urls.
*
* @param string $html HTML to filter.
* @param bool $partial If this is a partial content replacement and not a full page. It matters when we are are doing full page optimization like viewport lazyload.
*
* @return mixed Filtered content.
*/
public function replace_content( $html ) {
public function replace_content( $html, $partial = false ) {

if ( defined( 'REST_REQUEST' ) && REST_REQUEST && is_user_logged_in() && ( apply_filters( 'optml_force_replacement', false ) !== true ) ) {
return $html;
}
if ( $this->settings->is_lazyload_type_viewport() ) {
if ( $this->settings->is_lazyload_type_viewport() && ! $partial ) {
$profile_id = Profile::generate_id( $html );
// We disable the optimizer for logged in users.
if ( ! is_user_logged_in() || ! apply_filters( 'optml_force_page_profiler', false ) !== true ) {
Expand All @@ -442,7 +443,9 @@ public function replace_content( $html ) {
Profile::set_current_profile_id( $profile_id );
$this->page_profiler->set_current_profile_data();
}
$html = $this->add_html_class( $html );
if ( ! $partial ) {
$html = $this->add_html_class( $html );
}

$html = $this->process_images_from_content( $html );

Expand All @@ -457,7 +460,7 @@ public function replace_content( $html ) {
}
}

if ( $this->settings->is_lazyload_type_viewport() ) {
if ( $this->settings->is_lazyload_type_viewport() && ! $partial ) {
$personalized_bg_css = Lazyload::get_current_personalized_css();
if ( OPTML_DEBUG ) {
do_action( 'optml_log', 'viewport_bgselectorsdata: ' . print_r( $personalized_bg_css, true ) );
Expand All @@ -475,22 +478,24 @@ public function replace_content( $html ) {
}
}
}
// WE need this last since during bg personalized CSS we collect preload urls
if ( Links::get_links_count() > 0 ) {
if ( OPTML_DEBUG ) {
do_action( 'optml_log', 'preload_links: ' . print_r( Links::get_links(), true ) );
if ( ! $partial ) {
// WE need this last since during bg personalized CSS we collect preload urls
if ( Links::get_links_count() > 0 ) {
if ( OPTML_DEBUG ) {
do_action( 'optml_log', 'preload_links: ' . print_r( Links::get_links(), true ) );
}
$html = str_replace( Optml_Admin::get_preload_links_placeholder(), Links::get_links_html(), $html );
} else {
$html = str_replace( Optml_Admin::get_preload_links_placeholder(), '', $html );
}
$html = str_replace( Optml_Admin::get_preload_links_placeholder(), Links::get_links_html(), $html );
} else {
$html = str_replace( Optml_Admin::get_preload_links_placeholder(), '', $html );
}

$html = apply_filters( 'optml_url_pre_process', $html );

$html = $this->process_urls_from_content( $html );

$html = apply_filters( 'optml_url_post_process', $html );
if ( $this->settings->is_lazyload_type_viewport() ) {
if ( $this->settings->is_lazyload_type_viewport() && ! $partial ) {
Profile::reset_current_profile();
}
return $html;
Expand Down
Loading