PluginProbe
WP Super Minify • Minify, Compress and Cache HTML, CSS & JavaScript / 1.5
WP Super Minify • Minify, Compress and Cache HTML, CSS & JavaScript v1.5
trunk 1.0 1.1 1.2 1.3 1.3.1 1.3.2 1.4 1.5 1.5.1 1.6 2.0 2.0.1
wp-super-minify / wp-super-minify.php

wp-super-minify.php in WP Super Minify • Minify, Compress and Cache HTML, CSS & JavaScript 1.5, at wp-super-minify.php

235 lines 11.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: WP Super Minify
4 Plugin URI: https://github.com/dipakcg/wp-super-minify
5 Description: Minifies, caches and combine inline JavaScript and CSS files to improve page load time.
6 Version: 1.5
7 Author: Dipak C. Gajjar
8 Author URI: https://dipakgajjar.com
9 */
10
11 // Define plugin version for future releases
12 if (!defined('WPSMY_PLUGIN_VERSION')) {
13 define('WPSMY_PLUGIN_VERSION', 'wpsmy_plugin_version');
14 }
15 if (!defined('WPSMY_PLUGIN_VERSION_NUM')) {
16 define('WPSMY_PLUGIN_VERSION_NUM', '1.5');
17 }
18 update_option(WPSMY_PLUGIN_VERSION, WPSMY_PLUGIN_VERSION_NUM);
19
20 // Register with hook 'wp_enqueue_scripts', which can be used for front end CSS and JavaScript
21 add_action( 'admin_init', 'wpsmy_add_stylesheet' );
22 function wpsmy_add_stylesheet() {
23 // Respects SSL, Style.css is relative to the current file
24 wp_register_style( 'wpsmy-stylesheet', plugins_url('assets/css/style.min.css', __FILE__) );
25 wp_enqueue_style( 'wpsmy-stylesheet' );
26 }
27
28 // Register admin menu
29 add_action( 'admin_menu', 'wpsmy_add_admin_menu' );
30 function wpsmy_add_admin_menu() {
31 // add_menu_page( 'WP Super Minify Settings', 'WP Super Minify', 'manage_options', 'wp-super-minify', 'wpsmy_admin_options', plugins_url('assets/images/wpsmy-icon-24x24.png', __FILE__) );
32 // add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function);
33 add_options_page( 'WP Super Minify', 'WP Super Minify', 'manage_options', 'wp-super-minify', 'wpsmy_admin_options' );
34 }
35
36 // Add settings link on plugin page
37 function wpsmy_settings_link($links) {
38 // $settings_link = '<a href="admin.php?page=wp-performance-score-booster">Settings</a>';
39 $settings_link = '<a href="options-general.php?page=wp-super-minify">Settings</a>';
40 array_unshift($links, $settings_link);
41 return $links;
42 }
43 $plugin = plugin_basename(__FILE__);
44 add_filter("plugin_action_links_$plugin", 'wpsmy_settings_link' );
45
46 // Adding WordPress plugin meta links
47 function wpsmy_plugin_meta_links( $links, $file ) {
48 $plugin = plugin_basename(__FILE__);
49 // Create link
50 if ( $file == $plugin ) {
51 return array_merge(
52 $links,
53 array( '<a href="https://dipakgajjar.com/products/wordpress-speed-optimisation-service?utm_source=plugins%20page&utm_medium=text%20link&utm_campaign=wordplress%20plugins" style="color:#FF0000;" target="_blank">Order WordPress Speed Optimisation Service</a>' )
54 );
55 }
56 return $links;
57 }
58 add_filter( 'plugin_row_meta', 'wpsmy_plugin_meta_links', 10, 2 );
59
60 // Admin options/setting page
61 function wpsmy_admin_options() {
62 ?>
63 <div class="wrap">
64 <table width="100%" border="0">
65 <tr>
66 <td width="75%">
67 <h2><?php echo '<img src="' . plugins_url( 'assets/images/wpsmy-icon-24x24.png' , __FILE__ ) . '" > '; ?> WP Super Minify : Settings</h2>
68 <hr />
69 <?php
70 if ( !current_user_can( 'manage_options' ) ) {
71 wp_die( __('You do not have sufficient permissions to access this page.') );
72 }
73
74 // Variables for the field and option names
75 $hidden_field_name = 'wpsmy_submit_hidden';
76 $combine_js = 'wpsmy_combine_js';
77 $combine_css = 'wpsmy_combine_css';
78
79 // Read in existing option value from database
80 $combine_js_val = get_option($combine_js);
81 $combine_css_val = get_option($combine_css);
82
83 // See if the user has posted us some information
84 // If they did, this hidden field will be set to 'Y'
85 if( isset($_POST[$hidden_field_name]) && $_POST[$hidden_field_name] == 'Y' ) {
86 // Read their posted value
87 $combine_js_val = (isset($_POST[$combine_js]) ? $_POST[$combine_js] : "");
88 $combine_css_val = (isset($_POST[$combine_css]) ? $_POST[$combine_css] : "");
89
90 // Save the posted value in the database
91 update_option( $combine_js, $combine_js_val );
92 update_option( $combine_css, $combine_css_val );
93
94 // Put an settings updated message on the screen
95 ?>
96 <div class="updated"><p><strong>Settings Saved.</strong></p></div>
97 <?php
98 }
99 ?>
100 <form method="post" name="options_form">
101 <input type="hidden" name="<?php echo $hidden_field_name; ?>" value="Y">
102 <p>
103 <input type="checkbox" name="<?php echo $combine_js; ?>" id="<?php echo $combine_js; ?>" <?php checked( $combine_js_val == 'on',true); ?> />
104 <label for="<?php echo $combine_js; ?>" class="wpsmy_settings" style="display: inline;"> <?php _e('Compress JavaScript'); ?> </label>
105 </p>
106 <p>
107 <input type="checkbox" name="<?php echo $combine_css; ?>" id="<?php echo $combine_css; ?>" <?php checked( $combine_css_val == 'on',true); ?> />
108 <label for="<?php echo $combine_css; ?>" class="wpsmy_settings" style="display: inline;"> <?php _e('Compress CSS'); ?> </label>
109 </p>
110 <p><input type="submit" value="<?php esc_attr_e('Save Changes') ?>" class="button button-primary" name="submit" />
111 </p>
112 </form>
113 </td>
114 <td style="text-align: left;">
115 <div class="wpsmy_admin_dev_sidebar_div">
116 <!-- <img src="//www.gravatar.com/avatar/38b380cf488d8f8c4007cf2015dc16ac.jpg" width="100px" height="100px" /> -->
117 <br />
118 <span class="wpsmy_admin_dev_sidebar"> <?php echo '<img src="' . plugins_url( 'assets/images/wpsmy-support-this-16x16.png' , __FILE__ ) . '" > '; ?> <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3S8BRPLWLNQ38" target="_blank"> Donate and support this plugin </a> </span>
119 <span class="wpsmy_admin_dev_sidebar"> <?php echo '<img src="' . plugins_url( 'assets/images/wpsmy-rate-this-16x16.png' , __FILE__ ) . '" > '; ?> <a href="http://wordpress.org/support/view/plugin-reviews/wp-super-minify" target="_blank"> Rate this plugin on WordPress.org </a> </span>
120 <span class="wpsmy_admin_dev_sidebar"> <?php echo '<img src="' . plugins_url( 'assets/images/wpsmy-wordpress-16x16.png' , __FILE__ ) . '" > '; ?> <a href="http://wordpress.org/support/plugin/wp-super-minify" target="_blank"> Get support on WordPress.org </a> </span>
121 <span class="wpsmy_admin_dev_sidebar"> <?php echo '<img src="' . plugins_url( 'assets/images/wpsmy-github-16x16.png' , __FILE__ ) . '" > '; ?> <a href="https://github.com/dipakcg/wp-super-minify" target="_blank"> Contribute development on GitHub </a> </span>
122 <span class="wpsmy_admin_dev_sidebar"> <?php echo '<img src="' . plugins_url( 'assets/images/wpsmy-other-plugins-16x16.png' , __FILE__ ) . '" > '; ?> <a href="http://profiles.wordpress.org/dipakcg#content-plugins" target="_blank"> Get my other plugins </a> </span>
123 <span class="wpsmy_admin_dev_sidebar"> <?php echo '<img src="' . plugins_url( 'assets/images/wpsmy-twitter-16x16.png' , __FILE__ ) . '" > '; ?>Follow me on Twitter: <a href="https://twitter.com/dipakcgajjar" target="_blank">@dipakcgajjar</a> </span>
124 <br />
125 <span class="wpsmy_admin_dev_sidebar" style="float: right;"> Version: <strong> <?php echo get_option('wpsmy_plugin_version'); ?> </strong> </span>
126 </div>
127 </td>
128 </tr>
129 </table>
130 </div>
131 <hr style="margin: 2em 0 1.5em 0;" />
132 <?php
133 // Promo - Ad contents
134 $promo_content = wp_remote_fopen("https://cdn.rawgit.com/dipakcg/wp-performance-score-booster/master/promos.html");
135 echo $promo_content;
136 ?>
137 <?php // Bottom - News and Referrals part ?>
138 <hr style="margin: 1.5em 0 2em 0;" />
139 <table cellspacing="0" cellpadding="0" class="wpsmy_news_section"> <tr>
140 <td width="49%" valign="top">
141 <h2><strong>News & Updates from Dipak C. Gajjar</strong></h2>
142 <hr />
143 <div class="wpsmy_rss-widget">
144 <?php
145 /* wp_widget_rss_output(array(
146 'url' => 'https://dipakgajjar.com/category/news/feed/?refresh='.rand(10,100).'', // feed URL
147 'title' => 'News & Updates from Dipak C. Gajjar',
148 'items' => 3, // nubmer of posts to display
149 'show_summary' => 1,
150 'show_author' => 0,
151 'show_date' => 0
152 )); */
153 /* Load the news content from Github */
154 $news_content = wp_remote_fopen("https://cdn.rawgit.com/dipakcg/wp-performance-score-booster/master/news-and-updates.html");
155 echo $news_content;
156 ?>
157 </div> </td>
158 <!-- Referrals -->
159 <td width="1%"> &nbsp </td>
160 <td width="50%" valign="top">
161 <div class="wpsmy_referrals">
162 Scalable and affordable SSD VPS at DigitalOcean starting from $5 per month. <br /> <br />
163 <a href="https://www.digitalocean.com" target="_blank" onClick="this.href='https://m.do.co/c/f90a24a27dcc'" ><img src="https://dl.dropboxusercontent.com/u/21966579/do-ssd-virtual-servers-250x250.jpg" alt="Digital Ocean SSD VPS" width="250" height="250" border="0"></a>
164 </div>
165 <div class="wpsmy_referrals">
166 Great managed WordPress hosting at SiteGround starting from $3.95 per month. <br /> <br />
167 <a href="http://www.siteground.com" target="_blank" onClick="this.href='https://www.siteground.com/wordpress-hosting.htm?afbannercode=783dd6fb6802e26ada6cf20768622fda'" ><img src="https://ua.siteground.com/img/banners/general/best-pack/250x250.gif" alt="WordPress Hosting" width="250" height="250" border="0"></a>
168 </div>
169 <?php echo '</td> </tr> </table>'; ?>
170 <?php
171 }
172
173 // Make the default value of enable javascript and enable CSS to true on plugin activation
174 function wpsmy_activate_plugin() {
175
176 // Save default options value in the database
177 update_option( 'wpsmy_combine_js', 'on' );
178 update_option( 'wpsmy_combine_css', 'on' );
179 }
180 register_activation_hook( __FILE__, 'wpsmy_activate_plugin' );
181
182 // Remove filters/functions on plugin deactivation
183 function wpsmy_deactivate_plugin() {
184 delete_option( 'wpsmy_plugin_version' );
185 }
186 register_deactivation_hook( __FILE__, 'wpsmy_deactivate_plugin' );
187
188 function wpsmy_minify_html ($buffer) {
189 $wpsmy_plugin_version = get_option('wpsmy_plugin_version');
190 /* if ( is_user_logged_in() ) {
191 $buffer .= PHP_EOL . '<!--' . PHP_EOL . '*** This site runs WP Super Minify plugin v'. $wpsmy_plugin_version . ' - http://wordpress.org/plugins/wp-super-minify ***' . PHP_EOL . '*** User is logged in, compression is not applied. ***' . PHP_EOL . '-->';
192 return $buffer; // for loggedin users minify is not required
193 } else { */
194 $initial = strlen($buffer);
195 $minify_lib_path = plugin_dir_path( __FILE__ ) . 'includes/min';
196
197 if (!class_exists('Minify_HTML')) {
198 require_once("$minify_lib_path/lib/Minify/HTML.php");
199 ini_set('include_path', ini_get('include_path').":$minify_lib_path/lib");
200 require_once("$minify_lib_path/lib/Minify/CSS.php");
201 require_once("$minify_lib_path/lib/JSMin.php");
202 require ("$minify_lib_path/lib/Minify/Loader.php");
203 Minify_Loader::register();
204 }
205 if ( get_option('wpsmy_combine_js', 1) == 'on') {
206 $buffer = Minify_HTML::minify($buffer,
207 array('jsMinifier' => array('JSMin', 'minify')));
208 }
209 if ( get_option('wpsmy_combine_css', 1) == 'on') {
210 $buffer = Minify_HTML::minify($buffer,
211 array('cssMinifier' => array('Minify_CSS', 'minify')));
212 }
213
214 $final = strlen($buffer);
215 $savings = round((($initial-$final)/$initial*100), 3);
216
217 // $buffer .= "<br/><!-- Uncompressed size: $initial bytes; Compressed size: $final bytes; $savings% savings -->";
218
219 if ($savings != 0) {
220 $buffer .= PHP_EOL . '<!--' . PHP_EOL . '*** This site runs WP Super Minify plugin v'. $wpsmy_plugin_version .' - http://wordpress.org/plugins/wp-super-minify ***' . PHP_EOL . '*** Total size saved: ' . $savings . '% | Size before compression: ' . $initial . ' bytes | Size after compression: ' . $final . ' bytes. ***' . PHP_EOL . '-->';
221 }
222
223 return $buffer;
224 // }
225 }
226
227 // Minifying HTML
228 function wpsmy_minify() {
229 ob_start('wpsmy_minify_html');
230 }
231 add_action('get_header', 'wpsmy_minify');
232
233 /* END OF PLUGIN */
234 ?>
235