Skip to content

Commit 8b7906d

Browse files
committed
Release new version 1.9.2
* This maintenance update is for compatibility with WordPress 5.0.2 and PHP 7.3. It also includes performance updates to the plugin framework. * Tweak - Test for compatibility with WordPress 5.0.2 and WordPress 4.9.9 * Tweak - Create new structure for future development of Gutenberg Blocks * Framework - Performance improvement. Replace wp_remote_fopen with file_get_contents for get web fonts * Framework - Performance improvement. Define new variable `is_load_google_fonts` if admin does not require to load google fonts * Credit - Props to Derek for alerting us to the framework google fonts performance issue * Framework - Register style name for dynamic style of plugin for use with Gutenberg block * Framework - Update Modal script and style to version 4.1.1 * Framework - Update a3rev Plugin Framework to version 2.1.0 * Framework - Test and update for compatibility with PHP 7.3
1 parent a5c909c commit 8b7906d

10 files changed

+222
-21
lines changed

a3-lazy-load.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
/*
33
Plugin Name: a3 Lazy Load
44
Description: Speed up your site and enhance frontend user's visual experience in PC's, Tablets and mobile with a3 Lazy Load.
5-
Version: 1.9.1
5+
Version: 1.9.2
66
Author: a3rev Software
77
Author URI: https://a3rev.com/
88
Requires at least: 4.0
9-
Tested up to: 4.9.8
9+
Tested up to: 5.0.2
1010
Text Domain: a3-lazy-load
1111
Domain Path: /languages
1212
WC requires at least: 2.0.0
13-
WC tested up to: 3.4.4
13+
WC tested up to: 3.5.3
1414
License: GPLv2 or later
1515
Copyright © 2011 a3 Revolution Software Development team
1616
a3 Revolution Software Development team
@@ -32,7 +32,8 @@
3232
define('A3_LAZY_LOAD_IMAGES_URL', A3_LAZY_LOAD_URL . '/assets/images');
3333

3434
define( 'A3_LAZY_LOAD_KEY', 'a3_lazy_load' );
35-
define( 'A3_LAZY_VERSION', '1.9.1' );
35+
define( 'A3_LAZY_VERSION', '1.9.2' );
36+
define( 'A3_LAZY_LOAD_G_FONTS', false );
3637

3738
/**
3839
* Load Localisation files.

admin/admin-interface.php

+58-2
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ public function get_settings_default( $options, $option_name = '' ) {
384384

385385
default :
386386
// Do not include when it's separate option
387-
if ( isset( $value['separate_option'] ) && $value['separate_option'] != false ) continue;
387+
if ( isset( $value['separate_option'] ) && $value['separate_option'] != false ) break;
388388

389389
// Remove [, ] characters from id argument
390390
if ( strstr( $value['id'], '[' ) ) {
@@ -1144,7 +1144,7 @@ public function settings_get_option( $option_name, $default = '' ) {
11441144
* @return void
11451145
* ========================================================================
11461146
* Option Array Structure :
1147-
* type => row | column | heading | ajax_submit | ajax_multi_submit | google_api_key | onoff_toggle_box
1147+
* type => row | column | heading | ajax_submit | ajax_multi_submit | google_api_key | google_map_api_key | onoff_toggle_box
11481148
* | text | email | number | password | color | bg_color | textarea | select | multiselect | radio | onoff_radio | checkbox | onoff_checkbox
11491149
* | switcher_checkbox | image_size | single_select_page | typography | border | border_styles | border_corner | box_shadow
11501150
* | slider | upload | wp_editor | array_textfields | time_picker
@@ -1834,6 +1834,62 @@ class="a3rev-ui-text a3rev-ui-<?php echo sanitize_title( $value['type'] ) ?> <?p
18341834

18351835
break;
18361836

1837+
// Google Map API Key input
1838+
case 'google_map_api_key':
1839+
1840+
$google_map_api_key = $this->settings_get_option( $this->google_map_api_key_option );
1841+
$google_map_api_key_enable = $this->settings_get_option( $this->google_map_api_key_option . '_enable', 0 );
1842+
if ( ! isset( $value['checked_label'] ) ) $value['checked_label'] = __( 'ON', 'a3-lazy-load' );
1843+
if ( ! isset( $value['unchecked_label'] ) ) $value['unchecked_label'] = __( 'OFF', 'a3-lazy-load' );
1844+
1845+
?><tr valign="top">
1846+
<th scope="row" class="titledesc">
1847+
<?php echo $tip; ?>
1848+
<label for="<?php echo $this->google_map_api_key_option; ?>"><?php echo __( 'Google Maps API', 'a3-lazy-load' ); ?></label>
1849+
</th>
1850+
<td class="forminp forminp-onoff_checkbox forminp-<?php echo sanitize_title( $value['type'] ) ?>">
1851+
<input
1852+
name="<?php echo $this->google_map_api_key_option; ?>_enable"
1853+
id="<?php echo $this->google_map_api_key_option; ?>_enable"
1854+
class="a3rev-ui-onoff_checkbox a3rev-ui-onoff_google_api_key_enable"
1855+
checked_label="<?php echo esc_html( $value['checked_label'] ); ?>"
1856+
unchecked_label="<?php echo esc_html( $value['unchecked_label'] ); ?>"
1857+
type="checkbox"
1858+
value="1"
1859+
<?php checked( $google_map_api_key_enable, 1 ); ?>
1860+
/> <span class="description" style="margin-left:5px;"><?php echo __( 'Switch ON to connect to Google Maps API', 'a3-lazy-load' ); ?></span>
1861+
1862+
<div>&nbsp;</div>
1863+
<div class="a3rev-ui-google-api-key-container" style="<?php if( 1 != $google_map_api_key_enable ) { echo 'display: none;'; } ?>">
1864+
<div class="a3rev-ui-google-api-key-description"><?php echo sprintf( __( "Enter your existing Google Map API Key below. Don't have a key? Visit <a href='%s' target='_blank'>Google Maps API</a> to create a key", 'a3-lazy-load' ), 'https://developers.google.com/maps/documentation/javascript/get-api-key' ); ?></div>
1865+
<div class="a3rev-ui-google-api-key-inside
1866+
<?php
1867+
if ( $this->is_valid_google_map_api_key() ) {
1868+
echo 'a3rev-ui-google-valid-key';
1869+
} elseif ( '' != $google_map_api_key ) {
1870+
echo 'a3rev-ui-google-unvalid-key';
1871+
}
1872+
?>
1873+
">
1874+
<input
1875+
name="<?php echo $this->google_map_api_key_option; ?>"
1876+
id="<?php echo $this->google_map_api_key_option; ?>"
1877+
type="text"
1878+
style="<?php echo esc_attr( $value['css'] ); ?>"
1879+
value="<?php echo esc_attr( $google_map_api_key ); ?>"
1880+
class="a3rev-ui-text a3rev-ui-<?php echo sanitize_title( $value['type'] ) ?> <?php echo esc_attr( $value['class'] ); ?>"
1881+
placeholder="<?php echo __( 'Google Map API Key', 'a3-lazy-load' ); ?>"
1882+
<?php echo implode( ' ', $custom_attributes ); ?>
1883+
/>
1884+
<p class="a3rev-ui-google-valid-key-message"><?php echo __( 'Your Google API Key is valid and automatic font updates are enabled.', 'a3-lazy-load' ); ?></p>
1885+
<p class="a3rev-ui-google-unvalid-key-message"><?php echo __( 'Please enter a valid Google API Key.', 'a3-lazy-load' ); ?></p>
1886+
</div>
1887+
</div>
1888+
</td>
1889+
</tr><?php
1890+
1891+
break;
1892+
18371893
// Manual Check New Version when click on the button instead of wait for daily
18381894
case 'manual_check_version':
18391895

admin/admin-ui.php

+103-5
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,17 @@ class A3_Lazy_Load_Admin_UI
2929
/**
3030
* @var string
3131
* You must change to correct plugin name that you are working
32-
*/
32+
*/A3_LAZY_LOAD_KEY
3333

