Version Description
[2021.01.11] = * disable FVM update routines when a user runs wp-cli commands outside of the root directory * database routine improvements for users with custom table prefixes
Download this release
Release Info
Developer | Alignak |
Plugin | Fast Velocity Minify |
Version | 3.1.4 |
Comparing to | |
See all releases |
Code changes from version 3.1.3 to 3.1.4
- fvm.php +2 -1
- inc/admin.php +72 -50
- inc/common.php +136 -9
- inc/updates.php +21 -119
- readme.txt +5 -1
fvm.php
CHANGED
@@ -6,7 +6,7 @@ Description: Improve your speed score on GTmetrix, Pingdom Tools and Google Page
|
|
6 |
Author: Raul Peixoto
|
7 |
Author URI: http://fastvelocity.com
|
8 |
Text Domain: fast-velocity-minify
|
9 |
-
Version: 3.1.
|
10 |
License: GPL2
|
11 |
|
12 |
------------------------------------------------------------------------
|
@@ -76,6 +76,7 @@ if(is_admin()) {
|
|
76 |
add_action('admin_init', 'fvm_save_settings');
|
77 |
add_action('admin_init', 'fvm_check_minimum_requirements');
|
78 |
add_action('admin_init', 'fvm_check_misconfiguration');
|
|
|
79 |
add_action('admin_enqueue_scripts', 'fvm_add_admin_jscss');
|
80 |
add_action('admin_menu', 'fvm_add_admin_menu');
|
81 |
add_action('admin_notices', 'fvm_show_admin_notice_from_transient');
|
6 |
Author: Raul Peixoto
|
7 |
Author URI: http://fastvelocity.com
|
8 |
Text Domain: fast-velocity-minify
|
9 |
+
Version: 3.1.4
|
10 |
License: GPL2
|
11 |
|
12 |
------------------------------------------------------------------------
|
76 |
add_action('admin_init', 'fvm_save_settings');
|
77 |
add_action('admin_init', 'fvm_check_minimum_requirements');
|
78 |
add_action('admin_init', 'fvm_check_misconfiguration');
|
79 |
+
add_action('admin_init', 'fvm_update_changes');
|
80 |
add_action('admin_enqueue_scripts', 'fvm_add_admin_jscss');
|
81 |
add_action('admin_menu', 'fvm_add_admin_menu');
|
82 |
add_action('admin_notices', 'fvm_show_admin_notice_from_transient');
|
inc/admin.php
CHANGED
@@ -286,12 +286,15 @@ function fvm_get_logs_callback() {
|
|
286 |
|
287 |
# defaults
|
288 |
global $wpdb;
|
|
|
|
|
289 |
|
290 |
# initialize log
|
291 |
$css_log = '';
|
292 |
|
293 |
# build css logs from database
|
294 |
-
|
|
|
295 |
|
296 |
# build second query
|
297 |
foreach ($results as $log) {
|
@@ -313,7 +316,7 @@ function fvm_get_logs_callback() {
|
|
313 |
if(count($list) > 0) {
|
314 |
$listuids = implode(', ', array_fill(0, count($list), '%s'));
|
315 |
if(!empty($listuids)) {
|
316 |
-
$rs = array(); $rs = $wpdb->get_results($wpdb->prepare("SELECT meta FROM
|
317 |
foreach ($rs as $r) {
|
318 |
$imt = json_decode($r->meta, true);
|
319 |
$css_log.= '[Size: '.str_pad(fvm_format_filesize($imt['fs']), 10,' ',STR_PAD_LEFT).']'."\t". $imt['url'] . PHP_EOL;
|
@@ -330,7 +333,7 @@ function fvm_get_logs_callback() {
|
|
330 |
$js_log = '';
|
331 |
|
332 |
# build css logs from database
|
333 |
-
$results = $wpdb->get_results(
|
334 |
|
335 |
# build second query
|
336 |
foreach ($results as $log) {
|
@@ -351,7 +354,7 @@ function fvm_get_logs_callback() {
|
|
351 |
if(count($list) > 0) {
|
352 |
$listuids = implode(', ', array_fill(0, count($list), '%s'));
|
353 |
if(!empty($listuids)) {
|
354 |
-
$rs = array(); $rs = $wpdb->get_results($wpdb->prepare("SELECT meta FROM
|
355 |
foreach ($rs as $r) {
|
356 |
$imt = json_decode($r->meta, true);
|
357 |
$js_log.= '['.__( 'Size:', 'fast-velocity-minify' ).' '.str_pad(fvm_format_filesize($imt['fs']), 10,' ',STR_PAD_LEFT).']'."\t". $imt['url'] . PHP_EOL;
|
@@ -393,48 +396,45 @@ function fvm_get_logs_callback() {
|
|
393 |
# run during activation
|
394 |
register_activation_hook($fvm_var_file, 'fvm_plugin_activate');
|
395 |
function fvm_plugin_activate() {
|
396 |
-
|
|
|
397 |
global $wpdb;
|
398 |
-
|
399 |
-
|
400 |
-
# defauls
|
401 |
-
$sql = array();
|
402 |
-
$wpdb_collate = $wpdb->collate;
|
403 |
-
|
404 |
-
# create cache table
|
405 |
$sqla_table_name = $wpdb->prefix . 'fvm_cache';
|
406 |
-
$
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
|
|
|
|
418 |
|
419 |
# create logs table
|
420 |
-
|
421 |
-
$sqlb = "CREATE TABLE IF NOT EXISTS
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
COLLATE {$wpdb_collate}";
|
434 |
|
435 |
# run sql
|
436 |
-
|
437 |
-
dbDelta($
|
|
|
438 |
|
439 |
# initialize cache time
|
440 |
fvm_cache_increment();
|
@@ -452,9 +452,15 @@ function fvm_plugin_deactivate() {
|
|
452 |
fvm_rrmdir($fvm_cache_paths['cache_base_dir']);
|
453 |
}
|
454 |
|
455 |
-
# delete
|
456 |
-
$
|
457 |
-
$wpdb->
|
|
|
|
|
|
|
|
|
|
|
|
|
458 |
|
459 |
}
|
460 |
|
@@ -469,13 +475,25 @@ function fvm_plugin_uninstall() {
|
|
469 |
|
470 |
# remove settings, unless disabled
|
471 |
if(!isset($fvm_settings['global']['preserve_settings']) || ( isset($fvm_settings['global']['preserve_settings']) && $fvm_settings['global']['preserve_settings'] != true)) {
|
472 |
-
|
473 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
474 |
}
|
475 |
|
476 |
-
#
|
477 |
-
$
|
478 |
-
$wpdb->
|
|
|
|
|
|
|
|
|
|
|
|
|
479 |
|
480 |
# remove all cache directories
|
481 |
if(isset($fvm_cache_paths['cache_dir_min']) && stripos($fvm_cache_paths['cache_dir_min'], '/fvm') !== false) {
|
@@ -485,9 +503,13 @@ function fvm_plugin_uninstall() {
|
|
485 |
|
486 |
# initialize database if it doesn't exist
|
487 |
function fvm_initialize_database() {
|
|
|
488 |
global $wpdb;
|
489 |
-
$
|
490 |
-
|
|
|
|
|
|
|
491 |
}
|
492 |
|
493 |
|
286 |
|
287 |
# defaults
|
288 |
global $wpdb;
|
289 |
+
$tbl_name_log = $wpdb->prefix .'fvm_logs';
|
290 |
+
$tbl_name_cache = $wpdb->prefix .'fvm_cache';
|
291 |
|
292 |
# initialize log
|
293 |
$css_log = '';
|
294 |
|
295 |
# build css logs from database
|
296 |
+
|
297 |
+
$results = $wpdb->get_results("SELECT date, content, meta FROM `$tbl_name_log` WHERE type = 'css' ORDER BY id DESC LIMIT 20");
|
298 |
|
299 |
# build second query
|
300 |
foreach ($results as $log) {
|
316 |
if(count($list) > 0) {
|
317 |
$listuids = implode(', ', array_fill(0, count($list), '%s'));
|
318 |
if(!empty($listuids)) {
|
319 |
+
$rs = array(); $rs = $wpdb->get_results($wpdb->prepare("SELECT meta FROM `$tbl_name_cache` WHERE uid IN (".$listuids.") ORDER BY FIELD(uid, '".implode("', '", $list)."')", $list));
|
320 |
foreach ($rs as $r) {
|
321 |
$imt = json_decode($r->meta, true);
|
322 |
$css_log.= '[Size: '.str_pad(fvm_format_filesize($imt['fs']), 10,' ',STR_PAD_LEFT).']'."\t". $imt['url'] . PHP_EOL;
|
333 |
$js_log = '';
|
334 |
|
335 |
# build css logs from database
|
336 |
+
$results = $wpdb->get_results("SELECT date, content, meta FROM `$tbl_name_log` WHERE type = 'js' ORDER BY id DESC LIMIT 20");
|
337 |
|
338 |
# build second query
|
339 |
foreach ($results as $log) {
|
354 |
if(count($list) > 0) {
|
355 |
$listuids = implode(', ', array_fill(0, count($list), '%s'));
|
356 |
if(!empty($listuids)) {
|
357 |
+
$rs = array(); $rs = $wpdb->get_results($wpdb->prepare("SELECT meta FROM `$tbl_name_cache` WHERE uid IN (".$listuids.") ORDER BY FIELD(uid, '".implode("', '", $list)."')", $list));
|
358 |
foreach ($rs as $r) {
|
359 |
$imt = json_decode($r->meta, true);
|
360 |
$js_log.= '['.__( 'Size:', 'fast-velocity-minify' ).' '.str_pad(fvm_format_filesize($imt['fs']), 10,' ',STR_PAD_LEFT).']'."\t". $imt['url'] . PHP_EOL;
|
396 |
# run during activation
|
397 |
register_activation_hook($fvm_var_file, 'fvm_plugin_activate');
|
398 |
function fvm_plugin_activate() {
|
399 |
+
|
400 |
+
# default variables
|
401 |
global $wpdb;
|
402 |
+
$charset_collate = $wpdb->get_charset_collate();
|
|
|
|
|
|
|
|
|
|
|
|
|
403 |
$sqla_table_name = $wpdb->prefix . 'fvm_cache';
|
404 |
+
$sqlb_table_name = $wpdb->prefix . 'fvm_logs';
|
405 |
+
|
406 |
+
# prepare
|
407 |
+
$sqla = "CREATE TABLE IF NOT EXISTS `$sqla_table_name` (
|
408 |
+
`id` bigint(20) unsigned NOT NULL auto_increment,
|
409 |
+
`uid` varchar(60) NOT NULL,
|
410 |
+
`date` bigint(20) unsigned NOT NULL,
|
411 |
+
`type` varchar(32) NOT NULL,
|
412 |
+
`content` mediumtext NOT NULL,
|
413 |
+
`meta` mediumtext NOT NULL,
|
414 |
+
PRIMARY KEY (id),
|
415 |
+
UNIQUE KEY uid (uid),
|
416 |
+
KEY date (date), KEY type (type)
|
417 |
+
) $charset_collate;";
|
418 |
|
419 |
# create logs table
|
420 |
+
|
421 |
+
$sqlb = "CREATE TABLE IF NOT EXISTS `$sqlb_table_name` (
|
422 |
+
`id` bigint(20) unsigned NOT NULL auto_increment,
|
423 |
+
`uid` varchar(60) NOT NULL,
|
424 |
+
`date` bigint(20) unsigned NOT NULL,
|
425 |
+
`type` varchar(32) NOT NULL,
|
426 |
+
`content` mediumtext NOT NULL,
|
427 |
+
`meta` mediumtext NOT NULL,
|
428 |
+
PRIMARY KEY (id),
|
429 |
+
UNIQUE KEY uid (uid),
|
430 |
+
KEY date (date),
|
431 |
+
KEY type (type)
|
432 |
+
) $charset_collate;";
|
|
|
433 |
|
434 |
# run sql
|
435 |
+
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
436 |
+
dbDelta( $sqla );
|
437 |
+
dbDelta( $sqlb );
|
438 |
|
439 |
# initialize cache time
|
440 |
fvm_cache_increment();
|
452 |
fvm_rrmdir($fvm_cache_paths['cache_base_dir']);
|
453 |
}
|
454 |
|
455 |
+
# delete cache table
|
456 |
+
$tbl_name = $wpdb->prefix .'fvm_cache';
|
457 |
+
$sql = $wpdb->prepare( "DROP TABLE IF EXISTS `$tbl_name`", $tbl_name);
|
458 |
+
$wpdb->query($sql);
|
459 |
+
|
460 |
+
# delete logs table
|
461 |
+
$tbl_name = $wpdb->prefix .'fvm_logs';
|
462 |
+
$sql = $wpdb->prepare( "DROP TABLE IF EXISTS `$tbl_name`", $tbl_name);
|
463 |
+
$wpdb->query($sql);
|
464 |
|
465 |
}
|
466 |
|
475 |
|
476 |
# remove settings, unless disabled
|
477 |
if(!isset($fvm_settings['global']['preserve_settings']) || ( isset($fvm_settings['global']['preserve_settings']) && $fvm_settings['global']['preserve_settings'] != true)) {
|
478 |
+
|
479 |
+
# prepare and delete
|
480 |
+
$tbl_name = $wpdb->prefix .'options';
|
481 |
+
$sql = $wpdb->prepare( "DELETE FROM `$tbl_name` WHERE option_name = 'fvm_settings'");
|
482 |
+
$wpdb->query($sql);
|
483 |
+
$sql = $wpdb->prepare( "DELETE FROM `$tbl_name` WHERE option_name = 'fvm_last_cache_update'");
|
484 |
+
$wpdb->query($sql);
|
485 |
+
|
486 |
}
|
487 |
|
488 |
+
# delete cache table
|
489 |
+
$tbl_name = $wpdb->prefix .'fvm_cache';
|
490 |
+
$sql = $wpdb->prepare( "DROP TABLE IF EXISTS `$tbl_name`");
|
491 |
+
$wpdb->query($sql);
|
492 |
+
|
493 |
+
# delete logs table
|
494 |
+
$tbl_name = $wpdb->prefix .'fvm_logs';
|
495 |
+
$sql = $wpdb->prepare( "DROP TABLE IF EXISTS `$tbl_name`");
|
496 |
+
$wpdb->query($sql);
|
497 |
|
498 |
# remove all cache directories
|
499 |
if(isset($fvm_cache_paths['cache_dir_min']) && stripos($fvm_cache_paths['cache_dir_min'], '/fvm') !== false) {
|
503 |
|
504 |
# initialize database if it doesn't exist
|
505 |
function fvm_initialize_database() {
|
506 |
+
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
507 |
global $wpdb;
|
508 |
+
$tbl_name = $wpdb->prefix .'fvm_cache';
|
509 |
+
$sql = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $tbl_name ) );
|
510 |
+
if ( $wpdb->get_var( $sql ) !== $tbl_name ) {
|
511 |
+
fvm_plugin_activate();
|
512 |
+
}
|
513 |
}
|
514 |
|
515 |
|
inc/common.php
CHANGED
@@ -171,10 +171,16 @@ function fvm_purge_minification() {
|
|
171 |
# increment cache file names
|
172 |
$now = fvm_cache_increment();
|
173 |
|
174 |
-
# truncate cache table
|
175 |
global $wpdb;
|
176 |
-
|
177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
|
179 |
# get cache and min directories
|
180 |
global $fvm_cache_paths, $fvm_settings;
|
@@ -198,7 +204,7 @@ function fvm_purge_minification() {
|
|
198 |
}
|
199 |
|
200 |
} else {
|
201 |
-
return __( 'The cache directory is not
|
202 |
}
|
203 |
|
204 |
return false;
|
@@ -738,6 +744,122 @@ function fvm_get_default_settings($fvm_settings) {
|
|
738 |
}
|
739 |
|
740 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
741 |
# save log to database
|
742 |
function fvm_save_log($arr) {
|
743 |
|
@@ -776,7 +898,8 @@ function fvm_save_log($arr) {
|
|
776 |
}
|
777 |
|
778 |
# prepare and insert to database
|
779 |
-
$
|
|
|
780 |
$result = $wpdb->query($sql);
|
781 |
|
782 |
# check if it already exists
|
@@ -881,16 +1004,18 @@ function fvm_save_file($file, $content) {
|
|
881 |
# get transients
|
882 |
function fvm_get_transient($key, $check=null) {
|
883 |
|
|
|
884 |
global $wpdb;
|
|
|
885 |
|
886 |
# normalize unknown keys
|
887 |
if(strlen($key) != 40) { $key = hash('sha1', $key); }
|
888 |
|
889 |
# check or fetch
|
890 |
if($check) {
|
891 |
-
$sql = $wpdb->prepare("SELECT id FROM
|
892 |
} else {
|
893 |
-
$sql = $wpdb->prepare("SELECT content FROM
|
894 |
}
|
895 |
|
896 |
# get result from database
|
@@ -948,7 +1073,8 @@ function fvm_set_transient($arr) {
|
|
948 |
}
|
949 |
|
950 |
# prepare and insert to database
|
951 |
-
$
|
|
|
952 |
$result = $wpdb->query($sql);
|
953 |
|
954 |
# check if it already exists
|
@@ -970,7 +1096,8 @@ function fvm_del_transient($key) {
|
|
970 |
if(strlen($key) != 40) { $key = hash('sha1', $key); }
|
971 |
|
972 |
# delete
|
973 |
-
$
|
|
|
974 |
$result = $wpdb->get_row($sql);
|
975 |
return true;
|
976 |
}
|
171 |
# increment cache file names
|
172 |
$now = fvm_cache_increment();
|
173 |
|
174 |
+
# truncate cache table (doesn't work with prepared statements)
|
175 |
global $wpdb;
|
176 |
+
|
177 |
+
# purge cache table
|
178 |
+
$tbl_name = "{$wpdb->prefix}fvm_cache";
|
179 |
+
$wpdb->query("TRUNCATE TABLE `$tbl_name`");
|
180 |
+
|
181 |
+
# purge logs table
|
182 |
+
$tbl_name = "{$wpdb->prefix}fvm_logs";
|
183 |
+
$wpdb->query("TRUNCATE TABLE `$tbl_name`");
|
184 |
|
185 |
# get cache and min directories
|
186 |
global $fvm_cache_paths, $fvm_settings;
|
204 |
}
|
205 |
|
206 |
} else {
|
207 |
+
return __( 'The cache directory is not writeable!', 'fast-velocity-minify' );
|
208 |
}
|
209 |
|
210 |
return false;
|
744 |
}
|
745 |
|
746 |
|
747 |
+
|
748 |
+
# update routines for new fields and replacements
|
749 |
+
function fvm_get_updated_field_routines($fvm_settings) {
|
750 |
+
|
751 |
+
# current version
|
752 |
+
global $fvm_var_plugin_version;
|
753 |
+
|
754 |
+
# must have
|
755 |
+
if(!is_array($fvm_settings)) { return $fvm_settings; }
|
756 |
+
|
757 |
+
# Version 3.0 routines start
|
758 |
+
|
759 |
+
# settings migration
|
760 |
+
if (get_option("fastvelocity_upgraded") === false) {
|
761 |
+
if (get_option("fastvelocity_plugin_version") !== false) {
|
762 |
+
|
763 |
+
# cache path
|
764 |
+
if (get_option("fastvelocity_min_change_cache_path") !== false && !isset($fvm_settings['cache']['path'])) {
|
765 |
+
$fvm_settings['cache']['path'] = get_option("fastvelocity_min_change_cache_path");
|
766 |
+
}
|
767 |
+
|
768 |
+
# cache base_url
|
769 |
+
if (get_option("fastvelocity_min_change_cache_base_url") !== false && !isset($fvm_settings['cache']['url'])) {
|
770 |
+
$fvm_settings['cache']['url'] = get_option("fastvelocity_min_change_cache_base_url");
|
771 |
+
|
772 |
+
}
|
773 |
+
|
774 |
+
# disable html minification
|
775 |
+
if (get_option("fastvelocity_min_skip_html_minification") !== false && !isset($fvm_settings['html']['min_disable'])) {
|
776 |
+
$fvm_settings['html']['min_disable'] = 1;
|
777 |
+
}
|
778 |
+
|
779 |
+
# do not remove html comments
|
780 |
+
if (get_option("fastvelocity_min_strip_htmlcomments") !== false && !isset($fvm_settings['html']['nocomments'])) {
|
781 |
+
$fvm_settings['html']['nocomments'] = 1;
|
782 |
+
}
|
783 |
+
|
784 |
+
# cdn url
|
785 |
+
$oldcdn = get_option("fastvelocity_min_fvm_cdn_url");
|
786 |
+
if ($oldcdn !== false && !empty($oldcdn)) {
|
787 |
+
if (!isset($fvm_settings['cdn']['domain']) || (isset($fvm_settings['cdn']['domain']) && empty($fvm_settings['cdn']['domain']))) {
|
788 |
+
$fvm_settings['cdn']['enable'] = 1;
|
789 |
+
$fvm_settings['cdn']['cssok'] = 1;
|
790 |
+
$fvm_settings['cdn']['jsok'] = 1;
|
791 |
+
$fvm_settings['cdn']['domain'] = $oldcdn;
|
792 |
+
}
|
793 |
+
}
|
794 |
+
|
795 |
+
# force https
|
796 |
+
if (get_option("fastvelocity_min_default_protocol") == 'https' && !isset($fvm_settings['global']['force-ssl'])) {
|
797 |
+
$fvm_settings['global']['force-ssl'] = 1;
|
798 |
+
}
|
799 |
+
|
800 |
+
# preserve settings on uninstall
|
801 |
+
if (get_option("fastvelocity_preserve_settings_on_uninstall") !== false && !isset($fvm_settings['global']['preserve_settings'])) {
|
802 |
+
$fvm_settings['global']['preserve_settings'] = 1;
|
803 |
+
}
|
804 |
+
|
805 |
+
# inline all css
|
806 |
+
if (get_option("fastvelocity_min_force_inline_css") !== false && !isset($fvm_settings['css']['inline-all'])) {
|
807 |
+
$fvm_settings['css']['inline-all'] = 1;
|
808 |
+
}
|
809 |
+
|
810 |
+
# remove google fonts
|
811 |
+
if (get_option("fastvelocity_min_remove_googlefonts") !== false && !isset($fvm_settings['css']['remove'])) {
|
812 |
+
|
813 |
+
# add fonts.gstatic.com
|
814 |
+
$arr = array('fonts.gstatic.com');
|
815 |
+
$fvm_settings['css']['remove'] = implode(PHP_EOL, fvm_array_order($arr));
|
816 |
+
|
817 |
+
}
|
818 |
+
|
819 |
+
# Skip deferring the jQuery library, add them to the header render blocking
|
820 |
+
if (get_option("fastvelocity_min_exclude_defer_jquery") !== false && !isset($fvm_settings['js']['merge_header'])) {
|
821 |
+
|
822 |
+
# add jquery + jquery migrate
|
823 |
+
$arr = array('/jquery-migrate-', '/jquery-migrate.js', '/jquery-migrate.min.js', '/jquery.js', '/jquery.min.js');
|
824 |
+
$fvm_settings['js']['merge_header'] = implode(PHP_EOL, fvm_array_order($arr));
|
825 |
+
|
826 |
+
}
|
827 |
+
|
828 |
+
# new users, add recommended default scripts settings
|
829 |
+
if ( (!isset($fvm_settings['js']['merge_header']) || isset($fvm_settings['js']['merge_header']) && empty($fvm_settings['js']['merge_header'])) && (!isset($fvm_settings['js']['merge_defer']) || (isset($fvm_settings['js']['merge_defer']) && empty($fvm_settings['js']['merge_defer']))) ) {
|
830 |
+
|
831 |
+
# header
|
832 |
+
$arr = array('/jquery-migrate-', '/jquery-migrate.js', '/jquery-migrate.min.js', '/jquery.js', '/jquery.min.js');
|
833 |
+
$fvm_settings['js']['merge_header'] = implode(PHP_EOL, fvm_array_order($arr));
|
834 |
+
|
835 |
+
# defer
|
836 |
+
$arr = array('/ajax.aspnetcdn.com/ajax/', '/ajax.googleapis.com/ajax/libs/', '/cdnjs.cloudflare.com/ajax/libs/', '/stackpath.bootstrapcdn.com/bootstrap/', '/wp-admin/', '/wp-content/', '/wp-includes/');
|
837 |
+
$fvm_settings['js']['merge_defer'] = implode(PHP_EOL, fvm_array_order($arr));
|
838 |
+
|
839 |
+
# js footer dependencies
|
840 |
+
$arr = array('wp.i18n');
|
841 |
+
$fvm_settings['js']['defer_dependencies'] = implode(PHP_EOL, fvm_array_order($arr));
|
842 |
+
|
843 |
+
# recommended delayed scripts
|
844 |
+
$arr = array('function(f,b,e,v,n,t,s)', 'function(w,d,s,l,i)', 'function(h,o,t,j,a,r)', 'connect.facebook.net', 'www.googletagmanager.com', 'gtag(', 'fbq(', 'assets.pinterest.com/js/pinit_main.js', 'pintrk(');
|
845 |
+
$fvm_settings['js']['thirdparty'] = implode(PHP_EOL, fvm_array_order($arr));
|
846 |
+
|
847 |
+
}
|
848 |
+
|
849 |
+
# clear old cron
|
850 |
+
wp_clear_scheduled_hook( 'fastvelocity_purge_old_cron_event' );
|
851 |
+
|
852 |
+
# mark as done
|
853 |
+
update_option('fastvelocity_upgraded', true);
|
854 |
+
|
855 |
+
}
|
856 |
+
}
|
857 |
+
# Version 3.0 routines end
|
858 |
+
|
859 |
+
# return settings array
|
860 |
+
return $fvm_settings;
|
861 |
+
}
|
862 |
+
|
863 |
# save log to database
|
864 |
function fvm_save_log($arr) {
|
865 |
|
898 |
}
|
899 |
|
900 |
# prepare and insert to database
|
901 |
+
$tbl_name = "{$wpdb->prefix}fvm_logs";
|
902 |
+
$sql = $wpdb->prepare("INSERT IGNORE INTO `$tbl_name` (".implode(', ', $fld).") VALUES (".implode(', ', $tpe).")", $vls);
|
903 |
$result = $wpdb->query($sql);
|
904 |
|
905 |
# check if it already exists
|
1004 |
# get transients
|
1005 |
function fvm_get_transient($key, $check=null) {
|
1006 |
|
1007 |
+
# defaults
|
1008 |
global $wpdb;
|
1009 |
+
$tbl_name = "{$wpdb->prefix}fvm_cache";
|
1010 |
|
1011 |
# normalize unknown keys
|
1012 |
if(strlen($key) != 40) { $key = hash('sha1', $key); }
|
1013 |
|
1014 |
# check or fetch
|
1015 |
if($check) {
|
1016 |
+
$sql = $wpdb->prepare("SELECT id FROM `$tbl_name` WHERE uid = '%s' LIMIT 1", $key);
|
1017 |
} else {
|
1018 |
+
$sql = $wpdb->prepare("SELECT content FROM `$tbl_name` WHERE uid = '%s' LIMIT 1", $key);
|
1019 |
}
|
1020 |
|
1021 |
# get result from database
|
1073 |
}
|
1074 |
|
1075 |
# prepare and insert to database
|
1076 |
+
$tbl_name = "{$wpdb->prefix}fvm_cache";
|
1077 |
+
$sql = $wpdb->prepare("INSERT IGNORE INTO `$tbl_name` (".implode(', ', $fld).") VALUES (".implode(', ', $tpe).")", $vls);
|
1078 |
$result = $wpdb->query($sql);
|
1079 |
|
1080 |
# check if it already exists
|
1096 |
if(strlen($key) != 40) { $key = hash('sha1', $key); }
|
1097 |
|
1098 |
# delete
|
1099 |
+
$tbl_name = "{$wpdb->prefix}fvm_cache";
|
1100 |
+
$sql = $wpdb->prepare("DELETE FROM `$tbl_name` WHERE uid = '%s'", $key);
|
1101 |
$result = $wpdb->get_row($sql);
|
1102 |
return true;
|
1103 |
}
|
inc/updates.php
CHANGED
@@ -4,139 +4,45 @@
|
|
4 |
if (!defined('ABSPATH')){ exit(); }
|
5 |
|
6 |
# update routines for new fields and replacements
|
7 |
-
function
|
8 |
|
9 |
# current version
|
10 |
global $fvm_var_plugin_version;
|
11 |
|
12 |
-
# must have
|
13 |
-
if(!is_array($fvm_settings)) { return $fvm_settings; }
|
14 |
-
|
15 |
# Version 3.0 routines start
|
16 |
|
17 |
# delete old FVM files
|
18 |
global $fvm_var_dir_path, $fvm_var_inc_lib, $fvm_var_inc_dir;
|
19 |
-
if(file_exists($fvm_var_inc_dir.'functions-cache.php')) { @unlink($fvm_var_inc_dir.'functions-cache.php'); }
|
20 |
-
if(file_exists($fvm_var_inc_dir.'functions-cli.php')) { @unlink($fvm_var_inc_dir.'functions-cli.php'); }
|
21 |
-
if(file_exists($fvm_var_inc_dir.'functions-serverinfo.php')) { @unlink($fvm_var_inc_dir.'functions-serverinfo.php'); }
|
22 |
-
if(file_exists($fvm_var_inc_dir.'functions-upgrade.php')) { @unlink($fvm_var_inc_dir.'functions-upgrade.php'); }
|
23 |
-
if(file_exists($fvm_var_inc_dir.'functions.php')) { @unlink($fvm_var_inc_dir.'functions.php'); }
|
24 |
-
if(file_exists($fvm_var_dir_path.'fvm.css')) { @unlink($fvm_var_dir_path.'fvm.css'); }
|
25 |
-
if(file_exists($fvm_var_dir_path.'fvm.js')) { @unlink($fvm_var_dir_path.'fvm.js'); }
|
26 |
-
if(file_exists($fvm_var_inc_lib.'mrclay' . DIRECTORY_SEPARATOR . 'HTML.php')) {
|
27 |
-
@unlink($fvm_var_inc_lib.'mrclay' . DIRECTORY_SEPARATOR . 'HTML.php');
|
28 |
-
@unlink($fvm_var_inc_lib.'mrclay' . DIRECTORY_SEPARATOR . 'index.html');
|
29 |
-
@rmdir($fvm_var_inc_lib.'mrclay');
|
30 |
-
}
|
31 |
|
32 |
-
|
33 |
-
#
|
34 |
-
if (
|
35 |
-
if (get_option("fastvelocity_plugin_version") !== false) {
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
if
|
44 |
-
|
45 |
-
|
46 |
-
}
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
$
|
51 |
-
|
52 |
-
|
53 |
-
# do not remove html comments
|
54 |
-
if (get_option("fastvelocity_min_strip_htmlcomments") !== false && !isset($fvm_settings['html']['nocomments'])) {
|
55 |
-
$fvm_settings['html']['nocomments'] = 1;
|
56 |
-
}
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
# cdn url
|
61 |
-
if (get_option("fastvelocity_min_fvm_cdn_url") !== false) {
|
62 |
-
if (!isset($fvm_settings['cdn']['domain']) || (isset($fvm_settings['cdn']['domain']) && empty($fvm_settings['cdn']['domain']))) {
|
63 |
-
$fvm_settings['cdn']['enable'] = 1;
|
64 |
-
$fvm_settings['cdn']['cssok'] = 1;
|
65 |
-
$fvm_settings['cdn']['jsok'] = 1;
|
66 |
-
$fvm_settings['cdn']['domain'] = get_option("fastvelocity_min_fvm_cdn_url");
|
67 |
-
}
|
68 |
-
}
|
69 |
-
|
70 |
-
# force https
|
71 |
-
if (get_option("fastvelocity_min_default_protocol") == 'https' && !isset($fvm_settings['global']['force-ssl'])) {
|
72 |
-
$fvm_settings['global']['force-ssl'] = 1;
|
73 |
-
}
|
74 |
-
|
75 |
-
# preserve settings on uninstall
|
76 |
-
if (get_option("fastvelocity_preserve_settings_on_uninstall") !== false && !isset($fvm_settings['global']['preserve_settings'])) {
|
77 |
-
$fvm_settings['global']['preserve_settings'] = 1;
|
78 |
-
}
|
79 |
-
|
80 |
-
# inline all css
|
81 |
-
if (get_option("fastvelocity_min_force_inline_css") !== false && !isset($fvm_settings['css']['inline-all'])) {
|
82 |
-
$fvm_settings['css']['inline-all'] = 1;
|
83 |
-
}
|
84 |
-
|
85 |
-
# remove google fonts
|
86 |
-
if (get_option("fastvelocity_min_remove_googlefonts") !== false && !isset($fvm_settings['css']['remove'])) {
|
87 |
-
|
88 |
-
# add fonts.gstatic.com
|
89 |
-
$arr = array('fonts.gstatic.com');
|
90 |
-
$fvm_settings['css']['remove'] = implode(PHP_EOL, fvm_array_order($arr));
|
91 |
-
|
92 |
-
}
|
93 |
-
|
94 |
-
# Skip deferring the jQuery library, add them to the header render blocking
|
95 |
-
if (get_option("fastvelocity_min_exclude_defer_jquery") !== false && !isset($fvm_settings['js']['merge_header'])) {
|
96 |
-
|
97 |
-
# add jquery + jquery migrate
|
98 |
-
$arr = array('/jquery-migrate-', '/jquery-migrate.js', '/jquery-migrate.min.js', '/jquery.js', '/jquery.min.js');
|
99 |
-
$fvm_settings['js']['merge_header'] = implode(PHP_EOL, fvm_array_order($arr));
|
100 |
-
|
101 |
-
}
|
102 |
-
|
103 |
-
# new users, add recommended default scripts settings
|
104 |
-
if ( (!isset($fvm_settings['js']['merge_header']) || isset($fvm_settings['js']['merge_header']) && empty($fvm_settings['js']['merge_header'])) && (!isset($fvm_settings['js']['merge_defer']) || (isset($fvm_settings['js']['merge_defer']) && empty($fvm_settings['js']['merge_defer']))) ) {
|
105 |
-
|
106 |
-
# header
|
107 |
-
$arr = array('/jquery-migrate-', '/jquery-migrate.js', '/jquery-migrate.min.js', '/jquery.js', '/jquery.min.js');
|
108 |
-
$fvm_settings['js']['merge_header'] = implode(PHP_EOL, fvm_array_order($arr));
|
109 |
-
|
110 |
-
# defer
|
111 |
-
$arr = array('/ajax.aspnetcdn.com/ajax/', '/ajax.googleapis.com/ajax/libs/', '/cdnjs.cloudflare.com/ajax/libs/', '/stackpath.bootstrapcdn.com/bootstrap/', '/wp-admin/', '/wp-content/', '/wp-includes/');
|
112 |
-
$fvm_settings['js']['merge_defer'] = implode(PHP_EOL, fvm_array_order($arr));
|
113 |
-
|
114 |
-
# js footer dependencies
|
115 |
-
$arr = array('wp.i18n');
|
116 |
-
$fvm_settings['js']['defer_dependencies'] = implode(PHP_EOL, fvm_array_order($arr));
|
117 |
-
|
118 |
-
# recommended delayed scripts
|
119 |
-
$arr = array('function(f,b,e,v,n,t,s)', 'function(w,d,s,l,i)', 'function(h,o,t,j,a,r)', 'connect.facebook.net', 'www.googletagmanager.com', 'gtag(', 'fbq(', 'assets.pinterest.com/js/pinit_main.js', 'pintrk(');
|
120 |
-
$fvm_settings['js']['thirdparty'] = implode(PHP_EOL, fvm_array_order($arr));
|
121 |
-
|
122 |
}
|
123 |
-
|
124 |
-
# clear old cron
|
125 |
-
wp_clear_scheduled_hook( 'fastvelocity_purge_old_cron_event' );
|
126 |
-
|
127 |
-
# mark as done
|
128 |
-
update_option('fastvelocity_upgraded', true);
|
129 |
|
130 |
}
|
131 |
-
}
|
132 |
-
# Version 3.0 routines end
|
133 |
|
134 |
# Version 3.2 routines start
|
135 |
if (get_option("fastvelocity_plugin_version") !== false) {
|
136 |
-
if (version_compare($fvm_var_plugin_version, '3.2.0', '>=' )) {
|
137 |
|
138 |
# cleanup
|
139 |
-
delete_option('fastvelocity_upgraded');
|
140 |
delete_option('fastvelocity_min_change_cache_path');
|
141 |
delete_option('fastvelocity_min_change_cache_base_url');
|
142 |
delete_option('fastvelocity_min_fvm_cdn_url');
|
@@ -181,8 +87,4 @@ function fvm_get_updated_field_routines($fvm_settings) {
|
|
181 |
}
|
182 |
# Version 3.2 routines end
|
183 |
|
184 |
-
# return settings array
|
185 |
-
return $fvm_settings;
|
186 |
}
|
187 |
-
|
188 |
-
|
4 |
if (!defined('ABSPATH')){ exit(); }
|
5 |
|
6 |
# update routines for new fields and replacements
|
7 |
+
function fvm_update_changes() {
|
8 |
|
9 |
# current version
|
10 |
global $fvm_var_plugin_version;
|
11 |
|
|
|
|
|
|
|
12 |
# Version 3.0 routines start
|
13 |
|
14 |
# delete old FVM files
|
15 |
global $fvm_var_dir_path, $fvm_var_inc_lib, $fvm_var_inc_dir;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
# prevent deleting if the paths are empty
|
18 |
+
# can happen when a user runs wp-cli on a child directory
|
19 |
+
if(isset($fvm_var_dir_path) && isset($fvm_var_inc_lib) && isset($fvm_var_inc_dir) && !empty($fvm_var_dir_path) && !empty($fvm_var_inc_lib) && !empty($fvm_var_inc_dir)) {
|
|
|
20 |
|
21 |
+
# must be inside a fast-velocity-minify directory
|
22 |
+
if (stripos($fvm_var_dir_path, 'fast-velocity-minify') !== false) {
|
23 |
+
|
24 |
+
# delete
|
25 |
+
if(file_exists($fvm_var_inc_dir.'functions-cache.php')) { @unlink($fvm_var_inc_dir.'functions-cache.php'); }
|
26 |
+
if(file_exists($fvm_var_inc_dir.'functions-cli.php')) { @unlink($fvm_var_inc_dir.'functions-cli.php'); }
|
27 |
+
if(file_exists($fvm_var_inc_dir.'functions-serverinfo.php')) { @unlink($fvm_var_inc_dir.'functions-serverinfo.php'); }
|
28 |
+
if(file_exists($fvm_var_inc_dir.'functions-upgrade.php')) { @unlink($fvm_var_inc_dir.'functions-upgrade.php'); }
|
29 |
+
if(file_exists($fvm_var_inc_dir.'functions.php')) { @unlink($fvm_var_inc_dir.'functions.php'); }
|
30 |
+
if(file_exists($fvm_var_dir_path.'fvm.css')) { @unlink($fvm_var_dir_path.'fvm.css'); }
|
31 |
+
if(file_exists($fvm_var_dir_path.'fvm.js')) { @unlink($fvm_var_dir_path.'fvm.js'); }
|
32 |
+
if(file_exists($fvm_var_inc_lib.'mrclay' . DIRECTORY_SEPARATOR . 'HTML.php')) {
|
33 |
+
@unlink($fvm_var_inc_lib.'mrclay' . DIRECTORY_SEPARATOR . 'HTML.php');
|
34 |
+
@unlink($fvm_var_inc_lib.'mrclay' . DIRECTORY_SEPARATOR . 'index.html');
|
35 |
+
@rmdir($fvm_var_inc_lib.'mrclay');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
}
|
39 |
+
}
|
|
|
40 |
|
41 |
# Version 3.2 routines start
|
42 |
if (get_option("fastvelocity_plugin_version") !== false) {
|
43 |
+
if (version_compare($fvm_var_plugin_version, '3.2.0', '>=') && get_option("fastvelocity_min_ignore") !== false) {
|
44 |
|
45 |
# cleanup
|
|
|
46 |
delete_option('fastvelocity_min_change_cache_path');
|
47 |
delete_option('fastvelocity_min_change_cache_base_url');
|
48 |
delete_option('fastvelocity_min_fvm_cdn_url');
|
87 |
}
|
88 |
# Version 3.2 routines end
|
89 |
|
|
|
|
|
90 |
}
|
|
|
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: Alignak
|
|
3 |
Tags: PHP Minify, Lighthouse, GTmetrix, Pingdom, Pagespeed, Merging, Minification, Optimization, Speed, Performance, FVM
|
4 |
Requires at least: 4.7
|
5 |
Requires PHP: 5.6
|
6 |
-
Stable tag: 3.1.
|
7 |
Tested up to: 5.6
|
8 |
Text Domain: fast-velocity-minify
|
9 |
License: GPLv3 or later
|
@@ -55,6 +55,10 @@ Version 3.0 is a major code rewrite to improve JS and CSS merging, but it requir
|
|
55 |
|
56 |
== Changelog ==
|
57 |
|
|
|
|
|
|
|
|
|
58 |
= 3.1.3 [2021.01.10] =
|
59 |
* Link preload headers improvement
|
60 |
|
3 |
Tags: PHP Minify, Lighthouse, GTmetrix, Pingdom, Pagespeed, Merging, Minification, Optimization, Speed, Performance, FVM
|
4 |
Requires at least: 4.7
|
5 |
Requires PHP: 5.6
|
6 |
+
Stable tag: 3.1.4
|
7 |
Tested up to: 5.6
|
8 |
Text Domain: fast-velocity-minify
|
9 |
License: GPLv3 or later
|
55 |
|
56 |
== Changelog ==
|
57 |
|
58 |
+
= 3.1.4 [2021.01.11] =
|
59 |
+
* disable FVM update routines when a user runs wp-cli commands outside of the root directory
|
60 |
+
* database routine improvements for users with custom table prefixes
|
61 |
+
|
62 |
= 3.1.3 [2021.01.10] =
|
63 |
* Link preload headers improvement
|
64 |
|