Skip to content

Commit

Permalink
release: fix
Browse files Browse the repository at this point in the history
- Support for external image replacement should be added in the editor if the domain is allowed.
- Close output buffer on shutdown
- Update dependencies.
  • Loading branch information
selul authored Aug 20, 2024
2 parents b471000 + 0d8c972 commit b3f9a07
Show file tree
Hide file tree
Showing 60 changed files with 628 additions and 464 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.3",
"wp-coding-standards/wpcs": "^2.3.0",
"wp-coding-standards/wpcs": "^3.1.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"yoast/phpunit-polyfills": "^2.0",
"phpstan/phpstan": "^1.10",
Expand All @@ -56,6 +56,6 @@
"php": ">=7.4",
"codeinwp/themeisle-sdk": "^3.3",
"codeinwp/optimole-sdk": "^1.2",
"enshrined/svg-sanitize": "^0.18.0"
"enshrined/svg-sanitize": "^0.19.0"
}
}
566 changes: 377 additions & 189 deletions composer.lock

Large diffs are not rendered by default.

42 changes: 20 additions & 22 deletions inc/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,9 @@ public function register_public_actions() {
add_action( 'wp_enqueue_scripts', [ $this, 'add_diagnosis_script' ] );
}
if ( ! $this->settings->use_lazyload()
|| ( $this->settings->get( 'native_lazyload' ) === 'enabled'
&& $this->settings->get( 'video_lazyload' ) === 'disabled'
&& $this->settings->get( 'bg_replacer' ) === 'disabled' ) ) {
|| ( $this->settings->get( 'native_lazyload' ) === 'enabled'
&& $this->settings->get( 'video_lazyload' ) === 'disabled'
&& $this->settings->get( 'bg_replacer' ) === 'disabled' ) ) {
return;
}
add_action( 'wp_enqueue_scripts', [ $this, 'frontend_scripts' ] );
Expand Down Expand Up @@ -556,7 +556,7 @@ public function inline_bootstrap_script() {
$limit_width = $limit_dimensions ? $this->settings->get( 'limit_width' ) : 0;
$limit_height = $limit_dimensions ? $this->settings->get( 'limit_height' ) : 0;
$retina_ready = $limit_dimensions ||
! ( $this->settings->get( 'retina_images' ) === 'enabled' );
! ( $this->settings->get( 'retina_images' ) === 'enabled' );
$scale_is_disabled = ( $this->settings->get( 'scale' ) === 'enabled' );
$native_lazy_enabled = ( $this->settings->get( 'native_lazyload' ) === 'enabled' );
$output = sprintf(
Expand Down Expand Up @@ -647,7 +647,7 @@ public function add_diagnosis_script() {
*
* @return array Altered links.
*/
function add_action_links( $links ) {
public function add_action_links( $links ) {
if ( ! is_array( $links ) ) {
return $links;
}
Expand Down Expand Up @@ -704,7 +704,7 @@ public function add_notice_upgrade() {
}
?>
<div class="notice optml-notice-optin"
style="background-color: #577BF9; color:white; border: none !important; display: flex;">
style="background-color: #577BF9; color:white; border: none !important; display: flex;">
<div style="margin: 1% 2%;">
<img src='<?php echo OPTML_URL . 'assets/img/upgrade_icon.png'; ?>'>
</div>
Expand All @@ -725,11 +725,11 @@ public function add_notice_upgrade() {
</p>
<p style="margin: 1.5% 0;">
<a href="<?php echo esc_url( tsdk_translate_link( 'https://optimole.com/pricing' ) ); ?>"
target="_blank"
style="border-radius: 4px;padding: 9px 10px;border: 2px solid #FFF;color: white;text-decoration: none;"><?php _e( 'Check upgrade plans', 'optimole-wp' ); ?>
target="_blank"
style="border-radius: 4px;padding: 9px 10px;border: 2px solid #FFF;color: white;text-decoration: none;"><?php _e( 'Check upgrade plans', 'optimole-wp' ); ?>
</a>
<a style="padding: 2%; color: white;"
href="<?php echo wp_nonce_url( add_query_arg( [ 'optml_hide_upg' => 'yes' ] ), 'hide_nonce', 'optml_nonce' ); ?>"><?php _e( 'I have already done this', 'optimole-wp' ); ?></a>
href="<?php echo wp_nonce_url( add_query_arg( [ 'optml_hide_upg' => 'yes' ] ), 'hide_nonce', 'optml_nonce' ); ?>"><?php _e( 'I have already done this', 'optimole-wp' ); ?></a>
</p>
</div>
</div>
Expand All @@ -744,10 +744,10 @@ public function add_notice_upgrade() {
public function should_show_upgrade() {
$current_screen = get_current_screen();
if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ||
is_network_admin() ||
! current_user_can( 'manage_options' ) ||
! $this->settings->is_connected() ||
empty( $current_screen )
is_network_admin() ||
! current_user_can( 'manage_options' ) ||
! $this->settings->is_connected() ||
empty( $current_screen )
) {
return false;
}
Expand Down Expand Up @@ -870,7 +870,7 @@ public function add_notice() {
<div class="notice notice-info optml-notice-optin">
<div class="content">
<img src="<?php echo OPTML_URL . '/assets/img/logo.svg'; ?>"
alt="<?php echo esc_attr__( 'Logo', 'optimole-wp' ); ?>"/>
alt="<?php echo esc_attr__( 'Logo', 'optimole-wp' ); ?>"/>

<div>
<p class="notice-title"> <?php echo esc_html__( 'Finish setting up!', 'optimole-wp' ); ?></p>
Expand All @@ -888,10 +888,10 @@ public function add_notice() {
</p>
<div class="actions">
<a href="<?php echo esc_url( admin_url( 'admin.php?page=optimole' ) ); ?>"
class="button button-primary button-hero"><?php _e( 'Connect to OptiMole', 'optimole-wp' ); ?>
class="button button-primary button-hero"><?php _e( 'Connect to OptiMole', 'optimole-wp' ); ?>
</a>
<a class="button button-secondary button-hero"
href="<?php echo wp_nonce_url( add_query_arg( [ 'optml_hide_optin' => 'yes' ] ), 'hide_nonce', 'optml_nonce' ); ?>"><?php _e( 'I will do it later', 'optimole-wp' ); ?>
href="<?php echo wp_nonce_url( add_query_arg( [ 'optml_hide_optin' => 'yes' ] ), 'hide_nonce', 'optml_nonce' ); ?>"><?php _e( 'I will do it later', 'optimole-wp' ); ?>
</a>
</div>
</div>
Expand Down Expand Up @@ -924,7 +924,7 @@ public function add_notice_conflicts() {
<div class="notice notice-info optml-notice-optin has-dismiss">
<div class="content">
<img src="<?php echo OPTML_URL . '/assets/img/logo.svg'; ?>"
alt="<?php echo esc_attr__( 'Logo', 'optimole-wp' ); ?>"/>
alt="<?php echo esc_attr__( 'Logo', 'optimole-wp' ); ?>"/>

<div>
<p class="notice-title">
Expand All @@ -943,7 +943,7 @@ public function add_notice_conflicts() {
</p>
<div class="actions">
<a href="<?php echo esc_url( admin_url( 'plugins.php?optimole_conflicts' ) ); ?>"
class="button button-primary button-hero"><?php _e( 'Manage Plugins', 'optimole-wp' ); ?>
class="button button-primary button-hero"><?php _e( 'Manage Plugins', 'optimole-wp' ); ?>
</a>
</div>
</div>
Expand Down Expand Up @@ -1006,7 +1006,6 @@ public function frontend_scripts() {
';
wp_add_inline_script( 'optml-print', $script );
}

}

/**
Expand Down Expand Up @@ -1059,7 +1058,7 @@ public function generator() {
/**
* Update daily the quota routine.
*/
function daily_sync() {
public function daily_sync() {

$api_key = $this->settings->get( 'api_key' );
$service_data = $this->settings->get( 'service_data' );
Expand Down Expand Up @@ -1093,7 +1092,6 @@ function daily_sync() {
}

remove_filter( 'optml_dont_trigger_settings_updated', '__return_true' );

}

/**
Expand All @@ -1106,7 +1104,7 @@ function daily_sync() {
*/
public function add_dns_prefetch( $hints, $relation_type ) {
if ( 'dns-prefetch' !== $relation_type &&
'preconnect' !== $relation_type
'preconnect' !== $relation_type
) {
return $hints;
}
Expand Down
11 changes: 5 additions & 6 deletions inc/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ public function request( $path, $method = 'GET', $params = [], $extra_headers =
}

return $response['data'];

}

/**
Expand Down Expand Up @@ -256,7 +255,7 @@ private function build_args( $method, $url, $headers, $params ) {
* @return bool Whether or not the url is valid.
*/
public function check_optimized_url( $url ) {
$response = wp_remote_get( $url, ['timeout' => 30] );
$response = wp_remote_get( $url, [ 'timeout' => 30 ] );

if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 || ! empty( wp_remote_retrieve_header( $response, 'x-not-found-o' ) ) ) {
$this->log_offload_error( $response );
Expand Down Expand Up @@ -304,7 +303,7 @@ public function call_onboard_api( $images = [] ) {
* @return array
*/
public function call_data_enrich_api( $images = [] ) {
return $this->request( 'optml/v2/media/add_data', 'POST', ['images' => $images, 'key' => Optml_Config::$key] );
return $this->request( 'optml/v2/media/add_data', 'POST', [ 'images' => $images, 'key' => Optml_Config::$key ] );
}
/**
* Register user remotely on optimole.com.
Expand Down Expand Up @@ -343,7 +342,7 @@ public function get_optimized_images( $api_key = '' ) {
if ( isset( $service_data['cdn_key'] ) ) {
$app_key = $service_data['cdn_key'];
}
return $this->request( '/optml/v1/stats/images', 'GET', [], ['application' => $app_key] );
return $this->request( '/optml/v1/stats/images', 'GET', [], [ 'application' => $app_key ] );
}

/**
Expand Down Expand Up @@ -409,7 +408,7 @@ public function add_watermark( $file ) {
*/
public function get_cloud_images( $page = 0, $domains = [], $search = '' ) {

$params = ['key' => Optml_Config::$key ];
$params = [ 'key' => Optml_Config::$key ];
$params['page'] = $page;
$params['size'] = 40;
if ( $search !== '' ) {
Expand Down Expand Up @@ -447,7 +446,7 @@ public function log_offload_error( $error_response ) {
wp_remote_post(
$this->upload_conflicts_api,
[
'headers' => [ 'Content-Type' => 'application/json' ],
'headers' => [ 'Content-Type' => 'application/json' ],
'timeout' => 15,
'blocking' => true,
'sslverify' => false,
Expand Down
8 changes: 4 additions & 4 deletions inc/app_replacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
abstract class Optml_App_Replacer {
use Optml_Dam_Offload_Utils;

/**
* Filters used for lazyload.
*
Expand Down Expand Up @@ -198,7 +199,7 @@ public static function possible_tag_flags() {

self::$ignore_tag_strings = apply_filters( 'optml_skip_optimizations_css_classes', [ 'skip-optimization' ] );

return self::$ignore_tag_strings;
return self::$ignore_tag_strings;
}
/**
* Returns possible data-opt-src ignore flags attributes.
Expand Down Expand Up @@ -257,7 +258,6 @@ public static function add_size( $width = null, $height = null, $crop = null ) {
'enlarge' => true,
'crop' => $crop,
];

}

/**
Expand Down Expand Up @@ -335,7 +335,7 @@ public function init() {
self::$filters = $this->settings->get_filters();
add_filter(
'optml_should_avif_ext',
function( $should_avif, $ext ) {
function ( $should_avif, $ext ) {
return $ext !== 'svg';
},
10,
Expand Down Expand Up @@ -481,7 +481,7 @@ public function get_upload_resource() {
*
* @return mixed Original value.
*/
static function listen_to_sizes( $value, $orig_w, $orig_h, $dest_w, $dest_h, $crop ) {
public static function listen_to_sizes( $value, $orig_w, $orig_h, $dest_w, $dest_h, $crop ) {
self::add_size( $dest_w, $dest_h, $crop );

return $value;
Expand Down
1 change: 0 additions & 1 deletion inc/attachment_cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public static function set_cached_attachment_id( $url, $id ) {
wp_using_ext_object_cache()
? wp_cache_set( $cache_key, $id, self::CACHE_GROUP, $expiration )
: set_transient( self::CACHE_GROUP . $cache_key, $id, $expiration );

}

/**
Expand Down
3 changes: 1 addition & 2 deletions inc/cli/cli_media.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@ private function update_images_template( $action ) {
}

$progress->tick();
$tick++;
++$tick;
}
$progress->finish();
WP_CLI::line( $strings[ $action ]['success'] );
}
}

5 changes: 2 additions & 3 deletions inc/compatibilities/beaver_builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class Optml_beaver_builder extends Optml_compatibility {
*
* @return bool Should we load.
*/
function should_load() {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
public function should_load() {
include_once ABSPATH . 'wp-admin/includes/plugin.php';

return is_plugin_active( 'bb-plugin/fl-builder.php' ) || is_plugin_active( 'beaver-builder-lite-version/fl-builder.php' );
}
Expand All @@ -35,5 +35,4 @@ function ( $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 );
}

}
6 changes: 2 additions & 4 deletions inc/compatibilities/cache_enabler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class Optml_cache_enabler extends Optml_compatibility {
*
* @return bool Should we load.
*/
function should_load() {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
public function should_load() {
include_once ABSPATH . 'wp-admin/includes/plugin.php';

return is_plugin_active( 'cache-enabler/cache-enabler.php' );
}
Expand All @@ -32,7 +32,6 @@ function () {
do_action( 'cache_enabler_clear_site_cache' );
}
);

}

/**
Expand All @@ -43,5 +42,4 @@ function () {
public function should_load_early() {
return true;
}

}
6 changes: 3 additions & 3 deletions inc/compatibilities/compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ abstract class Optml_compatibility {
/**
* Register compatibility actions/filters.
*/
abstract function register();
abstract public function register();

/**
* Should we load the compatibility?
*
* @return bool Compatiblity
*/
abstract function should_load();
abstract public function should_load();

/**
* Will the compatibility be loaded?
*
* @return bool
*/
public final function will_load() {
final public function will_load() {
if ( ! Optml_Main::instance()->admin->settings->is_connected() ) {
return false;
}
Expand Down
16 changes: 8 additions & 8 deletions inc/compatibilities/divi_builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Optml_divi_builder extends Optml_compatibility {
*
* @return bool Should we load.
*/
function should_load() {
public function should_load() {
return (
strcmp( wp_get_theme(), 'Divi' ) === 0 ||
is_plugin_active( 'divi-builder/divi-builder.php' )
Expand All @@ -25,9 +25,9 @@ function should_load() {
*/
public function register() {

add_action( 'et_core_static_file_created', [$this, 'optimize_divi_static_files'] );
add_action( 'et_core_static_file_created', [ $this, 'optimize_divi_static_files' ] );

add_action( 'optml_settings_updated', [$this, 'clear_divi_static_files'] );
add_action( 'optml_settings_updated', [ $this, 'clear_divi_static_files' ] );

add_filter(
'optml_lazyload_bg_selectors',
Expand All @@ -47,17 +47,17 @@ function ( $all_watchers ) {
/**
* Replace image urls upon divi's static css files creation
*
* @param ET_Core_PageResource $resource ET_Core_PageResource object.
* @param ET_Core_PageResource $page_resource ET_Core_PageResource object.
* @return void
*/
public function optimize_divi_static_files( $resource ) {
public function optimize_divi_static_files( $page_resource ) {
if ( class_exists( 'ET_Core_PageResource' ) && null !== ET_Core_PageResource::$wpfs ) {
if ( isset( $resource->path ) ) {
$data = $resource->get_data( 'file' );
if ( isset( $page_resource->path ) ) {
$data = $page_resource->get_data( 'file' );

if ( ! empty( $data ) ) {
$data = Optml_Main::instance()->manager->replace_content( $data );
ET_Core_PageResource::$wpfs->put_contents( $resource->path, $data, 0644 );
ET_Core_PageResource::$wpfs->put_contents( $page_resource->path, $data, 0644 );
}
}
}
Expand Down
Loading

0 comments on commit b3f9a07

Please sign in to comment.