34-
public $framework_version = '2.0.7';
34+
public $framework_version = '2.1.0';
3535
public $plugin_name = A3_LAZY_LOAD_KEY;
3636
public $plugin_path = A3_LAZY_LOAD_NAME;
3737
public $google_api_key_option = '';
38+
public $google_map_api_key_option = '';
3839
public $toggle_box_open_option = '';
3940
public $version_transient = '';
4041
public $is_free_plugin = true;
42+
public $is_load_google_fonts = true;
4143

4244
public $support_url = '';
4345

@@ -71,11 +73,18 @@ class A3_Lazy_Load_Admin_UI
7173
public $admin_pages = array( 'a3-lazy-load', 'a3-lazy-load-add' );
7274

7375
public function __construct() {
74-
$this->google_api_key_option = A3_LAZY_LOAD_KEY . '_google_api_key';
75-
$this->toggle_box_open_option = A3_LAZY_LOAD_KEY . '_toggle_box_open';
76-
$this->version_transient = A3_LAZY_LOAD_KEY . '_licinfo';
76+
$this->google_api_key_option = A3_LAZY_LOAD_KEY . '_google_api_key';
77+
$this->google_map_api_key_option = A3_LAZY_LOAD_KEY . '_google_map_api_key';
78+
$this->toggle_box_open_option = A3_LAZY_LOAD_KEY . '_toggle_box_open';
79+
$this->version_transient = A3_LAZY_LOAD_KEY . '_licinfo';
80+
81+
if ( defined( 'A3_LAZY_LOAD_G_FONTS' ) ) {
82+
$this->is_load_google_fonts = (boolean) A3_LAZY_LOAD_G_FONTS;
83+
}
7784

7885
$this->support_url = 'https://wordpress.org/support/plugin/a3-lazy-load/';
86+
87+
$this->update_google_map_api_key();
7988
}
8089

