initial
This commit is contained in:
+81
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
namespace Automattic\Jetpack_Boost\Modules\Optimizations\Minify;
|
||||
|
||||
use Automattic\Jetpack\Schema\Schema;
|
||||
use Automattic\Jetpack\WP_JS_Data_Sync\Data_Sync;
|
||||
use Automattic\Jetpack_Boost\Contracts\Has_Activate;
|
||||
use Automattic\Jetpack_Boost\Contracts\Has_Data_Sync;
|
||||
use Automattic\Jetpack_Boost\Contracts\Has_Deactivate;
|
||||
use Automattic\Jetpack_Boost\Contracts\Is_Always_On;
|
||||
use Automattic\Jetpack_Boost\Contracts\Optimization;
|
||||
use Automattic\Jetpack_Boost\Contracts\Sub_Feature;
|
||||
|
||||
class Minify_Common implements Sub_Feature, Optimization, Is_Always_On, Has_Activate, Has_Deactivate, Has_Data_Sync {
|
||||
|
||||
/**
|
||||
* Setup the module. This runs on every page load.
|
||||
*/
|
||||
public function setup() {
|
||||
require_once JETPACK_BOOST_DIR_PATH . '/app/lib/minify/functions-helpers.php';
|
||||
|
||||
jetpack_boost_minify_init();
|
||||
}
|
||||
|
||||
public static function get_slug() {
|
||||
return 'minify_common';
|
||||
}
|
||||
|
||||
public function register_data_sync( Data_Sync $instance ) {
|
||||
$instance->register_readonly(
|
||||
'minify_legacy_notice',
|
||||
Schema::as_unsafe_any(),
|
||||
array( self::class, 'show_legacy_notice' )
|
||||
);
|
||||
}
|
||||
|
||||
public static function is_available() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function show_legacy_notice() {
|
||||
// If the JETPACK_BOOST_DISABLE_404_TESTER is set and true, we don't need to show the legacy notice.
|
||||
if ( defined( 'JETPACK_BOOST_DISABLE_404_TESTER' ) && JETPACK_BOOST_DISABLE_404_TESTER ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If this is a multisite, and the user is not a super admin, don't show the legacy notice, as they won't be able to do anything about it.
|
||||
if ( is_multisite() && ! current_user_can( 'manage_network_options' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the static minfification has not ran yet, don't show the legacy notice.
|
||||
$static_minification_enabled = get_site_option( 'jetpack_boost_static_minification', 'na' );
|
||||
if ( $static_minification_enabled === 'na' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Otherwise show it if the 404 tester determined it can't be used.
|
||||
return ! (bool) $static_minification_enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called when either minify module is activated
|
||||
*/
|
||||
public static function activate() {
|
||||
jetpack_boost_minify_activation();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called when either minify module is deactivated.
|
||||
*/
|
||||
public static function deactivate() {
|
||||
jetpack_boost_minify_clear_scheduled_events();
|
||||
}
|
||||
|
||||
public static function get_parent_features(): array {
|
||||
return array(
|
||||
Minify_JS::class,
|
||||
Minify_CSS::class,
|
||||
);
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Automattic\Jetpack_Boost\Modules\Optimizations\Minify;
|
||||
|
||||
use Automattic\Jetpack\Schema\Schema;
|
||||
use Automattic\Jetpack\WP_JS_Data_Sync\Data_Sync;
|
||||
use Automattic\Jetpack_Boost\Contracts\Changes_Output_After_Activation;
|
||||
use Automattic\Jetpack_Boost\Contracts\Changes_Output_On_Activation;
|
||||
use Automattic\Jetpack_Boost\Contracts\Feature;
|
||||
use Automattic\Jetpack_Boost\Contracts\Has_Data_Sync;
|
||||
use Automattic\Jetpack_Boost\Contracts\Has_Deactivate;
|
||||
use Automattic\Jetpack_Boost\Contracts\Optimization;
|
||||
use Automattic\Jetpack_Boost\Data_Sync\Minify_Excludes_State_Entry;
|
||||
use Automattic\Jetpack_Boost\Lib\Minify\Concatenate_CSS;
|
||||
|
||||
class Minify_CSS implements Feature, Changes_Output_On_Activation, Changes_Output_After_Activation, Optimization, Has_Deactivate, Has_Data_Sync {
|
||||
|
||||
public static $default_excludes = array( 'admin-bar', 'dashicons', 'elementor-app' );
|
||||
|
||||
/**
|
||||
* Setup the module. This runs on every page load.
|
||||
*/
|
||||
public function setup() {
|
||||
if ( jetpack_boost_page_optimize_bail() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_action( 'init', array( $this, 'init_minify' ) );
|
||||
}
|
||||
|
||||
public function register_data_sync( Data_Sync $instance ) {
|
||||
$parser = Schema::as_array( Schema::as_string() )->fallback( self::$default_excludes );
|
||||
|
||||
$instance->register( 'minify_css_excludes', $parser, new Minify_Excludes_State_Entry( 'minify_css_excludes' ) );
|
||||
|
||||
$instance->register_readonly(
|
||||
'minify_css_excludes_default',
|
||||
Schema::as_unsafe_any(),
|
||||
function () {
|
||||
return Minify_CSS::$default_excludes;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static function get_slug() {
|
||||
return 'minify_css';
|
||||
}
|
||||
|
||||
public static function get_change_output_action_names() {
|
||||
return array( 'update_option_' . JETPACK_BOOST_DATASYNC_NAMESPACE . '_minify_css_excludes' );
|
||||
}
|
||||
|
||||
public static function is_available() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function init_minify() {
|
||||
global $wp_styles;
|
||||
|
||||
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
||||
$wp_styles = new Concatenate_CSS( $wp_styles );
|
||||
$wp_styles->allow_gzip_compression = true; // @todo - used constant ALLOW_GZIP_COMPRESSION = true if not defined.
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called only when the module is deactivated.
|
||||
*/
|
||||
public static function deactivate() {
|
||||
jetpack_boost_page_optimize_cleanup_cache( 'css' );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Automattic\Jetpack_Boost\Modules\Optimizations\Minify;
|
||||
|
||||
use Automattic\Jetpack\Schema\Schema;
|
||||
use Automattic\Jetpack\WP_JS_Data_Sync\Data_Sync;
|
||||
use Automattic\Jetpack_Boost\Contracts\Changes_Output_After_Activation;
|
||||
use Automattic\Jetpack_Boost\Contracts\Changes_Output_On_Activation;
|
||||
use Automattic\Jetpack_Boost\Contracts\Feature;
|
||||
use Automattic\Jetpack_Boost\Contracts\Has_Data_Sync;
|
||||
use Automattic\Jetpack_Boost\Contracts\Has_Deactivate;
|
||||
use Automattic\Jetpack_Boost\Contracts\Optimization;
|
||||
use Automattic\Jetpack_Boost\Data_Sync\Minify_Excludes_State_Entry;
|
||||
use Automattic\Jetpack_Boost\Lib\Minify\Concatenate_JS;
|
||||
|
||||
class Minify_JS implements Feature, Changes_Output_On_Activation, Changes_Output_After_Activation, Optimization, Has_Deactivate, Has_Data_Sync {
|
||||
|
||||
public static $default_excludes = array( 'jquery', 'jquery-core', 'underscore', 'backbone' );
|
||||
|
||||
/**
|
||||
* Setup the module. This runs on every page load.
|
||||
*/
|
||||
public function setup() {
|
||||
if ( jetpack_boost_page_optimize_bail() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_action( 'init', array( $this, 'init_minify' ) );
|
||||
}
|
||||
|
||||
public function register_data_sync( Data_Sync $instance ) {
|
||||
$parser = Schema::as_array( Schema::as_string() )->fallback( self::$default_excludes );
|
||||
|
||||
$instance->register( 'minify_js_excludes', $parser, new Minify_Excludes_State_Entry( 'minify_js_excludes' ) );
|
||||
|
||||
$instance->register_readonly(
|
||||
'minify_js_excludes_default',
|
||||
Schema::as_unsafe_any(),
|
||||
function () {
|
||||
return Minify_JS::$default_excludes;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static function get_slug() {
|
||||
return 'minify_js';
|
||||
}
|
||||
|
||||
public static function get_change_output_action_names() {
|
||||
return array( 'update_option_' . JETPACK_BOOST_DATASYNC_NAMESPACE . '_minify_js_excludes' );
|
||||
}
|
||||
|
||||
public static function is_available() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function init_minify() {
|
||||
global $wp_scripts;
|
||||
|
||||
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
||||
$wp_scripts = new Concatenate_JS( $wp_scripts );
|
||||
$wp_scripts->allow_gzip_compression = true; // @todo - used constant ALLOW_GZIP_COMPRESSION = true if not defined.
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called only when the module is deactivated.
|
||||
*/
|
||||
public static function deactivate() {
|
||||
jetpack_boost_page_optimize_cleanup_cache( 'js' );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user