forked from Automattic/nginx-http-concat
-
Notifications
You must be signed in to change notification settings - Fork 1
/
wp-enqueue-masher.php
63 lines (52 loc) · 1.56 KB
/
wp-enqueue-masher.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* Plugin Name: WP Enqueue Masher
* Plugin URI: https://wordpress.org/plugins/wp-enqueue-masher/
* Author: John James Jacoby
* Author URI: https://jjj.blog/
* Version: 0.1.0
* Description: Minify & concatenate enqueued scripts & styles
* License: GPL v2 or later
*/
/**
* This plugin is based on Automattic's nginx-http-concat plugin.
*
* https://github.com/Automattic/nginx-http-concat/
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
// Allow Gzip compression by default
if ( ! defined( 'ALLOW_GZIP_COMPRESSION' ) ) {
define( 'ALLOW_GZIP_COMPRESSION', true );
}
// Allow custom slug (changing this requires nginx restart)
if ( ! defined( 'MASHER_SLUG' ) ) {
define( 'MASHER_SLUG', 's' );
}
// Allow custom slug (changing this requires nginx restart)
if ( ! defined( 'ROOT_DIR' ) ) {
define( 'ROOT_DIR', ABSPATH );
}
/**
* Load the masher
*
* @since 0.1.0
*
* @global WP_CSS_Concat $wp_styles
* @global WP_JS_Concat $wp_scripts
*/
function _wp_enqueue_masher() {
global $wp_styles, $wp_scripts;
// Get include path
$path = plugin_dir_path( __FILE__ ) . 'wp-enqueue-masher/';
// Include files
require_once $path . 'includes/class-wp-css-concat.php';
require_once $path . 'includes/class-wp-js-concat.php';
// Styles
$wp_styles = new WP_CSS_Concat( $wp_styles );
$wp_styles->allow_gzip_compression = ALLOW_GZIP_COMPRESSION;
// Scripts
$wp_scripts = new WP_JS_Concat( $wp_scripts );
$wp_scripts->allow_gzip_compression = ALLOW_GZIP_COMPRESSION;
}
add_action( 'plugins_loaded', '_wp_enqueue_masher', -PHP_INT_MAX );