Changeset 3175027
- Timestamp:
- 10/24/2024 01:50:48 PM (16 months ago)
- Location:
- detech-cache/trunk
- Files:
-
- 3 edited
-
detech-cache.php (modified) (2 diffs)
-
includes/class-detech-admin-settings.php (modified) (1 diff)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
detech-cache/trunk/detech-cache.php
r3169962 r3175027 3 3 * Plugin Name: Detech Cache 4 4 * Description: A simple caching plugin to improve WordPress performance by caching HTML pages. 5 * Version: 1. 0.05 * Version: 1.2.0 6 6 * Author: Adeniyi Balogun 7 7 * License: GPLv2 or later … … 9 9 */ 10 10 11 // Prevent direct access to the file 11 12 if ( ! defined( 'ABSPATH' ) ) { 12 13 exit; // Exit if accessed directly 13 14 } 14 15 15 // Include required files 16 require_once plugin_dir_path( __FILE__ ) . 'includes/class-detech-cache.php'; 16 // Include admin settings file 17 17 require_once plugin_dir_path( __FILE__ ) . 'includes/class-detech-admin-settings.php'; 18 18 19 // Activation hook19 // Plugin activation hook 20 20 function detech_cache_activate() { 21 Detech_Cache::activate();21 // Actions to perform on plugin activation 22 22 } 23 23 register_activation_hook( __FILE__, 'detech_cache_activate' ); 24 24 25 // Deactivation hook25 // Plugin deactivation hook 26 26 function detech_cache_deactivate() { 27 Detech_Cache::deactivate();27 // Actions to perform on plugin deactivation 28 28 } 29 29 register_deactivation_hook( __FILE__, 'detech_cache_deactivate' ); 30 30 31 31 // Enqueue admin assets 32 function detech_cache_enqueue_admin_assets() { 33 wp_enqueue_style( 'detech-cache-admin-style', plugin_dir_url( __FILE__ ) . 'assets/css/admin.css' ); 34 wp_enqueue_script( 'detech-cache-admin-script', plugin_dir_url( __FILE__ ) . 'assets/js/admin.js', array( 'jquery' ), '1.0.0', true ); 32 function detech_cache_enqueue_admin_assets( $hook_suffix ) { 33 // Only load the CSS/JS on the settings page 34 if ( $hook_suffix !== 'settings_page_detech-cache' ) { 35 return; 36 } 37 38 wp_enqueue_style( 'detech-cache-admin-style', plugins_url( 'assets/css/admin-style.css', __FILE__ ) ); 39 wp_enqueue_script( 'detech-cache-admin-script', plugins_url( 'assets/js/admin-script.js', __FILE__ ), array( 'jquery' ), false, true ); 35 40 } 36 41 add_action( 'admin_enqueue_scripts', 'detech_cache_enqueue_admin_assets' ); 42 43 // Initialize plugin settings and cache logic 44 add_action( 'plugins_loaded', function() { 45 // Add any additional initialization here 46 }); 47 -
detech-cache/trunk/includes/class-detech-admin-settings.php
r3169962 r3175027 7 7 8 8 public function __construct() { 9 add_action( 'admin_menu', array( $this, 'add_admin_menu' ) ); 9 // Hook to add admin menu 10 add_action( 'admin_menu', array( $this, 'add_settings_page' ) ); 11 12 // Hook to register settings 10 13 add_action( 'admin_init', array( $this, 'register_settings' ) ); 11 14 } 12 15 13 public function add_admin_menu() { 16 // Add settings page 17 public function add_settings_page() { 14 18 add_options_page( 15 19 'Detech Cache Settings', 16 20 'Detech Cache', 17 21 'manage_options', 18 'detech-cache', 19 array( $this, ' settings_page' )22 'detech-cache', // slug 23 array( $this, 'render_settings_page' ) 20 24 ); 21 25 } 22 26 27 // Register settings, sections, and fields 23 28 public function register_settings() { 24 register_setting( 'detech_cache_settings', 'detech_cache_expiry_time' ); 29 // Register the setting 30 register_setting( 'detech_cache_settings', 'detech_cache_expiry_time', array( 31 'sanitize_callback' => 'absint' // sanitize as an integer 32 ) ); 25 33 34 // Add a section for settings 26 35 add_settings_section( 27 'detech_cache_se ction',28 __( 'Cache Settings', 'detech-cache' ),29 null, 30 'detech-cache' 36 'detech_cache_settings_section', 37 'Cache Settings', 38 null, // No description callback 39 'detech-cache' // matches the slug used in add_options_page 31 40 ); 32 41 42 // Add a field to the settings section 33 43 add_settings_field( 34 44 'detech_cache_expiry_time', 35 __( 'Cache Expiry Time (seconds)', 'detech-cache' ),36 array( $this, 'expiry_time_field ' ),45 'Cache Expiry Time (seconds)', 46 array( $this, 'expiry_time_field_callback' ), 37 47 'detech-cache', 38 'detech_cache_se ction'48 'detech_cache_settings_section' 39 49 ); 40 50 } 41 51 42 public function expiry_time_field() { 43 $expiry_time = get_option( 'detech_cache_expiry_time', 3600 ); 52 // Callback function to display the input field for cache expiry time 53 public function expiry_time_field_callback() { 54 // Get the current value of the cache expiry time option 55 $cache_expiry_time = get_option( 'detech_cache_expiry_time', 3600 ); // default to 3600 seconds (1 hour) 44 56 ?> 45 <input type="number" name="detech_cache_expiry_time" value="<?php echo esc_attr( $ expiry_time ); ?>" min="60" />46 <p class="description"> <?php esc_html_e( 'The time in seconds before the cache expires. Minimum 60 seconds.', 'detech-cache' ); ?></p>57 <input type="number" name="detech_cache_expiry_time" value="<?php echo esc_attr( $cache_expiry_time ); ?>" /> 58 <p class="description">Enter the cache expiry time in seconds.</p> 47 59 <?php 48 60 } 49 61 50 public function settings_page() { 62 // Render the settings page 63 public function render_settings_page() { 51 64 ?> 52 65 <div class="wrap"> 53 <h1> <?php esc_html_e( 'Detech Cache Settings', 'detech-cache' ); ?></h1>66 <h1>Detech Cache Settings</h1> 54 67 <form method="post" action="options.php"> 55 68 <?php 69 // Output security fields for the registered settings 56 70 settings_fields( 'detech_cache_settings' ); 71 72 // Output the settings sections and fields 57 73 do_settings_sections( 'detech-cache' ); 74 75 // Output the submit button 58 76 submit_button(); 59 77 ?> -
detech-cache/trunk/readme.txt
r3169962 r3175027 5 5 Tested up to: 6.6 6 6 Requires PHP: 7.0 7 Stable tag: 1. 0.07 Stable tag: 1.2.0 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset
for help on using the changeset viewer.