8190

@@ -104,6 +113,95 @@ public function admin_pages() {
104113
return (array)$admin_pages;
105114
}
106115

116+
public function is_valid_google_map_api_key( $cache=true ) {
117+
$is_valid = false;
118+
119+
$this->google_map_api_key = get_option( $this->google_map_api_key_option, '' );
120+
$google_map_api_key_enable = get_option( $this->google_map_api_key_option . '_enable', 0 );
121+
122+
if ( '' != trim( $this->google_map_api_key ) && 1 == $google_map_api_key_enable ) {
123+
124+
$google_map_api_key_status = get_transient( $this->google_map_api_key_option . '_status' );
125+
126+
if ( ! $cache ) {
127+
$google_map_api_key_status = null;
128+
}
129+
130+
if ( ! $google_map_api_key_status ) {
131+
$respone_api = wp_remote_get( "https://maps.googleapis.com/maps/api/geocode/json?address=Australia&key=" . trim( $this->google_map_api_key ),
132+
array(
133+
'sslverify' => false,
134+
'timeout' => 45
135+
)
136+
);
137+
138+
$response_map = array();
139+
140+
// Check it is a valid request
141+
if ( ! is_wp_error( $respone_api ) ) {
142+
143+
$json_string = get_magic_quotes_gpc() ? stripslashes( $respone_api['body'] ) : $respone_api['body'];
144+
$response_map = json_decode( $json_string, true );
145+
146+
// Make sure that the valid response from google is not an error message
147+
if ( ! isset( $response_map['error_message'] ) ) {
148+
$google_map_api_key_status = 'valid';
149+
} else {
150+
$google_map_api_key_status = 'invalid';
151+
}
152+
153+
} else {
154+
$google_map_api_key_status = 'invalid';
155+
}
156+
157+
//caching google map api status for 24 hours
158+
set_transient( $this->google_map_api_key_option . '_status', $google_map_api_key_status, 86400 );
159+
}
160+
161+
if ( 'valid' == $google_map_api_key_status ) {
162+
$is_valid = true;
163+
}
164+
165+
}
166+
167+
return $is_valid;
168+
}
169+
170+
public function update_google_map_api_key() {
171+
// Enable Google Map API Key
172+
if ( isset( $_POST[ $this->google_map_api_key_option . '_enable' ] ) ) {
173+
$old_google_map_api_key_enable = get_option( $this->google_map_api_key_option . '_enable', 0 );
174+
175+
update_option( $this->google_map_api_key_option . '_enable', 1 );
176+
177+
$option_value = trim( $_POST[ $this->google_map_api_key_option ] );
178+
179+
$old_google_map_api_key_option = get_option( $this->google_map_api_key_option );
180+
181+
if ( 1 != $old_google_map_api_key_enable || $option_value != $old_google_map_api_key_option ) {
182+
183+
update_option( $this->google_map_api_key_option, $option_value );
184+
185+
// Clear cached of google map api key status
186+
delete_transient( $this->google_map_api_key_option . '_status' );
187+
}
188+
189+
// Disable Google Map API Key
190+
} elseif ( isset( $_POST[ $this->google_map_api_key_option ] ) ) {
191+
$old_google_map_api_key_enable = get_option( $this->google_map_api_key_option . '_enable', 0 );
192+
193+
update_option( $this->google_map_api_key_option . '_enable', 0 );
194+
195+
$option_value = trim( $_POST[ $this->google_map_api_key_option ] );
196+
update_option( $this->google_map_api_key_option, $option_value );
197+
198+
if ( 0 != $old_google_map_api_key_enable ) {
199+
// Clear cached of google map api key status
200+
delete_transient( $this->google_map_api_key_option . '_status' );
201+
}
202+
}
203+
}
204+
107205
/**
108206
* get_premium_video_data()
109207
* return array

admin/assets/css/a3_admin_metabox.rtl.less

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,4 @@
103103
}
104104
}
105105
}
106-
}
106+
}

admin/assets/css/admin-ui-style.css

+2-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@
248248
.a3rev_panel_container .a3rev-ui-password { width:300px; max-width:70%; }
249249

250250
/* Google API KEY Control */
251-
.a3rev_panel_container .a3rev-ui-google_api_key { width:350px; max-width: 100%; }
251+
.a3rev_panel_container .a3rev-ui-google_api_key,
252+
.a3rev_panel_container .a3rev-ui-google_map_api_key { width:350px; max-width: 100%; }
252253
.a3rev_panel_container .a3rev-ui-google-api-key-inside { margin-top: 10px; }
253254
.a3rev_panel_container .a3rev-ui-google-valid-key-message,
254255
.a3rev_panel_container .a3rev-ui-google-unvalid-key-message { display: none; }

