added maple performance caching plugin
This commit is contained in:
parent
c44c49a836
commit
e468202f95
12 changed files with 4501 additions and 0 deletions
837
native/wordpress/maple-performance-wp/inc/class-maple-admin.php
Normal file
837
native/wordpress/maple-performance-wp/inc/class-maple-admin.php
Normal file
|
|
@ -0,0 +1,837 @@
|
|||
<?php
|
||||
/**
|
||||
* Admin Settings Class
|
||||
*
|
||||
* Handles plugin settings page and admin functionality.
|
||||
*
|
||||
* @package MaplePerformance
|
||||
*/
|
||||
|
||||
// Prevent direct access
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin class
|
||||
*/
|
||||
class Maple_Performance_Admin {
|
||||
|
||||
/**
|
||||
* Single instance
|
||||
*/
|
||||
private static $instance = null;
|
||||
|
||||
/**
|
||||
* Get instance
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
private function __construct() {
|
||||
$this->init_hooks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize hooks
|
||||
*/
|
||||
private function init_hooks() {
|
||||
// Add admin menu
|
||||
add_action( 'admin_menu', array( $this, 'add_menu' ) );
|
||||
|
||||
// Register settings
|
||||
add_action( 'admin_init', array( $this, 'register_settings' ) );
|
||||
|
||||
// Admin bar cache clear button
|
||||
add_action( 'admin_bar_menu', array( $this, 'add_admin_bar_button' ), 100 );
|
||||
|
||||
// Handle cache clear action
|
||||
add_action( 'admin_init', array( $this, 'handle_cache_clear' ) );
|
||||
|
||||
// Admin notices
|
||||
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
|
||||
|
||||
// Admin styles
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles' ) );
|
||||
|
||||
// Plugin action links
|
||||
add_filter( 'plugin_action_links_' . plugin_basename( MAPLE_PERF_FILE ), array( $this, 'action_links' ) );
|
||||
|
||||
// Privacy policy
|
||||
add_action( 'admin_init', array( $this, 'add_privacy_policy_content' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add privacy policy content
|
||||
*/
|
||||
public function add_privacy_policy_content() {
|
||||
if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$content = sprintf(
|
||||
'<h2>%s</h2><p>%s</p><h3>%s</h3><p>%s</p><h3>%s</h3><p>%s</p><h3>%s</h3><p>%s</p>',
|
||||
__( 'Maple Performance WP', 'maple-performance' ),
|
||||
__( 'This site uses the Maple Performance WP plugin to improve page load times through caching and asset optimization.', 'maple-performance' ),
|
||||
__( 'What personal data we collect and why', 'maple-performance' ),
|
||||
__( 'Maple Performance WP does not collect, store, or process any personal data. The plugin caches publicly-visible page content to improve performance. By default, pages are not cached for logged-in users, ensuring that no user-specific content is stored in the cache.', 'maple-performance' ),
|
||||
__( 'Cookies', 'maple-performance' ),
|
||||
__( 'Maple Performance WP does not set any cookies. The plugin may read existing cookies (such as WordPress login cookies or WooCommerce cart cookies) solely to determine whether to serve a cached page or bypass the cache for dynamic content. No cookie data is stored or transmitted.', 'maple-performance' ),
|
||||
__( 'Third-party services', 'maple-performance' ),
|
||||
__( 'Maple Performance WP does not connect to any external services or transmit any data to third parties. All caching and optimization is performed locally on your web server.', 'maple-performance' )
|
||||
);
|
||||
|
||||
wp_add_privacy_policy_content(
|
||||
'Maple Performance WP',
|
||||
wp_kses_post( $content )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add admin menu
|
||||
*/
|
||||
public function add_menu() {
|
||||
add_options_page(
|
||||
__( 'Maple Performance', 'maple-performance' ),
|
||||
__( 'Maple Performance', 'maple-performance' ),
|
||||
'manage_options',
|
||||
'maple-performance',
|
||||
array( $this, 'settings_page' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register settings
|
||||
*/
|
||||
public function register_settings() {
|
||||
register_setting(
|
||||
'maple_performance_settings',
|
||||
'maple_performance_settings',
|
||||
array( $this, 'sanitize_settings' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize settings
|
||||
*/
|
||||
public function sanitize_settings( $input ) {
|
||||
$sanitized = array();
|
||||
|
||||
// Site mode
|
||||
$sanitized['site_mode'] = sanitize_text_field( $input['site_mode'] ?? 'brochure' );
|
||||
|
||||
// Google Fonts mode
|
||||
$valid_font_modes = array( 'leave', 'remove', 'combine', 'defer' );
|
||||
$sanitized['google_fonts'] = in_array( $input['google_fonts'] ?? 'defer', $valid_font_modes )
|
||||
? $input['google_fonts']
|
||||
: 'defer';
|
||||
|
||||
// Plugin compatibility
|
||||
$sanitized['compat_auto_detect'] = ! empty( $input['compat_auto_detect'] );
|
||||
|
||||
// Manual plugin selection
|
||||
$valid_compat_plugins = array( 'woocommerce', 'learndash', 'wordfence', 'wpforms', 'gutenberg_fse' );
|
||||
$sanitized['compat_plugins'] = array();
|
||||
if ( ! empty( $input['compat_plugins'] ) && is_array( $input['compat_plugins'] ) ) {
|
||||
foreach ( $input['compat_plugins'] as $plugin ) {
|
||||
if ( in_array( $plugin, $valid_compat_plugins ) ) {
|
||||
$sanitized['compat_plugins'][] = $plugin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Boolean settings
|
||||
$booleans = array(
|
||||
'cache_enabled', 'cache_logged_in', 'cache_gzip', 'cache_brotli',
|
||||
'html_minify', 'html_remove_comments',
|
||||
'css_minify', 'css_aggregate', 'css_inline_aggregate', 'css_defer',
|
||||
'js_minify', 'js_aggregate', 'js_defer', 'js_exclude_jquery',
|
||||
'remove_emojis', 'remove_query_strings', 'dns_prefetch',
|
||||
'lazyload_images', 'lazyload_iframes',
|
||||
'local_font_display',
|
||||
);
|
||||
|
||||
foreach ( $booleans as $key ) {
|
||||
$sanitized[ $key ] = ! empty( $input[ $key ] );
|
||||
}
|
||||
|
||||
// Integer settings
|
||||
$sanitized['cache_expiry'] = absint( $input['cache_expiry'] ?? 0 );
|
||||
|
||||
// Array settings (textarea, one per line)
|
||||
$arrays = array(
|
||||
'exclude_paths', 'exclude_cookies', 'exclude_js', 'exclude_css',
|
||||
'preconnect_domains', 'lazyload_exclude', 'preload_fonts',
|
||||
);
|
||||
|
||||
foreach ( $arrays as $key ) {
|
||||
$value = $input[ $key ] ?? '';
|
||||
if ( is_string( $value ) ) {
|
||||
$lines = explode( "\n", $value );
|
||||
$sanitized[ $key ] = array_filter( array_map( function( $line ) {
|
||||
// Sanitize each line - remove potentially dangerous characters
|
||||
$line = trim( $line );
|
||||
$line = str_replace( array( "\0", "\r" ), '', $line );
|
||||
// For URLs/paths, use esc_url_raw for domains, sanitize_text_field for others
|
||||
if ( strpos( $line, 'http' ) === 0 || strpos( $line, '//' ) === 0 ) {
|
||||
return esc_url_raw( $line );
|
||||
}
|
||||
return sanitize_text_field( $line );
|
||||
}, $lines ) );
|
||||
} else {
|
||||
$sanitized[ $key ] = array();
|
||||
}
|
||||
}
|
||||
|
||||
// Clear cache when settings change
|
||||
maple_performance()->clear_cache();
|
||||
|
||||
return $sanitized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add admin bar button
|
||||
*/
|
||||
public function add_admin_bar_button( $wp_admin_bar ) {
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$wp_admin_bar->add_node( array(
|
||||
'id' => 'maple-performance',
|
||||
'title' => '<span class="ab-icon dashicons dashicons-performance" style="font-family: dashicons; font-size: 20px; padding-top: 4px;"></span>' . __( 'Maple Cache', 'maple-performance' ),
|
||||
'href' => '#',
|
||||
) );
|
||||
|
||||
$wp_admin_bar->add_node( array(
|
||||
'parent' => 'maple-performance',
|
||||
'id' => 'maple-clear-cache',
|
||||
'title' => __( 'Clear All Cache', 'maple-performance' ),
|
||||
'href' => wp_nonce_url( admin_url( 'admin.php?action=maple_clear_cache' ), 'maple_clear_cache' ),
|
||||
) );
|
||||
|
||||
$wp_admin_bar->add_node( array(
|
||||
'parent' => 'maple-performance',
|
||||
'id' => 'maple-settings',
|
||||
'title' => __( 'Settings', 'maple-performance' ),
|
||||
'href' => admin_url( 'options-general.php?page=maple-performance' ),
|
||||
) );
|
||||
|
||||
// Show cache stats - use transient to avoid filesystem scan on every page load
|
||||
$stats = get_transient( 'maple_perf_cache_stats' );
|
||||
if ( false === $stats ) {
|
||||
// Only calculate if not cached, with a 5-minute expiry
|
||||
$stats = array(
|
||||
'count' => Maple_Performance_Cache::get_cache_count(),
|
||||
'size' => Maple_Performance_Cache::get_cache_size(),
|
||||
);
|
||||
set_transient( 'maple_perf_cache_stats', $stats, 5 * MINUTE_IN_SECONDS );
|
||||
}
|
||||
|
||||
$wp_admin_bar->add_node( array(
|
||||
'parent' => 'maple-performance',
|
||||
'id' => 'maple-cache-stats',
|
||||
'title' => sprintf( __( 'Cache: %d pages (%s)', 'maple-performance' ), $stats['count'], size_format( $stats['size'] ) ),
|
||||
'href' => admin_url( 'options-general.php?page=maple-performance' ),
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle cache clear action
|
||||
*/
|
||||
public function handle_cache_clear() {
|
||||
if ( ! isset( $_GET['action'] ) || $_GET['action'] !== 'maple_clear_cache' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_die( __( 'Unauthorized', 'maple-performance' ) );
|
||||
}
|
||||
|
||||
if ( ! wp_verify_nonce( $_GET['_wpnonce'] ?? '', 'maple_clear_cache' ) ) {
|
||||
wp_die( __( 'Invalid nonce', 'maple-performance' ) );
|
||||
}
|
||||
|
||||
maple_performance()->clear_cache();
|
||||
|
||||
// Redirect back with notice
|
||||
$redirect = remove_query_arg( array( 'action', '_wpnonce' ), wp_get_referer() );
|
||||
$redirect = add_query_arg( 'maple_cache_cleared', '1', $redirect );
|
||||
|
||||
wp_safe_redirect( $redirect );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin notices
|
||||
*/
|
||||
public function admin_notices() {
|
||||
// Show activation conflict notice (only once, immediately after activation)
|
||||
$activation_conflicts = get_transient( 'maple_perf_activation_conflict' );
|
||||
if ( false !== $activation_conflicts && is_array( $activation_conflicts ) ) {
|
||||
delete_transient( 'maple_perf_activation_conflict' );
|
||||
|
||||
echo '<div class="notice notice-error">';
|
||||
echo '<p><strong>' . esc_html__( '⚠️ Maple Performance WP - Important!', 'maple-performance' ) . '</strong></p>';
|
||||
echo '<p>' . sprintf(
|
||||
esc_html__( 'Another caching plugin is already active: %s', 'maple-performance' ),
|
||||
'<strong>' . esc_html( implode( ', ', $activation_conflicts ) ) . '</strong>'
|
||||
) . '</p>';
|
||||
echo '<p>' . esc_html__( 'Running multiple caching plugins can cause site errors, blank pages, or performance issues.', 'maple-performance' ) . '</p>';
|
||||
echo '<p>';
|
||||
echo '<a href="' . esc_url( admin_url( 'plugins.php' ) ) . '" class="button button-primary">' . esc_html__( 'Choose which plugin to keep', 'maple-performance' ) . '</a> ';
|
||||
echo '<a href="' . esc_url( admin_url( 'options-general.php?page=maple-performance' ) ) . '" class="button">' . esc_html__( 'Go to Settings', 'maple-performance' ) . '</a>';
|
||||
echo '</p>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only display check
|
||||
if ( isset( $_GET['maple_cache_cleared'] ) ) {
|
||||
echo '<div class="notice notice-success is-dismissible">';
|
||||
echo '<p>' . esc_html__( 'Maple Performance: Cache cleared successfully.', 'maple-performance' ) . '</p>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
// Check if settings were saved
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only display check
|
||||
$page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
|
||||
if ( isset( $_GET['settings-updated'] ) && $page === 'maple-performance' ) {
|
||||
echo '<div class="notice notice-success is-dismissible">';
|
||||
echo '<p>' . esc_html__( 'Maple Performance: Settings saved and cache cleared.', 'maple-performance' ) . '</p>';
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin styles
|
||||
*/
|
||||
public function admin_styles( $hook ) {
|
||||
if ( $hook !== 'settings_page_maple-performance' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
wp_add_inline_style( 'common', '
|
||||
.maple-settings { max-width: 900px; }
|
||||
.maple-settings h2 { border-bottom: 1px solid #ccc; padding-bottom: 10px; margin-top: 30px; }
|
||||
.maple-settings h2:first-of-type { margin-top: 10px; }
|
||||
.maple-settings table { margin-bottom: 20px; }
|
||||
.maple-settings .description { color: #666; font-style: italic; }
|
||||
.maple-settings textarea { width: 100%; max-width: 400px; }
|
||||
.maple-settings .site-mode-card {
|
||||
border: 2px solid #ddd;
|
||||
padding: 15px;
|
||||
margin: 10px 0;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.maple-settings .site-mode-card:hover { border-color: #2271b1; }
|
||||
.maple-settings .site-mode-card.selected { border-color: #2271b1; background: #f0f7fc; }
|
||||
.maple-settings .site-mode-card h4 { margin: 0 0 5px; }
|
||||
.maple-settings .warning { color: #d63638; }
|
||||
.maple-settings .safe { color: #00a32a; }
|
||||
.maple-cache-stats {
|
||||
background: #f0f0f1;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.maple-cache-stats strong { font-size: 1.2em; }
|
||||
.maple-detected-plugins {
|
||||
background: #f9f9f9;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
padding: 15px 20px;
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
.maple-detected-plugins h3 { margin-top: 0; }
|
||||
.maple-detected-plugins table { margin-top: 15px; }
|
||||
.maple-detected-plugins ul li { font-size: 13px; color: #555; }
|
||||
' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin action links
|
||||
*/
|
||||
public function action_links( $links ) {
|
||||
$settings_link = '<a href="' . admin_url( 'options-general.php?page=maple-performance' ) . '">' . __( 'Settings', 'maple-performance' ) . '</a>';
|
||||
$clear_link = '<a href="' . wp_nonce_url( admin_url( 'admin.php?action=maple_clear_cache' ), 'maple_clear_cache' ) . '">' . __( 'Clear Cache', 'maple-performance' ) . '</a>';
|
||||
|
||||
array_unshift( $links, $settings_link, $clear_link );
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings page
|
||||
*/
|
||||
public function settings_page() {
|
||||
$settings = maple_performance()->settings;
|
||||
|
||||
// Get cache stats
|
||||
$cache_count = Maple_Performance_Cache::get_cache_count();
|
||||
$cache_size = Maple_Performance_Cache::get_cache_size();
|
||||
?>
|
||||
<div class="wrap maple-settings">
|
||||
<h1><?php _e( 'Maple Performance WP', 'maple-performance' ); ?></h1>
|
||||
|
||||
<p><?php _e( 'A lightweight, privacy-focused performance plugin. No external dependencies, no tracking, no upsells.', 'maple-performance' ); ?></p>
|
||||
|
||||
<div class="maple-cache-stats">
|
||||
<strong><?php _e( 'Cache Status:', 'maple-performance' ); ?></strong>
|
||||
<?php printf( __( '%d cached pages (%s)', 'maple-performance' ), $cache_count, size_format( $cache_size ) ); ?>
|
||||
|
||||
<a href="<?php echo wp_nonce_url( admin_url( 'admin.php?action=maple_clear_cache' ), 'maple_clear_cache' ); ?>" class="button button-secondary">
|
||||
<?php _e( 'Clear All Cache', 'maple-performance' ); ?>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
// Get compat class for detection info
|
||||
$compat = class_exists( 'Maple_Performance_Compat' ) ? Maple_Performance_Compat::get_instance() : null;
|
||||
$detected_plugins = $compat ? $compat->get_detected() : array();
|
||||
?>
|
||||
|
||||
<form method="post" action="options.php">
|
||||
<?php settings_fields( 'maple_performance_settings' ); ?>
|
||||
|
||||
<h2><?php _e( 'Plugin Compatibility', 'maple-performance' ); ?></h2>
|
||||
<p class="description"><?php _e( 'Configure compatibility rules for common plugins. These rules protect critical functionality like checkout, form submissions, and course tracking.', 'maple-performance' ); ?></p>
|
||||
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'Detection Mode', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="maple_performance_settings[compat_auto_detect]" value="1" <?php checked( $settings['compat_auto_detect'] ); ?> id="compat_auto_detect">
|
||||
<?php _e( 'Auto-detect installed plugins', 'maple-performance' ); ?>
|
||||
</label>
|
||||
<p class="description">
|
||||
<?php _e( 'When enabled, Maple Performance will attempt to detect plugins automatically. This can be fragile if plugins change their file structure. <strong>Manual selection below is recommended for reliability.</strong>', 'maple-performance' ); ?>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="manual_compat_row">
|
||||
<th scope="row"><?php _e( 'Enable Compatibility For', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<label style="display: block; margin-bottom: 12px;">
|
||||
<input type="checkbox" name="maple_performance_settings[compat_plugins][]" value="woocommerce" <?php checked( in_array( 'woocommerce', $settings['compat_plugins'] ?? array() ) ); ?>>
|
||||
<strong>WooCommerce</strong>
|
||||
<?php if ( ! empty( $detected_plugins['woocommerce'] ) ) : ?>
|
||||
<span class="safe" style="margin-left: 5px;">✓ Detected</span>
|
||||
<?php endif; ?>
|
||||
<br>
|
||||
<span class="description" style="margin-left: 24px;">Excludes cart, checkout, account pages from cache. Protects payment gateway scripts. Bypasses cache when cart has items.</span>
|
||||
</label>
|
||||
|
||||
<label style="display: block; margin-bottom: 12px;">
|
||||
<input type="checkbox" name="maple_performance_settings[compat_plugins][]" value="learndash" <?php checked( in_array( 'learndash', $settings['compat_plugins'] ?? array() ) ); ?>>
|
||||
<strong>LearnDash</strong>
|
||||
<?php if ( ! empty( $detected_plugins['learndash'] ) ) : ?>
|
||||
<span class="safe" style="margin-left: 5px;">✓ Detected</span>
|
||||
<?php endif; ?>
|
||||
<br>
|
||||
<span class="description" style="margin-left: 24px;">Excludes lesson, topic, quiz pages from cache. Protects progress tracking and quiz submission scripts.</span>
|
||||
</label>
|
||||
|
||||
<label style="display: block; margin-bottom: 12px;">
|
||||
<input type="checkbox" name="maple_performance_settings[compat_plugins][]" value="wpforms" <?php checked( in_array( 'wpforms', $settings['compat_plugins'] ?? array() ) ); ?>>
|
||||
<strong>WPForms</strong>
|
||||
<?php if ( ! empty( $detected_plugins['wpforms'] ) ) : ?>
|
||||
<span class="safe" style="margin-left: 5px;">✓ Detected</span>
|
||||
<?php endif; ?>
|
||||
<br>
|
||||
<span class="description" style="margin-left: 24px;">Protects form validation and submission scripts. Ensures AJAX form submissions work correctly.</span>
|
||||
</label>
|
||||
|
||||
<label style="display: block; margin-bottom: 12px;">
|
||||
<input type="checkbox" name="maple_performance_settings[compat_plugins][]" value="wordfence" <?php checked( in_array( 'wordfence', $settings['compat_plugins'] ?? array() ) ); ?>>
|
||||
<strong>Wordfence</strong>
|
||||
<?php if ( ! empty( $detected_plugins['wordfence'] ) ) : ?>
|
||||
<span class="safe" style="margin-left: 5px;">✓ Detected</span>
|
||||
<?php endif; ?>
|
||||
<br>
|
||||
<span class="description" style="margin-left: 24px;">Excludes login pages from cache. Respects firewall bypass cookies. Protects security scripts.</span>
|
||||
</label>
|
||||
|
||||
<label style="display: block; margin-bottom: 12px;">
|
||||
<input type="checkbox" name="maple_performance_settings[compat_plugins][]" value="gutenberg_fse" <?php checked( in_array( 'gutenberg_fse', $settings['compat_plugins'] ?? array() ) ); ?>>
|
||||
<strong>Gutenberg / Block Themes (FSE)</strong>
|
||||
<?php if ( ! empty( $detected_plugins['gutenberg_fse'] ) ) : ?>
|
||||
<span class="safe" style="margin-left: 5px;">✓ Detected</span>
|
||||
<?php endif; ?>
|
||||
<br>
|
||||
<span class="description" style="margin-left: 24px;">Protects global styles and block CSS. Safe optimization for Full Site Editing themes (Twenty Twenty-Two, etc.).</span>
|
||||
</label>
|
||||
</fieldset>
|
||||
<p class="description" style="margin-top: 10px;">
|
||||
<?php _e( '<strong>Tip:</strong> Select plugins you have installed even if not detected. Detection can miss plugins due to naming changes between versions.', 'maple-performance' ); ?>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
var autoDetect = document.getElementById('compat_auto_detect');
|
||||
var manualRow = document.getElementById('manual_compat_row');
|
||||
|
||||
function toggleManual() {
|
||||
if (autoDetect.checked) {
|
||||
manualRow.style.opacity = '0.5';
|
||||
manualRow.querySelectorAll('input').forEach(function(el) {
|
||||
el.disabled = true;
|
||||
});
|
||||
} else {
|
||||
manualRow.style.opacity = '1';
|
||||
manualRow.querySelectorAll('input').forEach(function(el) {
|
||||
el.disabled = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
autoDetect.addEventListener('change', toggleManual);
|
||||
toggleManual();
|
||||
})();
|
||||
</script>
|
||||
|
||||
<h2><?php _e( 'Site Mode', 'maple-performance' ); ?></h2>
|
||||
<p class="description"><?php _e( 'Select your site type to apply safe default settings. This affects which optimizations are enabled.', 'maple-performance' ); ?></p>
|
||||
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'Site Type', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<select name="maple_performance_settings[site_mode]" id="site_mode">
|
||||
<option value="brochure" <?php selected( $settings['site_mode'], 'brochure' ); ?>>
|
||||
<?php _e( 'Brochure / Blog (No ecommerce or LMS)', 'maple-performance' ); ?>
|
||||
</option>
|
||||
<option value="woocommerce" <?php selected( $settings['site_mode'], 'woocommerce' ); ?>>
|
||||
<?php _e( 'WooCommerce Store', 'maple-performance' ); ?>
|
||||
</option>
|
||||
<option value="learndash" <?php selected( $settings['site_mode'], 'learndash' ); ?>>
|
||||
<?php _e( 'LearnDash LMS', 'maple-performance' ); ?>
|
||||
</option>
|
||||
<option value="woo_learndash" <?php selected( $settings['site_mode'], 'woo_learndash' ); ?>>
|
||||
<?php _e( 'WooCommerce + LearnDash', 'maple-performance' ); ?>
|
||||
</option>
|
||||
</select>
|
||||
<p class="description">
|
||||
<?php _e( '<strong>Brochure:</strong> Full optimization enabled. <strong>WooCommerce/LearnDash:</strong> Conservative settings to protect checkout and lesson tracking.', 'maple-performance' ); ?>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2><?php esc_html_e( 'Page Caching', 'maple-performance' ); ?></h2>
|
||||
|
||||
<?php
|
||||
// Check for caching conflicts
|
||||
$compat = Maple_Performance_Compat::get_instance();
|
||||
if ( method_exists( $compat, 'get_caching_conflicts' ) ) {
|
||||
$caching_conflicts = $compat->get_caching_conflicts();
|
||||
if ( ! empty( $caching_conflicts ) ) {
|
||||
echo '<div class="notice notice-warning inline" style="margin: 10px 0;">';
|
||||
echo '<p><strong>' . esc_html__( '⚠️ Another caching plugin detected:', 'maple-performance' ) . '</strong> ';
|
||||
echo esc_html( implode( ', ', $caching_conflicts ) ) . '</p>';
|
||||
echo '<p>' . esc_html__( 'Consider disabling Page Cache below and using only the CSS/JS/HTML optimizations to avoid conflicts.', 'maple-performance' ) . '</p>';
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'Enable Page Cache', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="maple_performance_settings[cache_enabled]" value="1" <?php checked( $settings['cache_enabled'] ); ?>>
|
||||
<?php esc_html_e( 'Create static HTML files for faster delivery', 'maple-performance' ); ?>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'Cache Expiry', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<input type="number" name="maple_performance_settings[cache_expiry]" value="<?php echo esc_attr( $settings['cache_expiry'] ); ?>" min="0" step="1" class="small-text">
|
||||
<?php _e( 'hours (0 = never expires, cleared on content updates)', 'maple-performance' ); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'Pre-compression', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="maple_performance_settings[cache_gzip]" value="1" <?php checked( $settings['cache_gzip'] ); ?>>
|
||||
<?php _e( 'Create Gzip compressed versions', 'maple-performance' ); ?>
|
||||
</label>
|
||||
<br>
|
||||
<label>
|
||||
<input type="checkbox" name="maple_performance_settings[cache_brotli]" value="1" <?php checked( $settings['cache_brotli'] ); ?> <?php disabled( ! function_exists( 'brotli_compress' ) ); ?>>
|
||||
<?php _e( 'Create Brotli compressed versions', 'maple-performance' ); ?>
|
||||
<?php if ( ! function_exists( 'brotli_compress' ) ) : ?>
|
||||
<span class="description">(<?php _e( 'PHP Brotli extension not installed', 'maple-performance' ); ?>)</span>
|
||||
<?php endif; ?>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2><?php _e( 'HTML Optimization', 'maple-performance' ); ?></h2>
|
||||
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'Minify HTML', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="maple_performance_settings[html_minify]" value="1" <?php checked( $settings['html_minify'] ); ?>>
|
||||
<?php _e( 'Remove unnecessary whitespace from HTML', 'maple-performance' ); ?>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'Remove Comments', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="maple_performance_settings[html_remove_comments]" value="1" <?php checked( $settings['html_remove_comments'] ); ?>>
|
||||
<?php _e( 'Remove HTML comments (except IE conditionals)', 'maple-performance' ); ?>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2><?php _e( 'CSS Optimization', 'maple-performance' ); ?></h2>
|
||||
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'Minify CSS', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="maple_performance_settings[css_minify]" value="1" <?php checked( $settings['css_minify'] ); ?>>
|
||||
<?php _e( 'Remove whitespace and comments from CSS', 'maple-performance' ); ?>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'Aggregate CSS', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="maple_performance_settings[css_aggregate]" value="1" <?php checked( $settings['css_aggregate'] ); ?>>
|
||||
<?php _e( 'Combine CSS files into one', 'maple-performance' ); ?>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'Defer CSS', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="maple_performance_settings[css_defer]" value="1" <?php checked( $settings['css_defer'] ); ?>>
|
||||
<?php _e( 'Load CSS asynchronously (may cause flash of unstyled content)', 'maple-performance' ); ?>
|
||||
</label>
|
||||
<p class="description warning"><?php _e( '⚠️ Not recommended for WooCommerce/LearnDash sites', 'maple-performance' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'Exclude CSS', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<textarea name="maple_performance_settings[exclude_css]" rows="4" placeholder="handle-name another-handle"><?php echo esc_textarea( implode( "\n", $settings['exclude_css'] ) ); ?></textarea>
|
||||
<p class="description"><?php _e( 'CSS handles to exclude from optimization (one per line)', 'maple-performance' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2><?php _e( 'JavaScript Optimization', 'maple-performance' ); ?></h2>
|
||||
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'Minify JavaScript', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="maple_performance_settings[js_minify]" value="1" <?php checked( $settings['js_minify'] ); ?>>
|
||||
<?php _e( 'Remove whitespace and comments from JavaScript', 'maple-performance' ); ?>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'Aggregate JavaScript', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="maple_performance_settings[js_aggregate]" value="1" <?php checked( $settings['js_aggregate'] ); ?>>
|
||||
<?php _e( 'Combine JavaScript files into one', 'maple-performance' ); ?>
|
||||
</label>
|
||||
<p class="description warning"><?php _e( '⚠️ Can break WooCommerce checkout and LearnDash tracking. Test thoroughly!', 'maple-performance' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'Exclude jQuery', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="maple_performance_settings[js_exclude_jquery]" value="1" <?php checked( $settings['js_exclude_jquery'] ); ?>>
|
||||
<?php _e( 'Keep jQuery loading separately (recommended)', 'maple-performance' ); ?>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'Exclude JavaScript', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<textarea name="maple_performance_settings[exclude_js]" rows="4" placeholder="handle-name woocommerce learndash"><?php echo esc_textarea( implode( "\n", $settings['exclude_js'] ) ); ?></textarea>
|
||||
<p class="description"><?php _e( 'JavaScript handles/strings to exclude from optimization (one per line)', 'maple-performance' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2><?php _e( 'Lazy Loading', 'maple-performance' ); ?></h2>
|
||||
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'Lazy Load Images', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="maple_performance_settings[lazyload_images]" value="1" <?php checked( $settings['lazyload_images'] ); ?>>
|
||||
<?php _e( 'Add loading="lazy" to images', 'maple-performance' ); ?>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'Lazy Load Iframes', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="maple_performance_settings[lazyload_iframes]" value="1" <?php checked( $settings['lazyload_iframes'] ); ?>>
|
||||
<?php _e( 'Add loading="lazy" to iframes (YouTube, maps, etc.)', 'maple-performance' ); ?>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'Exclude from Lazy Load', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<textarea name="maple_performance_settings[lazyload_exclude]" rows="4" placeholder="wp-image-12345 hero-image logo"><?php echo esc_textarea( implode( "\n", $settings['lazyload_exclude'] ) ); ?></textarea>
|
||||
<p class="description"><?php _e( 'Image class names or strings to exclude from lazy loading (one per line). Exclude your LCP/hero image.', 'maple-performance' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2><?php _e( 'Extra Optimizations', 'maple-performance' ); ?></h2>
|
||||
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'Google Fonts', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<select name="maple_performance_settings[google_fonts]" id="google_fonts">
|
||||
<option value="leave" <?php selected( $settings['google_fonts'], 'leave' ); ?>>
|
||||
<?php _e( 'Leave as is', 'maple-performance' ); ?>
|
||||
</option>
|
||||
<option value="remove" <?php selected( $settings['google_fonts'], 'remove' ); ?>>
|
||||
<?php _e( 'Remove Google Fonts', 'maple-performance' ); ?>
|
||||
</option>
|
||||
<option value="combine" <?php selected( $settings['google_fonts'], 'combine' ); ?>>
|
||||
<?php _e( 'Combine and link in head (with display:swap)', 'maple-performance' ); ?>
|
||||
</option>
|
||||
<option value="defer" <?php selected( $settings['google_fonts'], 'defer' ); ?>>
|
||||
<?php _e( 'Combine and load deferred (non-render-blocking, with display:swap)', 'maple-performance' ); ?>
|
||||
</option>
|
||||
</select>
|
||||
<p class="description">
|
||||
<?php _e( '<strong>Defer</strong> is recommended - loads fonts without blocking page render.', 'maple-performance' ); ?>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'Local Font Display', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="maple_performance_settings[local_font_display]" value="1" <?php checked( $settings['local_font_display'] ?? true ); ?>>
|
||||
<?php _e( 'Add font-display: swap to theme/plugin fonts', 'maple-performance' ); ?>
|
||||
</label>
|
||||
<p class="description">
|
||||
<?php _e( 'Ensures text remains visible while local fonts load. Fixes "Ensure text remains visible during webfont load" warning.', 'maple-performance' ); ?>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'Preload Fonts', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<textarea name="maple_performance_settings[preload_fonts]" rows="3" class="large-text code"><?php
|
||||
echo esc_textarea( implode( "\n", $settings['preload_fonts'] ?? array() ) );
|
||||
?></textarea>
|
||||
<p class="description">
|
||||
<?php _e( 'Enter font URLs to preload (one per line). This breaks the CSS → Font chain and improves LCP. Use .woff2 files for best results.', 'maple-performance' ); ?>
|
||||
<br>
|
||||
<?php _e( '<strong>Example:</strong> /wp-content/themes/yourtheme/fonts/font-name.woff2', 'maple-performance' ); ?>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'Remove Emojis', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="maple_performance_settings[remove_emojis]" value="1" <?php checked( $settings['remove_emojis'] ); ?>>
|
||||
<?php _e( 'Remove WordPress emoji CSS and JavaScript', 'maple-performance' ); ?>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'Remove Query Strings', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="maple_performance_settings[remove_query_strings]" value="1" <?php checked( $settings['remove_query_strings'] ); ?>>
|
||||
<?php _e( 'Remove ?ver= from static resource URLs', 'maple-performance' ); ?>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'DNS Prefetch', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="maple_performance_settings[dns_prefetch]" value="1" <?php checked( $settings['dns_prefetch'] ); ?>>
|
||||
<?php _e( 'Add DNS prefetch hints for external domains', 'maple-performance' ); ?>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'Preconnect Domains', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<textarea name="maple_performance_settings[preconnect_domains]" rows="4" placeholder="https://www.googletagmanager.com https://fonts.googleapis.com"><?php echo esc_textarea( implode( "\n", $settings['preconnect_domains'] ) ); ?></textarea>
|
||||
<p class="description"><?php _e( 'Third-party domains to preconnect to (one per line, include https://)', 'maple-performance' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2><?php _e( 'Cache Exclusions', 'maple-performance' ); ?></h2>
|
||||
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'Exclude Paths', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<textarea name="maple_performance_settings[exclude_paths]" rows="4" placeholder="/cart/ /checkout/ /my-account/"><?php echo esc_textarea( implode( "\n", $settings['exclude_paths'] ) ); ?></textarea>
|
||||
<p class="description"><?php _e( 'URL paths to exclude from caching (one per line)', 'maple-performance' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php _e( 'Exclude Cookies', 'maple-performance' ); ?></th>
|
||||
<td>
|
||||
<textarea name="maple_performance_settings[exclude_cookies]" rows="4" placeholder="woocommerce_items_in_cart woocommerce_cart_hash"><?php echo esc_textarea( implode( "\n", $settings['exclude_cookies'] ) ); ?></textarea>
|
||||
<p class="description"><?php _e( 'Cookie names that bypass cache when present (one per line)', 'maple-performance' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php submit_button( __( 'Save Settings & Clear Cache', 'maple-performance' ) ); ?>
|
||||
|
||||
</form>
|
||||
|
||||
<hr>
|
||||
<p>
|
||||
<strong><?php _e( 'Maple Performance WP', 'maple-performance' ); ?></strong> v<?php echo MAPLE_PERF_VERSION; ?> |
|
||||
<?php _e( 'by', 'maple-performance' ); ?> <a href="https://mapleopentech.ca" target="_blank">Maple Open Tech</a> |
|
||||
<?php _e( 'No tracking. No external dependencies. No upsells.', 'maple-performance' ); ?> 🍁
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue