add wp-rocket
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
namespace WP_Rocket\Subscriber\Optimization;
|
||||
|
||||
use WP_Rocket\deprecated\DeprecatedClassTrait;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
use WP_Rocket\Admin\Options_Data as Options;
|
||||
use WP_Rocket\Dependencies\Minify;
|
||||
|
||||
/**
|
||||
* HTML minification subscriber
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*/
|
||||
class Minify_HTML_Subscriber implements Subscriber_Interface {
|
||||
use DeprecatedClassTrait;
|
||||
/**
|
||||
* Plugin options
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @var Options
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param Options $options Plugin options.
|
||||
*/
|
||||
public function __construct( Options $options ) {
|
||||
self::deprecated_class( '3.7' );
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of events that this subscriber wants to listen to.
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
return [
|
||||
'rocket_buffer' => [ 'process', 14 ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Minifies HTML
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param string $html HTML content.
|
||||
* @return string
|
||||
*/
|
||||
public function process( $html ) {
|
||||
if ( defined( 'DONOTROCKETOPTIMIZE' ) && DONOTROCKETOPTIMIZE ) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
if ( ! $this->options->get( 'minify_html' ) || \is_rocket_post_excluded_option( 'minify_html' ) ) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
$html_options = [
|
||||
'cssMinifier' => [ $this, 'minify_inline_css' ],
|
||||
];
|
||||
|
||||
/**
|
||||
* Filter options of minify inline HTML
|
||||
*
|
||||
* @since 1.1.12
|
||||
*
|
||||
* @param array $html_options Options of minify inline HTML.
|
||||
*/
|
||||
$html_options = apply_filters( 'rocket_minify_html_options', $html_options );
|
||||
|
||||
return \Minify_HTML::minify( $html, $html_options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Minifies inline CSS
|
||||
*
|
||||
* @since 1.1.6
|
||||
*
|
||||
* @param string $css HTML content.
|
||||
* @return string
|
||||
*/
|
||||
public function minify_inline_css( $css ) {
|
||||
$minify = new Minify\CSS( $css );
|
||||
return $minify->minify();
|
||||
}
|
||||
|
||||
/**
|
||||
* Minifies inline JavaScript
|
||||
*
|
||||
* @since 1.1.6
|
||||
*
|
||||
* @param string $javascript HTML content.
|
||||
* @return string
|
||||
*/
|
||||
public function minify_inline_js( $javascript ) {
|
||||
$minify = new Minify\JS( $javascript );
|
||||
return $minify->minify();
|
||||
}
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace WP_Rocket\Subscriber\Admin\Settings;
|
||||
|
||||
use WP_Rocket\deprecated\DeprecatedClassTrait;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
use WP_Rocket\Admin\Settings\Beacon;
|
||||
|
||||
/**
|
||||
* Beacon Subscriber to WordPress
|
||||
*
|
||||
* @since 3.2
|
||||
* @author Remy Perona
|
||||
*/
|
||||
class Beacon_Subscriber implements Subscriber_Interface {
|
||||
use DeprecatedClassTrait;
|
||||
/**
|
||||
* Beacon instance
|
||||
*
|
||||
* @var Beacon
|
||||
*/
|
||||
private $beacon;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Beacon $beacon Beacon instance.
|
||||
*/
|
||||
public function __construct( Beacon $beacon ) {
|
||||
self::deprecated_class( '3.6' );
|
||||
$this->beacon = $beacon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of events that this subscriber wants to listen to.
|
||||
*
|
||||
* @since 3.2
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
return [
|
||||
'admin_print_footer_scripts-settings_page_wprocket' => 'insert_script',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert HelpScout Beacon script
|
||||
*
|
||||
* @since 3.0
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function insert_script() {
|
||||
echo $this->beacon->insert_script(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user