Plugin Directory

Changeset 3175027


Ignore:
Timestamp:
10/24/2024 01:50:48 PM (16 months ago)
Author:
detech
Message:

init v1.2.0

Location:
detech-cache/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • detech-cache/trunk/detech-cache.php

    r3169962 r3175027  
    33 * Plugin Name: Detech Cache
    44 * Description: A simple caching plugin to improve WordPress performance by caching HTML pages.
    5  * Version: 1.0.0
     5 * Version: 1.2.0
    66 * Author: Adeniyi Balogun
    77 * License: GPLv2 or later
     
    99 */
    1010
     11// Prevent direct access to the file
    1112if ( ! defined( 'ABSPATH' ) ) {
    1213    exit; // Exit if accessed directly
    1314}
    1415
    15 // Include required files
    16 require_once plugin_dir_path( __FILE__ ) . 'includes/class-detech-cache.php';
     16// Include admin settings file
    1717require_once plugin_dir_path( __FILE__ ) . 'includes/class-detech-admin-settings.php';
    1818
    19 // Activation hook
     19// Plugin activation hook
    2020function detech_cache_activate() {
    21     Detech_Cache::activate();
     21    // Actions to perform on plugin activation
    2222}
    2323register_activation_hook( __FILE__, 'detech_cache_activate' );
    2424
    25 // Deactivation hook
     25// Plugin deactivation hook
    2626function detech_cache_deactivate() {
    27     Detech_Cache::deactivate();
     27    // Actions to perform on plugin deactivation
    2828}
    2929register_deactivation_hook( __FILE__, 'detech_cache_deactivate' );
    3030
    3131// 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 );
     32function 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 );
    3540}
    3641add_action( 'admin_enqueue_scripts', 'detech_cache_enqueue_admin_assets' );
     42
     43// Initialize plugin settings and cache logic
     44add_action( 'plugins_loaded', function() {
     45    // Add any additional initialization here
     46});
     47
  • detech-cache/trunk/includes/class-detech-admin-settings.php

    r3169962 r3175027  
    77
    88    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
    1013        add_action( 'admin_init', array( $this, 'register_settings' ) );
    1114    }
    1215
    13     public function add_admin_menu() {
     16    // Add settings page
     17    public function add_settings_page() {
    1418        add_options_page(
    1519            'Detech Cache Settings',
    1620            'Detech Cache',
    1721            'manage_options',
    18             'detech-cache',
    19             array( $this, 'settings_page' )
     22            'detech-cache', // slug
     23            array( $this, 'render_settings_page' )
    2024        );
    2125    }
    2226
     27    // Register settings, sections, and fields
    2328    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        ) );
    2533
     34        // Add a section for settings
    2635        add_settings_section(
    27             'detech_cache_section',
    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
    3140        );
    3241
     42        // Add a field to the settings section
    3343        add_settings_field(
    3444            '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' ),
    3747            'detech-cache',
    38             'detech_cache_section'
     48            'detech_cache_settings_section'
    3949        );
    4050    }
    4151
    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)
    4456        ?>
    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>
    4759        <?php
    4860    }
    4961
    50     public function settings_page() {
     62    // Render the settings page
     63    public function render_settings_page() {
    5164        ?>
    5265        <div class="wrap">
    53             <h1><?php esc_html_e( 'Detech Cache Settings', 'detech-cache' ); ?></h1>
     66            <h1>Detech Cache Settings</h1>
    5467            <form method="post" action="options.php">
    5568                <?php
     69                // Output security fields for the registered settings
    5670                settings_fields( 'detech_cache_settings' );
     71
     72                // Output the settings sections and fields
    5773                do_settings_sections( 'detech-cache' );
     74
     75                // Output the submit button
    5876                submit_button();
    5977                ?>
  • detech-cache/trunk/readme.txt

    r3169962 r3175027  
    55Tested up to: 6.6
    66Requires PHP: 7.0
    7 Stable tag: 1.0.0
     7Stable tag: 1.2.0
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset for help on using the changeset viewer.