Add plugin structure, lazy load feature, and basic admin settings
This commit is contained in:
47
admin/settings.php
Normal file
47
admin/settings.php
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Admin settings page
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Add menu item
|
||||||
|
function wpa_superstar_admin_menu() {
|
||||||
|
add_options_page(
|
||||||
|
'WPA Superstar Settings',
|
||||||
|
'WPA Superstar',
|
||||||
|
'manage_options',
|
||||||
|
'wpa-superstar',
|
||||||
|
'wpa_superstar_settings_page'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
add_action( 'admin_menu', 'wpa_superstar_admin_menu' );
|
||||||
|
|
||||||
|
// Register settings
|
||||||
|
function wpa_superstar_register_settings() {
|
||||||
|
register_setting( 'wpa-superstar-settings', 'wpa_superstar_lazy_load' );
|
||||||
|
}
|
||||||
|
add_action( 'admin_init', 'wpa_superstar_register_settings' );
|
||||||
|
|
||||||
|
// Settings page HTML
|
||||||
|
function wpa_superstar_settings_page() {
|
||||||
|
?>
|
||||||
|
<div class="wrap">
|
||||||
|
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
|
||||||
|
<form method="post" action="options.php">
|
||||||
|
<?php settings_fields( 'wpa-superstar-settings' ); ?>
|
||||||
|
<?php do_settings_sections( 'wpa-superstar-settings' ); ?>
|
||||||
|
<table class="form-table">
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Lazy Load Images</th>
|
||||||
|
<td>
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="wpa_superstar_lazy_load" value="1" <?php checked( get_option( 'wpa_superstar_lazy_load', 1 ) ); ?> />
|
||||||
|
Enable lazy loading for images
|
||||||
|
</label>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<?php submit_button(); ?>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
18
includes/speed-functions.php
Normal file
18
includes/speed-functions.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Speed optimization functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
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
|
||||||
|
);
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
add_filter( 'the_content', 'wpa_superstar_lazy_load_images' );
|
||||||
|
add_filter( 'wp_get_attachment_image', 'wpa_superstar_lazy_load_images' );
|
@ -16,11 +16,22 @@
|
|||||||
|
|
||||||
// If this file is called directly, abort.
|
// If this file is called directly, abort.
|
||||||
if ( ! defined( 'WPINC' ) ) {
|
if ( ! defined( 'WPINC' ) ) {
|
||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Define plugin version
|
||||||
* Currently plugin version.
|
|
||||||
* Start at version 1.0.0 and use SemVer - https://semver.org
|
|
||||||
*/
|
|
||||||
define( 'WPA_SUPERSTAR_VERSION', '1.0.0' );
|
define( 'WPA_SUPERSTAR_VERSION', '1.0.0' );
|
||||||
|
|
||||||
|
// Activation hook
|
||||||
|
function wpa_superstar_activate() {
|
||||||
|
// Add activation logic later if needed
|
||||||
|
}
|
||||||
|
register_activation_hook( __FILE__, 'wpa_superstar_activate' );
|
||||||
|
|
||||||
|
// Load core functionality
|
||||||
|
require_once plugin_dir_path( __FILE__ ) . 'includes/speed-functions.php';
|
||||||
|
|
||||||
|
// Load admin UI
|
||||||
|
if ( is_admin() ) {
|
||||||
|
require_once plugin_dir_path( __FILE__ ) . 'admin/settings.php';
|
||||||
|
}
|
Reference in New Issue
Block a user