Add CSS minification, AJAX settings, and modern admin styling
This commit is contained in:
14
admin/css/wpa-superstar-admin.css
Normal file
14
admin/css/wpa-superstar-admin.css
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
.wpa-superstar-wrap {
|
||||||
|
max-width: 800px;
|
||||||
|
background: #fff;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||||
|
}
|
||||||
|
.wpa-superstar-wrap h1 {
|
||||||
|
font-size: 24px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
.wpa-superstar-toggle {
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
14
admin/js/wpa-superstar-admin.js
Normal file
14
admin/js/wpa-superstar-admin.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
jQuery(document).ready(function($) {
|
||||||
|
$('.wpa-superstar-toggle input').on('change', function() {
|
||||||
|
var option = $(this).attr('name');
|
||||||
|
var value = $(this).is(':checked') ? 1 : 0;
|
||||||
|
$.post(ajaxurl, {
|
||||||
|
action: 'wpa_superstar_update_option',
|
||||||
|
option: option,
|
||||||
|
value: value,
|
||||||
|
nonce: '<?php echo wp_create_nonce( "wpa-superstar-nonce" ); ?>'
|
||||||
|
}, function(response) {
|
||||||
|
console.log(response);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -18,28 +18,40 @@ add_action( 'admin_menu', 'wpa_superstar_admin_menu' );
|
|||||||
// Register settings
|
// Register settings
|
||||||
function wpa_superstar_register_settings() {
|
function wpa_superstar_register_settings() {
|
||||||
register_setting( 'wpa-superstar-settings', 'wpa_superstar_lazy_load' );
|
register_setting( 'wpa-superstar-settings', 'wpa_superstar_lazy_load' );
|
||||||
|
register_setting( 'wpa-superstar-settings', 'wpa_superstar_minify_css' );
|
||||||
}
|
}
|
||||||
add_action( 'admin_init', 'wpa_superstar_register_settings' );
|
add_action( 'admin_init', 'wpa_superstar_register_settings' );
|
||||||
|
|
||||||
|
// AJAX handler
|
||||||
|
function wpa_superstar_update_option() {
|
||||||
|
check_ajax_referer( 'wpa-superstar-nonce', 'nonce' );
|
||||||
|
$option = sanitize_text_field( $_POST['option'] );
|
||||||
|
$value = intval( $_POST['value'] );
|
||||||
|
update_option( $option, $value );
|
||||||
|
wp_send_json_success( 'Option updated' );
|
||||||
|
}
|
||||||
|
add_action( 'wp_ajax_wpa_superstar_update_option', 'wpa_superstar_update_option' );
|
||||||
|
|
||||||
// Settings page HTML
|
// Settings page HTML
|
||||||
function wpa_superstar_settings_page() {
|
function wpa_superstar_settings_page() {
|
||||||
?>
|
?>
|
||||||
<div class="wrap">
|
<div class="wpa-superstar-wrap">
|
||||||
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
|
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
|
||||||
<form method="post" action="options.php">
|
<form method="post" action="options.php">
|
||||||
<?php settings_fields( 'wpa-superstar-settings' ); ?>
|
<?php settings_fields( 'wpa-superstar-settings' ); ?>
|
||||||
<?php do_settings_sections( 'wpa-superstar-settings' ); ?>
|
<?php do_settings_sections( 'wpa-superstar-settings' ); ?>
|
||||||
<table class="form-table">
|
<div class="wpa-superstar-toggle">
|
||||||
<tr>
|
<label>
|
||||||
<th scope="row">Lazy Load Images</th>
|
<input type="checkbox" name="wpa_superstar_lazy_load" value="1" <?php checked( get_option( 'wpa_superstar_lazy_load', 1 ) ); ?> />
|
||||||
<td>
|
Enable lazy loading for images
|
||||||
<label>
|
</label>
|
||||||
<input type="checkbox" name="wpa_superstar_lazy_load" value="1" <?php checked( get_option( 'wpa_superstar_lazy_load', 1 ) ); ?> />
|
</div>
|
||||||
Enable lazy loading for images
|
<div class="wpa-superstar-toggle">
|
||||||
</label>
|
<label>
|
||||||
</td>
|
<input type="checkbox" name="wpa_superstar_minify_css" value="1" <?php checked( get_option( 'wpa_superstar_minify_css', 0 ) ); ?> />
|
||||||
</tr>
|
Enable CSS minification
|
||||||
</table>
|
</label>
|
||||||
|
</div>
|
||||||
<?php submit_button(); ?>
|
<?php submit_button(); ?>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -15,4 +15,18 @@ function wpa_superstar_lazy_load_images( $content ) {
|
|||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
add_filter( 'the_content', 'wpa_superstar_lazy_load_images' );
|
add_filter( 'the_content', 'wpa_superstar_lazy_load_images' );
|
||||||
add_filter( 'wp_get_attachment_image', 'wpa_superstar_lazy_load_images' );
|
add_filter( 'wp_get_attachment_image', 'wpa_superstar_lazy_load_images' );
|
||||||
|
|
||||||
|
// After lazy load function
|
||||||
|
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
|
||||||
|
);
|
||||||
|
return trim( $html );
|
||||||
|
}
|
||||||
|
add_filter( 'style_loader_tag', 'wpa_superstar_minify_css' );
|
@ -34,4 +34,11 @@ require_once plugin_dir_path( __FILE__ ) . 'includes/speed-functions.php';
|
|||||||
// Load admin UI
|
// Load admin UI
|
||||||
if ( is_admin() ) {
|
if ( is_admin() ) {
|
||||||
require_once plugin_dir_path( __FILE__ ) . 'admin/settings.php';
|
require_once plugin_dir_path( __FILE__ ) . 'admin/settings.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Admin assets
|
||||||
|
function wpa_superstar_admin_assets() {
|
||||||
|
wp_enqueue_style( 'wpa-superstar-admin', plugins_url( 'admin/css/wpa-superstar-admin.css', __FILE__ ), [], WPA_SUPERSTAR_VERSION );
|
||||||
|
wp_enqueue_script( 'wpa-superstar-admin', plugins_url( 'admin/js/wpa-superstar-admin.js', __FILE__ ), [ 'jquery' ], WPA_SUPERSTAR_VERSION, true );
|
||||||
|
}
|
||||||
|
add_action( 'admin_enqueue_scripts', 'wpa_superstar_admin_assets' );
|
Reference in New Issue
Block a user