Add error logging, UI status indicators, and update README

This commit is contained in:
Marcus Quinn
2025-03-13 00:56:06 +00:00
parent 75b60be213
commit 3f109c22f6
4 changed files with 67 additions and 20 deletions

View File

@ -3,15 +3,26 @@
* 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 ) {
if ( is_admin() || ! $content || ! get_option( 'wpa_superstar_lazy_load', 1 ) ) {
return $content;
}
$content = preg_replace(
'/(<img[^>]+)\/?>/i',
'$1 loading="lazy" />',
$content
);
try {
$content = preg_replace(
'/(<img[^>]+)\/?>/i',
'$1 loading="lazy" />',
$content
);
} catch ( Exception $e ) {
wpa_superstar_log( "Lazy load error: " . $e->getMessage() );
}
return $content;
}
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 ) ) {
return $html;
}
$html = preg_replace(
array( '/\s+/', '/\/\*.*?\*\//s', '/;}/' ),
array( ' ', '', '}' ),
$html
);
try {
$html = preg_replace(
array( '/\s+/', '/\/\*.*?\*\//s', '/;}/' ),
array( ' ', '', '}' ),
$html
);
} catch ( Exception $e ) {
wpa_superstar_log( "CSS minify error: " . $e->getMessage() );
}
return trim( $html );
}
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 ) ) {
return $html;
}
$html = preg_replace(
array( '/\s+/', '/\/\*.*?\*\//s', '//.*?\n/' ),
array( ' ', '', '' ),
$html
);
try {
$html = preg_replace(
array( '/\s+/', '/\/\*.*?\*\//s', '//.*?\n/' ),
array( ' ', '', '' ),
$html
);
} catch ( Exception $e ) {
wpa_superstar_log( "JS minify error: " . $e->getMessage() );
}
return trim( $html );
}
add_filter( 'script_loader_tag', 'wpa_superstar_minify_js' );