Add error logging, UI status indicators, and update README
This commit is contained in:
21
README.md
21
README.md
@ -1,3 +1,20 @@
|
|||||||
# wpa-superstar-plugin
|
# WP ALLSTARS Superstar Plugin
|
||||||
|
A lean speed optimization plugin for WordPress. Speed Matters.
|
||||||
|
|
||||||
WP ALLSTARS Superstar Plugin for WordPress. Speed Matters.
|
## Features
|
||||||
|
- Lazy loading of images
|
||||||
|
- CSS minification
|
||||||
|
- JS minification
|
||||||
|
- Modern, tabbed Admin UI with AJAX settings
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
1. Download or clone this repo.
|
||||||
|
2. Upload to `/wp-content/plugins/`.
|
||||||
|
3. Activate in WordPress Admin.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
- Go to Settings → WPA Superstar.
|
||||||
|
- Toggle features in General and Advanced tabs.
|
||||||
|
|
||||||
|
## Logs
|
||||||
|
- Errors are logged to `wp-content/wpa-superstar.log`.
|
@ -24,3 +24,7 @@
|
|||||||
background: #fff;
|
background: #fff;
|
||||||
border-bottom: 1px solid #fff;
|
border-bottom: 1px solid #fff;
|
||||||
}
|
}
|
||||||
|
.wpa-superstar-toggle label {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
@ -1,14 +1,21 @@
|
|||||||
jQuery(document).ready(function($) {
|
jQuery(document).ready(function($) {
|
||||||
$('.wpa-superstar-toggle input').on('change', function() {
|
$('.wpa-superstar-toggle input').on('change', function() {
|
||||||
var option = $(this).attr('name');
|
var $input = $(this);
|
||||||
var value = $(this).is(':checked') ? 1 : 0;
|
var option = $input.attr('name');
|
||||||
|
var value = $input.is(':checked') ? 1 : 0;
|
||||||
$.post(wpaSuperstar.ajaxurl, {
|
$.post(wpaSuperstar.ajaxurl, {
|
||||||
action: 'wpa_superstar_update_option',
|
action: 'wpa_superstar_update_option',
|
||||||
option: option,
|
option: option,
|
||||||
value: value,
|
value: value,
|
||||||
nonce: wpaSuperstar.nonce
|
nonce: wpaSuperstar.nonce
|
||||||
}, function(response) {
|
}, function(response) {
|
||||||
console.log(response);
|
if (response.success) {
|
||||||
|
$input.next('.wpa-status').remove();
|
||||||
|
$input.after('<span class="wpa-status" style="color: green; margin-left: 10px;">Saved</span>');
|
||||||
|
setTimeout(function() { $('.wpa-status').fadeOut(); }, 2000);
|
||||||
|
} else {
|
||||||
|
console.error('Error:', response);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
@ -3,15 +3,26 @@
|
|||||||
* Speed optimization functions
|
* Speed optimization functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Logging function
|
||||||
|
function wpa_superstar_log( $message ) {
|
||||||
|
$log_file = WP_CONTENT_DIR . '/wpa-superstar.log';
|
||||||
|
$time = current_time( 'mysql' );
|
||||||
|
file_put_contents( $log_file, "[$time] $message\n", FILE_APPEND );
|
||||||
|
}
|
||||||
|
|
||||||
function wpa_superstar_lazy_load_images( $content ) {
|
function wpa_superstar_lazy_load_images( $content ) {
|
||||||
if ( is_admin() || ! $content || ! get_option( 'wpa_superstar_lazy_load', 1 ) ) {
|
if ( is_admin() || ! $content || ! get_option( 'wpa_superstar_lazy_load', 1 ) ) {
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
$content = preg_replace(
|
$content = preg_replace(
|
||||||
'/(<img[^>]+)\/?>/i',
|
'/(<img[^>]+)\/?>/i',
|
||||||
'$1 loading="lazy" />',
|
'$1 loading="lazy" />',
|
||||||
$content
|
$content
|
||||||
);
|
);
|
||||||
|
} catch ( Exception $e ) {
|
||||||
|
wpa_superstar_log( "Lazy load error: " . $e->getMessage() );
|
||||||
|
}
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
add_filter( 'the_content', 'wpa_superstar_lazy_load_images' );
|
add_filter( 'the_content', 'wpa_superstar_lazy_load_images' );
|
||||||
@ -21,11 +32,15 @@ function wpa_superstar_minify_css( $html ) {
|
|||||||
if ( is_admin() || ! get_option( 'wpa_superstar_minify_css', 0 ) ) {
|
if ( is_admin() || ! get_option( 'wpa_superstar_minify_css', 0 ) ) {
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
$html = preg_replace(
|
$html = preg_replace(
|
||||||
array( '/\s+/', '/\/\*.*?\*\//s', '/;}/' ),
|
array( '/\s+/', '/\/\*.*?\*\//s', '/;}/' ),
|
||||||
array( ' ', '', '}' ),
|
array( ' ', '', '}' ),
|
||||||
$html
|
$html
|
||||||
);
|
);
|
||||||
|
} catch ( Exception $e ) {
|
||||||
|
wpa_superstar_log( "CSS minify error: " . $e->getMessage() );
|
||||||
|
}
|
||||||
return trim( $html );
|
return trim( $html );
|
||||||
}
|
}
|
||||||
add_filter( 'style_loader_tag', 'wpa_superstar_minify_css' );
|
add_filter( 'style_loader_tag', 'wpa_superstar_minify_css' );
|
||||||
@ -34,11 +49,15 @@ function wpa_superstar_minify_js( $html ) {
|
|||||||
if ( is_admin() || ! get_option( 'wpa_superstar_minify_js', 0 ) ) {
|
if ( is_admin() || ! get_option( 'wpa_superstar_minify_js', 0 ) ) {
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
$html = preg_replace(
|
$html = preg_replace(
|
||||||
array( '/\s+/', '/\/\*.*?\*\//s', '//.*?\n/' ),
|
array( '/\s+/', '/\/\*.*?\*\//s', '//.*?\n/' ),
|
||||||
array( ' ', '', '' ),
|
array( ' ', '', '' ),
|
||||||
$html
|
$html
|
||||||
);
|
);
|
||||||
|
} catch ( Exception $e ) {
|
||||||
|
wpa_superstar_log( "JS minify error: " . $e->getMessage() );
|
||||||
|
}
|
||||||
return trim( $html );
|
return trim( $html );
|
||||||
}
|
}
|
||||||
add_filter( 'script_loader_tag', 'wpa_superstar_minify_js' );
|
add_filter( 'script_loader_tag', 'wpa_superstar_minify_js' );
|
Reference in New Issue
Block a user