admin/assets/css/admin-ui-style.min.css

+2-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@
9393
.a3rev_panel_container .a3rev-ui-password{width:300px;max-width:70%;}
9494

9595
/* Google API KEY Control */
96-
.a3rev_panel_container .a3rev-ui-google_api_key{width:350px;max-width:100%;}
96+
.a3rev_panel_container .a3rev-ui-google_api_key,
97+
.a3rev_panel_container .a3rev-ui-google_map_api_key{width:350px;max-width:100%;}
9798
.a3rev_panel_container .a3rev-ui-google-api-key-inside{margin-top:10px;}
9899
.a3rev_panel_container .a3rev-ui-google-valid-key-message,
99100
.a3rev_panel_container .a3rev-ui-google-unvalid-key-message{display:none;}

admin/assets/js/admin-ui-script.js

+6
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,18 @@
102102

103103
/* Apply for Google API Key */
104104
elem.parents('.forminp-google_api_key').find('.a3rev-ui-google-api-key-container').slideDown();
105+
106+
/* Apply for Google Map API Key */
107+
elem.parents('.forminp-google_map_api_key').find('.a3rev-ui-google-api-key-container').slideDown();
105108
} else {
106109
/* Apply for Border Corner */
107110
elem.parents('.a3rev-ui-settings-control').find('.a3rev-ui-border-corner-value-container').slideUp();
108111

109112
/* Apply for Google API Key */
110113
elem.parents('.forminp-google_api_key').find('.a3rev-ui-google-api-key-container').slideUp();
114+
115+
/* Apply for Google Map API Key */
116+
elem.parents('.forminp-google_map_api_key').find('.a3rev-ui-google-api-key-container').slideUp();
111117
}
112118

113119
$('input[name="' + input_name + '"]').trigger("a3rev-ui-onoff_checkbox-switch", [elem.val(), status]);

admin/includes/fonts_face.php

+11-2
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,11 @@ class A3_Lazy_Load_Fonts_Face extends A3_Lazy_Load_Admin_UI
357357
public function __construct() {
358358
parent::__construct();
359359

360+
if ( ! $this->is_load_google_fonts ) {
361+
$this->google_fonts = array();
362+
return;
363+
}
364+
360365
// Enable Google Font API Key
361366
if ( isset( $_POST[ $this->google_api_key_option . '_enable' ] ) ) {
362367
$old_google_api_key_enable = get_option( $this->google_api_key_option . '_enable', 0 );
@@ -415,6 +420,10 @@ public function __construct() {
415420
public function is_valid_google_api_key( $cache=true ) {
416421
$is_valid = false;
417422

423+
if ( ! $this->is_load_google_fonts ) {
424+
return false;
425+
}
426+
418427
$this->google_api_key = get_option( $this->google_api_key_option, '' );
419428
$google_api_key_enable = get_option( $this->google_api_key_option . '_enable', 0 );
420429

@@ -456,7 +465,7 @@ public function is_valid_google_api_key( $cache=true ) {
456465

457466
// Get font list from default webfonts.json file of plugin
458467
if ( 'invalid' == $google_api_key_status && file_exists( $this->admin_plugin_dir() . '/assets/webfonts/webfonts.json' ) ) {
459-
$webfonts = wp_remote_fopen( $this->admin_plugin_url() . '/assets/webfonts/webfonts.json' );
468+
$webfonts = file_get_contents( $this->admin_plugin_dir() . '/assets/webfonts/webfonts.json' );
460469
if ( false != $webfonts ) {
461470
$json_string = get_magic_quotes_gpc() ? stripslashes( $webfonts ) : $webfonts;
462471
$response_fonts = json_decode( $json_string, true );
@@ -509,7 +518,7 @@ public function is_valid_google_api_key( $cache=true ) {
509518

510519
// Get font list from default webfonts.json file of plugin
511520
if ( file_exists( $this->admin_plugin_dir() . '/assets/webfonts/webfonts.json' ) ) {
512-
$webfonts = wp_remote_fopen( $this->admin_plugin_url() . '/assets/webfonts/webfonts.json' );
521+
$webfonts = file_get_contents( $this->admin_plugin_dir() . '/assets/webfonts/webfonts.json' );
513522
if ( false != $webfonts ) {
514523
$json_string = get_magic_quotes_gpc() ? stripslashes( $webfonts ) : $webfonts;
515524
$response_fonts = json_decode( $json_string, true );

admin/less/sass.php

+14-3
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,22 @@ public function __construct()
1919
add_action( 'wp_enqueue_scripts', array ($this, 'apply_style_css_fontend') , 12 );
2020
}
2121

22+
public function register_dynamic_style_file()
23+
{
24+
$_upload_dir = wp_upload_dir();
25+
if ( file_exists( $_upload_dir['basedir'] . '/sass/' . $this->css_file_name . '.min.css' ) ) {
26+
wp_register_style( 'a3' . $this->css_file_name, str_replace( array('http:','https:'), '', $_upload_dir['baseurl'] ) . '/sass/' . $this->css_file_name . '.min.css', array(), $this->get_css_file_version() );
27+
28+
return true;
29+
}
30+
31+
return false;
32+
}
33+
2234
public function apply_style_css_fontend()
2335
{
24-
$_upload_dir = wp_upload_dir();
25-
if ( file_exists( $_upload_dir['basedir'] . '/sass/' . $this->css_file_name . '.min.css' ) ) {
26-
wp_enqueue_style( 'a3' . $this->css_file_name, str_replace( array('http:','https:'), '', $_upload_dir['baseurl'] ) . '/sass/' . $this->css_file_name . '.min.css', array(), $this->get_css_file_version() );
36+
if ( $this->register_dynamic_style_file() ) {
37+
wp_enqueue_style( 'a3' . $this->css_file_name );
2738
}
2839
}
2940

0 commit comments

Comments
 (0)